+ [misc] Add unit tests for productplanZen::setSessionForViewPage() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -216,4 +216,38 @@ class productplanZenTest extends baseTest
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setSessionForViewPage method.
|
||||
*
|
||||
* @param int $planID
|
||||
* @param string $type
|
||||
* @param string $orderBy
|
||||
* @param int $pageID
|
||||
* @param int $recPerPage
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function setSessionForViewPageTest(int $planID, string $type, string $orderBy, int $pageID, int $recPerPage)
|
||||
{
|
||||
global $tester, $config;
|
||||
|
||||
// 清除之前的 session 设置,确保每次测试从干净状态开始
|
||||
$_SESSION = array();
|
||||
|
||||
// 调用被测方法
|
||||
$this->invokeArgs('setSessionForViewPage', [$planID, $type, $orderBy, $pageID, $recPerPage]);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
// 获取调用后的 session 值
|
||||
$afterStoryList = $tester->session->storyList;
|
||||
$afterBugList = $tester->session->bugList;
|
||||
|
||||
// 判断 session 是否被设置 (不是 false 表示已设置)
|
||||
$result = new stdClass();
|
||||
$result->storyList = $afterStoryList !== false ? 1 : 0;
|
||||
$result->bugList = $afterBugList !== false ? 1 : 0;
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 productplanZen::setSessionForViewPage();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1: 所有参数都符合不设置 session 的条件,storyList 应该不被设置属性storyList @0
|
||||
- 步骤2: 所有参数都符合不设置 session 的条件,bugList 应该不被设置属性bugList @0
|
||||
- 步骤3: orderBy 不为 order_desc,应该设置 storyList属性storyList @1
|
||||
- 步骤4: type 为 bug 且 orderBy 不为 order_desc,应该设置 bugList属性bugList @1
|
||||
- 步骤5: pageID 不为 1,应该设置 storyList属性storyList @1
|
||||
- 步骤6: recPerPage 不为 100,应该设置 bugList属性bugList @1
|
||||
- 步骤7: type 不为 story 或 bug,不应该设置 storyList属性storyList @0
|
||||
- 步骤8: type 不为 story 或 bug,不应该设置 bugList属性bugList @0
|
||||
- 步骤9: 多个参数均非默认值,应该设置 storyList属性storyList @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$productplanTest = new productplanZenTest();
|
||||
|
||||
$result1 = $productplanTest->setSessionForViewPageTest(1, 'story', 'order_desc', 1, 100);
|
||||
r($result1) && p('storyList') && e('0'); // 步骤1: 所有参数都符合不设置 session 的条件,storyList 应该不被设置
|
||||
r($result1) && p('bugList') && e('0'); // 步骤2: 所有参数都符合不设置 session 的条件,bugList 应该不被设置
|
||||
r($productplanTest->setSessionForViewPageTest(1, 'story', 'id_desc', 1, 100)) && p('storyList') && e('1'); // 步骤3: orderBy 不为 order_desc,应该设置 storyList
|
||||
r($productplanTest->setSessionForViewPageTest(2, 'bug', 'id_desc', 1, 100)) && p('bugList') && e('1'); // 步骤4: type 为 bug 且 orderBy 不为 order_desc,应该设置 bugList
|
||||
r($productplanTest->setSessionForViewPageTest(3, 'story', 'order_desc', 2, 100)) && p('storyList') && e('1'); // 步骤5: pageID 不为 1,应该设置 storyList
|
||||
r($productplanTest->setSessionForViewPageTest(4, 'bug', 'order_desc', 1, 50)) && p('bugList') && e('1'); // 步骤6: recPerPage 不为 100,应该设置 bugList
|
||||
$result6 = $productplanTest->setSessionForViewPageTest(5, 'task', 'order_desc', 1, 100);
|
||||
r($result6) && p('storyList') && e('0'); // 步骤7: type 不为 story 或 bug,不应该设置 storyList
|
||||
r($result6) && p('bugList') && e('0'); // 步骤8: type 不为 story 或 bug,不应该设置 bugList
|
||||
r($productplanTest->setSessionForViewPageTest(6, 'story', 'status_asc', 5, 20)) && p('storyList') && e('1'); // 步骤9: 多个参数均非默认值,应该设置 storyList
|
||||
Reference in New Issue
Block a user