+ [misc] Add unit tests for executionZen::checkLinkPlan() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -2179,4 +2179,54 @@ class executionZenTest
|
||||
|
||||
return $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test checkLinkPlan method.
|
||||
*
|
||||
* @param int $executionID
|
||||
* @param array $oldPlans
|
||||
* @param array $postPlans
|
||||
* @access public
|
||||
* @return mixed
|
||||
*/
|
||||
public function checkLinkPlanTest(int $executionID, array $oldPlans, array $postPlans = array())
|
||||
{
|
||||
global $tester;
|
||||
|
||||
$method = $this->executionZenTest->getMethod('checkLinkPlan');
|
||||
$method->setAccessible(true);
|
||||
|
||||
if(!empty($postPlans))
|
||||
{
|
||||
$_POST['plans'] = $postPlans;
|
||||
}
|
||||
else
|
||||
{
|
||||
unset($_POST['plans']);
|
||||
}
|
||||
|
||||
$executionZen = new executionZen();
|
||||
|
||||
ob_start();
|
||||
try {
|
||||
$result = $method->invoke($executionZen, $executionID, $oldPlans);
|
||||
ob_end_clean();
|
||||
if(dao::isError()) return dao::getError();
|
||||
return $result;
|
||||
}
|
||||
catch(EndResponseException $e)
|
||||
{
|
||||
ob_end_clean();
|
||||
$content = $e->getContent();
|
||||
if(strpos($content, '{') !== false && strpos($content, '}') !== false)
|
||||
{
|
||||
$jsonStart = strpos($content, '{');
|
||||
$jsonEnd = strrpos($content, '}') + 1;
|
||||
$jsonStr = substr($content, $jsonStart, $jsonEnd - $jsonStart);
|
||||
$result = json_decode($jsonStr, true);
|
||||
if($result !== null && isset($result['message'])) return $result['message'];
|
||||
}
|
||||
return $content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 executionZen::checkLinkPlan();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 测试步骤1:没有新计划关联 @0
|
||||
- 测试步骤2:有新计划关联 @保存成功
|
||||
- 测试步骤3:有多个新计划关联 @保存成功
|
||||
- 测试步骤4:oldPlans为空,POST中有plans @保存成功
|
||||
- 测试步骤5:oldPlans有值,POST中plans为空 @0
|
||||
- 测试步骤6:oldPlans和POST plans都为空 @0
|
||||
- 测试步骤7:POST plans中包含空值和0值 @保存成功
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/executionzen.unittest.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
$executionTest = new executionZenTest();
|
||||
|
||||
r($executionTest->checkLinkPlanTest(1, array(1, 2), array(array(1, 2)))) && p() && e('0'); // 测试步骤1:没有新计划关联
|
||||
r($executionTest->checkLinkPlanTest(1, array(1, 2), array(array(1, 2, 3)))) && p() && e('保存成功'); // 测试步骤2:有新计划关联
|
||||
r($executionTest->checkLinkPlanTest(1, array(1, 2), array(array(1, 2, 4, 5)))) && p() && e('保存成功'); // 测试步骤3:有多个新计划关联
|
||||
r($executionTest->checkLinkPlanTest(1, array(), array(array(1, 2)))) && p() && e('保存成功'); // 测试步骤4:oldPlans为空,POST中有plans
|
||||
r($executionTest->checkLinkPlanTest(1, array(1, 2), array())) && p() && e('0'); // 测试步骤5:oldPlans有值,POST中plans为空
|
||||
r($executionTest->checkLinkPlanTest(1, array(), array())) && p() && e('0'); // 测试步骤6:oldPlans和POST plans都为空
|
||||
r($executionTest->checkLinkPlanTest(1, array(1), array(array(1, 2, '', 0, 3)))) && p() && e('保存成功'); // 测试步骤7:POST plans中包含空值和0值
|
||||
Reference in New Issue
Block a user