* Refactor myModel::buildStorySearchForm, and add its unit test.

This commit is contained in:
liumengyi
2023-11-25 17:28:44 +08:00
parent 5f54e86f06
commit 0920f5b2d7
3 changed files with 48 additions and 2 deletions
+2 -2
View File
@@ -701,15 +701,15 @@ class myModel extends model
}
/**
* 构建需求搜索表单。
* Build Story search form.
*
* @param int $queryID
* @param string $actionURL
* @param string $type
* @access public
* @return void
*/
public function buildStorySearchForm($queryID, $actionURL, $type)
public function buildStorySearchForm(int $queryID, string $actionURL): void
{
$products = $this->dao->select('id,name')->from(TABLE_PRODUCT)
->where('deleted')->eq(0)
@@ -0,0 +1,26 @@
#!/usr/bin/env php
<?php
declare(strict_types=1);
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/my.class.php';
zdTable('user')->gen('1');
su('admin');
/**
title=测试 myModel->buildStorySearchForm();
cid=1
pid=1
*/
$my = new myTest();
$queryID = array(0, 1);
$actionURL = array('actionURL1', 'actionURL2');
$config1 = $my->buildStorySearchFormTest($queryID[0], $actionURL[0]);
$config2 = $my->buildStorySearchFormTest($queryID[1], $actionURL[1]);
r($config1) && p('module,queryID,actionURL') && e('storyStory,0,actionURL1'); // 测试获取queryID 1 actionURL actionURL1 的搜索表单
r($config2) && p('module,queryID,actionURL') && e('storyStory,1,actionURL2'); // 测试获取queryID 0 actionURL actionURL2 的搜索表单
+20
View File
@@ -329,4 +329,24 @@ class myTest
return array_keys($objects);
}
/**
* 测试构建需求搜索表单。
* Test build story search form.
*
* @param int $queryID
* @param string $actionURL
* @access public
* @return array
*/
public function buildStorySearchFormTest(int $queryID, string $actionURL): array
{
global $tester;
$tester->app->rawModule = 'my';
$tester->app->rawMethod = 'story';
$this->objectModel->buildStorySearchForm($queryID, $actionURL);
if(dao::isError()) return dao::getError();
return $tester->config->product->search;
}
}