+ [misc] Add unit tests for testcaseZen::checkProducts() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -3107,4 +3107,66 @@ class testcaseZenTest
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkProducts method.
|
||||
*
|
||||
* @param string $tab
|
||||
* @param int $projectID
|
||||
* @param int $executionID
|
||||
* @param bool $hasProducts
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function checkProductsTest(string $tab = 'qa', int $projectID = 0, int $executionID = 0, bool $hasProducts = true): array
|
||||
{
|
||||
global $tester;
|
||||
|
||||
// 保存原始状态
|
||||
$originalTab = $tester->app->tab;
|
||||
$originalProject = isset($tester->session->project) ? $tester->session->project : null;
|
||||
$originalExecution = isset($tester->session->execution) ? $tester->session->execution : null;
|
||||
|
||||
try {
|
||||
// 设置测试环境
|
||||
$tester->app->tab = $tab;
|
||||
if($tab == 'project') $tester->session->set('project', $projectID);
|
||||
if($tab == 'execution') $tester->session->set('execution', $executionID);
|
||||
|
||||
// 设置 products 属性
|
||||
if($hasProducts)
|
||||
{
|
||||
$product = new stdClass();
|
||||
$product->id = 1;
|
||||
$product->name = 'Test Product';
|
||||
$this->testcaseZenTest->products = array($product);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->testcaseZenTest->products = array();
|
||||
}
|
||||
|
||||
// 调用被测方法
|
||||
try {
|
||||
callZenMethod('testcase', 'checkProducts', array());
|
||||
$success = 1;
|
||||
$error = '';
|
||||
} catch(Exception $e) {
|
||||
$success = 0;
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return array(
|
||||
'success' => $success,
|
||||
'error' => $error,
|
||||
'tab' => $tab,
|
||||
'hasProducts' => $hasProducts ? 1 : 0
|
||||
);
|
||||
} finally {
|
||||
// 恢复原始环境
|
||||
$tester->app->tab = $originalTab;
|
||||
if($originalProject !== null) $tester->session->set('project', $originalProject);
|
||||
if($originalExecution !== null) $tester->session->set('execution', $originalExecution);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Executable
+47
@@ -0,0 +1,47 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 testcaseZen::checkProducts();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:qa tab,有产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性tab @qa
|
||||
- 步骤2:project tab,有产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性tab @project
|
||||
- 步骤3:execution tab,有产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性tab @execution
|
||||
- 步骤4:qa tab,无产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性hasProducts @0
|
||||
- 步骤5:project tab,无产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性hasProducts @0
|
||||
- 步骤6:execution tab,无产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性hasProducts @0
|
||||
- 步骤7:other tab,有产品,成功执行
|
||||
- 属性success @1
|
||||
- 属性tab @other
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/testcasezen.unittest.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$testcaseTest = new testcaseZenTest();
|
||||
|
||||
r($testcaseTest->checkProductsTest('qa', 0, 0, true)) && p('success;tab') && e('1;qa'); // 步骤1:qa tab,有产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('project', 1, 0, true)) && p('success;tab') && e('1;project'); // 步骤2:project tab,有产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('execution', 0, 1, true)) && p('success;tab') && e('1;execution'); // 步骤3:execution tab,有产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('qa', 0, 0, false)) && p('success;hasProducts') && e('1;0'); // 步骤4:qa tab,无产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('project', 1, 0, false)) && p('success;hasProducts') && e('1;0'); // 步骤5:project tab,无产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('execution', 0, 1, false)) && p('success;hasProducts') && e('1;0'); // 步骤6:execution tab,无产品,成功执行
|
||||
r($testcaseTest->checkProductsTest('other', 0, 0, true)) && p('success;tab') && e('1;other'); // 步骤7:other tab,有产品,成功执行
|
||||
Reference in New Issue
Block a user