diff --git a/module/execution/test/lib/executionzen.unittest.class.php b/module/execution/test/lib/executionzen.unittest.class.php index 9783c0b555..4051c4c3f6 100755 --- a/module/execution/test/lib/executionzen.unittest.class.php +++ b/module/execution/test/lib/executionzen.unittest.class.php @@ -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; + } + } } diff --git a/module/execution/test/zen/checklinkplan.php b/module/execution/test/zen/checklinkplan.php new file mode 100755 index 0000000000..3586eeb394 --- /dev/null +++ b/module/execution/test/zen/checklinkplan.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +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值 \ No newline at end of file