+ [misc] Add unit tests for productZen::setProjectMenu() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1202,6 +1202,46 @@ class productZenTest extends baseTest
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setProjectMenu method.
|
||||
*
|
||||
* @param int $productID
|
||||
* @param string $branch
|
||||
* @param string $preBranch
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function setProjectMenuTest(int $productID = 0, string $branch = '', string $preBranch = '')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
$executionSuccess = 0;
|
||||
ob_start();
|
||||
try {
|
||||
$this->invokeArgs('setProjectMenu', array($productID, $branch, $preBranch));
|
||||
$executionSuccess = 1;
|
||||
} catch (Throwable $e) {}
|
||||
ob_end_clean();
|
||||
|
||||
/* Get cookie value after execution. */
|
||||
$cookiePreBranch = isset($_COOKIE['preBranch']) ? $_COOKIE['preBranch'] : '';
|
||||
|
||||
/* Calculate expected branch value. */
|
||||
$expectedBranch = ($preBranch !== '' && $branch === '') ? $preBranch : $branch;
|
||||
|
||||
$result = array(
|
||||
'productID' => $productID,
|
||||
'inputBranch' => $branch,
|
||||
'inputPreBranch' => $preBranch,
|
||||
'cookiePreBranch' => $cookiePreBranch,
|
||||
'branchMatch' => ($cookiePreBranch === $expectedBranch) ? 1 : 0,
|
||||
'executionSuccess' => $executionSuccess
|
||||
);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test setMenu4All method.
|
||||
*
|
||||
|
||||
Executable
+39
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 productZen::setProjectMenu();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:正常场景,传入有效的productID和branch
|
||||
- 属性executionSuccess @1
|
||||
- 属性branchMatch @1
|
||||
- 步骤2:branch为空但preBranch有值
|
||||
- 属性branchMatch @1
|
||||
- 属性executionSuccess @1
|
||||
- 步骤3:branch和preBranch都为空
|
||||
- 属性branchMatch @1
|
||||
- 属性executionSuccess @1
|
||||
- 步骤4:branch有值,preBranch也有值
|
||||
- 属性branchMatch @1
|
||||
- 属性executionSuccess @1
|
||||
- 步骤5:传入不同的branch值
|
||||
- 属性branchMatch @1
|
||||
- 属性executionSuccess @1
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/zen.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$productTest = new productZenTest();
|
||||
|
||||
r($productTest->setProjectMenuTest(1, 'main', '')) && p('executionSuccess,branchMatch') && e('1,1'); // 步骤1:正常场景,传入有效的productID和branch
|
||||
r($productTest->setProjectMenuTest(1, '', 'dev')) && p('branchMatch,executionSuccess') && e('1,1'); // 步骤2:branch为空但preBranch有值
|
||||
r($productTest->setProjectMenuTest(2, '', '')) && p('branchMatch,executionSuccess') && e('1,1'); // 步骤3:branch和preBranch都为空
|
||||
r($productTest->setProjectMenuTest(3, 'test', 'dev')) && p('branchMatch,executionSuccess') && e('1,1'); // 步骤4:branch有值,preBranch也有值
|
||||
r($productTest->setProjectMenuTest(1, 'feature', '')) && p('branchMatch,executionSuccess') && e('1,1'); // 步骤5:传入不同的branch值
|
||||
Reference in New Issue
Block a user