diff --git a/module/testcase/model.php b/module/testcase/model.php
index 8b8a5a0a02..7ab4d5989c 100644
--- a/module/testcase/model.php
+++ b/module/testcase/model.php
@@ -1176,14 +1176,17 @@ class testcaseModel extends model
}
/**
+ * 从 bug 的步骤创建用例步骤。
* Create case steps from a bug's step.
*
- * @param string $steps
+ * @param string $steps
* @access public
* @return array
*/
- function createStepsFromBug($steps)
+ public function createStepsFromBug(string $steps): array
{
+ /* 初始化步骤相关变量,获取步骤的描述、结果和期望,以及他们在字符串中的位置。 */
+ /* Initializes the step variable, and get the desc, result and expect of the step and its position. */
$steps = strip_tags($steps);
$caseSteps = array((object)array('desc' => $steps, 'expect' => '')); // the default steps before parse.
$lblStep = strip_tags($this->lang->bug->tplStep);
@@ -1193,13 +1196,19 @@ class testcaseModel extends model
$lblResultPos = strpos($steps, $lblResult);
$lblExpectPos = strpos($steps, $lblExpect);
- if($lblStepPos === false or $lblResultPos === false or $lblExpectPos === false) return $caseSteps;
+ /* 如果 bug 的步骤没有描述、结果或者期望,返回默认步骤。 */
+ /* If steps don't have desc, result or expect, return default steps. */
+ if($lblStepPos === false || $lblResultPos === false || $lblExpectPos === false) return $caseSteps;
+ /* 计算描述和期望。 */
+ /* Process desc and expect. */
$caseSteps = substr($steps, $lblStepPos + strlen($lblStep), $lblResultPos - strlen($lblStep) - $lblStepPos);
$caseExpect = substr($steps, $lblExpectPos + strlen($lblExpect));
$caseSteps = trim($caseSteps);
$caseExpect = trim($caseExpect);
+ /* 计算步骤。 */
+ /* Process steps. */
$caseSteps = explode("\n", trim($caseSteps));
$stepCount = count($caseSteps);
foreach($caseSteps as $key => $caseStep)
@@ -1207,6 +1216,7 @@ class testcaseModel extends model
$expect = $key + 1 == $stepCount ? $caseExpect : '';
$caseSteps[$key] = (object)array('desc' => trim($caseStep), 'expect' => $expect, 'type' => 'item');
}
+
return $caseSteps;
}
diff --git a/module/testcase/test/model/createstepsformbug.php b/module/testcase/test/model/createstepsformbug.php
new file mode 100644
index 0000000000..3e05f43a20
--- /dev/null
+++ b/module/testcase/test/model/createstepsformbug.php
@@ -0,0 +1,27 @@
+#!/usr/bin/env php
+createStepsFromBug();
+cid=1
+pid=1
+
+
+*/
+
+$testcase = new testcaseTest();
+
+$steps1 = "
[步骤]
一个步骤\n[结果]
一个结果\n
[期望]
一个期望\n
";
+$steps2 = "[步骤]
1. 步骤1\n2. 步骤2
[结果]
1. 结果1\n2. 结果2\n
[期望]
期望\n
";
+$noStep = "[结果]
一个结果\n[期望]
一个期望\n";
+$noResult = "[步骤]
一个步骤\n[期望]
一个期望\n";
+$noExpect = "[步骤]
一个步骤\n[结果]
一个结果\n";
+
+r($testcase->createStepsFromBugTest($steps1)) && p() && e('step:一个步骤 expect:一个期望 type:item.'); // 测试从 bug 中创建步骤 steps1
+r($testcase->createStepsFromBugTest($steps2)) && p() && e('step:1. 步骤1 expect: type:item. step:2. 步骤2 expect:期望 type:item.'); // 测试从 bug 中创建步骤 steps2
+r($testcase->createStepsFromBugTest($noStep)) && p() && e('step:[结果]一个结果 [期望]一个期望 expect:'); // 测试从 bug 中创建步骤 没有步骤
+r($testcase->createStepsFromBugTest($noResult)) && p() && e('step:[步骤]一个步骤 [期望]一个期望 expect:'); // 测试从 bug 中创建步骤 没有结果
+r($testcase->createStepsFromBugTest($noExpect)) && p() && e('step:[步骤]一个步骤 [结果]一个结果 expect:'); // 测试从 bug 中创建步骤 没有期望
diff --git a/module/testcase/test/testcase.class.php b/module/testcase/test/testcase.class.php
index c242194ae6..b1a00bbf6c 100644
--- a/module/testcase/test/testcase.class.php
+++ b/module/testcase/test/testcase.class.php
@@ -1157,4 +1157,38 @@ class testcaseTest
foreach($configs as $config) $return .= "{$config->key}:{$config->value},";
return trim($return, ',');
}
+
+ /**
+ * 测试从 bug 的步骤创建用例步骤。
+ * Test create case steps from a bug's step.
+ *
+ * @param string $steps
+ * @access public
+ * @return array|string
+ */
+ public function createStepsFromBugTest(string $steps): array|string
+ {
+ $array = $this->objectModel->createStepsFromBug($steps);
+
+ if(dao::isError()) return dao::getError();
+
+ $return = '';
+ foreach($array as $key => $step)
+ {
+ if(!isset($step->type))
+ {
+ $step->desc = explode("\n", trim($step->desc));
+
+ $return .= 'step:';
+ foreach($step->desc as $desc) $return .= $desc . ' ';
+ $return .= "expect:{$step->expect}";
+ }
+ else
+ {
+ $return .= "step:{$step->desc} expect:{$step->expect} type:{$step->type}. ";
+ }
+ }
+
+ return trim($return);
+ }
}
diff --git a/module/testtask/config/action.php b/module/testtask/config/action.php
index 7d9d907ec5..56ad12238b 100644
--- a/module/testtask/config/action.php
+++ b/module/testtask/config/action.php
@@ -76,8 +76,8 @@ $config->testtask->cases->actionList['confirmChange']['class'] = 'ajax-submit';
$config->testtask->cases->actionList['createBug']['icon'] = 'bug';
$config->testtask->cases->actionList['createBug']['text'] = $lang->testcase->createBug;
$config->testtask->cases->actionList['createBug']['hint'] = $lang->testcase->createBug;
-$config->testtask->cases->actionList['createBug']['url'] = array('module' => 'testcase', 'method' => 'createBug', 'params' => 'product={product}&branch={branch}&extra=executionID=%execution%,buildID=%build%,caseID={case},version={version},runID={id},testtask=%testtask%', 'data-width' => '90%');
-$config->testtask->cases->actionList['createBug']['data-width'] = '90%';
+$config->testtask->cases->actionList['createBug']['url'] = array('module' => 'testcase', 'method' => 'createBug', 'params' => 'product={product}&extra=executionID=%execution%,buildID=%build%,caseID={case},version={version},runID={id},testtask=%testtask%', 'data-width' => '90%');
+$config->testtask->cases->actionList['createBug']['data-width'] = 'lg';
$config->testtask->cases->actionList['createBug']['data-toggle'] = 'modal';
$config->testtask->cases->actionList['runCase']['icon'] = 'play';