diff --git a/module/product/test/lib/zen.class.php b/module/product/test/lib/zen.class.php index 4b4e730caf..dfd9092717 100644 --- a/module/product/test/lib/zen.class.php +++ b/module/product/test/lib/zen.class.php @@ -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. * diff --git a/module/product/test/zen/setprojectmenu.php b/module/product/test/zen/setprojectmenu.php new file mode 100755 index 0000000000..317facf92b --- /dev/null +++ b/module/product/test/zen/setprojectmenu.php @@ -0,0 +1,39 @@ +#!/usr/bin/env php +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值 \ No newline at end of file