From aca053e650fa94c5c8fabee6418d2bf760f323c1 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Wed, 31 May 2023 10:01:41 +0800 Subject: [PATCH] * Refactor doCreateStory method and add unit test. --- module/story/tao.php | 10 ++++- module/story/test/story.class.php | 17 +++++++++ module/story/test/tao/docreatestory.php | 49 +++++++++++++++++++++++++ module/story/zen.php | 36 ++++++++++-------- 4 files changed, 96 insertions(+), 16 deletions(-) create mode 100755 module/story/test/tao/docreatestory.php diff --git a/module/story/tao.php b/module/story/tao.php index b7ea09c8f8..7b13f33b34 100644 --- a/module/story/tao.php +++ b/module/story/tao.php @@ -639,9 +639,17 @@ class storyTao extends storyModel ->fetchAll(); } + /** + * 将需求数据插入到需求表。 + * Do create story data. + * + * @param object $story + * @access protected + * @return int|false + */ protected function doCreateStory(object $story): int|false { - $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,reviewer,URS,region,lane') + $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,reviewer,URS,region,lane,branches,plans,modules') ->autoCheck() ->checkIF($story->notifyEmail, 'notifyEmail', 'email') ->checkFlow() diff --git a/module/story/test/story.class.php b/module/story/test/story.class.php index 34198a5133..adeafd5c5d 100644 --- a/module/story/test/story.class.php +++ b/module/story/test/story.class.php @@ -738,4 +738,21 @@ class storyTest if(dao::isError()) return dao::getError(); return $this->objectModel->dao->select('*')->from(TABLE_STORYSPEC)->fetchAll(); } + + /** + * 测试 doCreateStory 方法。 + * Test doCreateStory method. + * + * @param object $story + * @access public + * @return object|array + */ + public function doCreateStoryTest(object $story): object|array + { + $this->objectModel->dao->delete()->from(TABLE_STORY)->exec(); + $storyID = $this->objectModel->doCreateStory($story); + + if(dao::isError()) return dao::getError(); + return $this->objectModel->dao->select('*')->from(TABLE_STORY)->where('id')->eq($storyID)->fetch(); + } } diff --git a/module/story/test/tao/docreatestory.php b/module/story/test/tao/docreatestory.php new file mode 100755 index 0000000000..75e1dee4c7 --- /dev/null +++ b/module/story/test/tao/docreatestory.php @@ -0,0 +1,49 @@ +#!/usr/bin/env php +gen(0); + +/** + +title=测试 storyModel->doCreateStory(); +cid=1 +pid=1 + +*/ + +$data = new stdclass(); +$data->product = 1; +$data->module = 0; +$data->modules = array(0); +$data->plans = array(0); +$data->plan = 0; +$data->assignedTo = ''; +$data->source = ''; +$data->sourceNote = ''; +$data->feedbackBy = ''; +$data->notifyEmail = ''; +$data->parent = 0; +$data->title = 'test story'; +$data->color = ''; +$data->category = 'feature'; +$data->pri = 3; +$data->estimate = 1; +$data->spec = 'test spec'; +$data->verify = 'test verify'; +$data->keywords = ''; +$data->type = 'story'; +$data->status = 'active'; +$data->version = 1; +$data->openedBy = 'admin'; +$data->openedDate = date('Y-m-d H:i:s'); + +$storyTest = new storyTest(); +$story = $storyTest->doCreateStoryTest($data); +r($story) && p('product,title,status') && e('1,test story,active'); //检查保存后的数据。 + +$data->notifyEmail = 'test'; +$error = $storyTest->doCreateStoryTest($data); +r($error['notifyEmail'][0]) && p() && e('『通知邮箱』应当为合法的EMAIL。'); //检查报错信息。 diff --git a/module/story/zen.php b/module/story/zen.php index 6cbdcdc0cf..a895a3dac7 100644 --- a/module/story/zen.php +++ b/module/story/zen.php @@ -258,12 +258,13 @@ class storyZen extends story } $branch = current(explode(',', $branch)); - $product = $this->product->getByID($productID); - $users = $this->user->getPairs('pdfirst|noclosed|nodeleted'); - $stories = $this->story->getParentStoryPairs($productID); - $plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch == 0 ? '' : $branch, 'skipParent|unexpired|noclosed'); - $plans = array_map(function($planName){return str_replace(FUTURE_TIME, $this->lang->story->undetermined, $planName);}, $plans); - $needReview = ($account == $product->PO || $objectID > 0 || $this->config->story->needReview == 0 || !$this->story->checkForceReview()); + $product = $this->product->getByID($productID); + $users = $this->user->getPairs('pdfirst|noclosed|nodeleted'); + $stories = $this->story->getParentStoryPairs($productID); + $plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch == 0 ? '' : $branch, 'skipParent|unexpired|noclosed'); + $plans = array_map(function($planName){return str_replace(FUTURE_TIME, $this->lang->story->undetermined, $planName);}, $plans); + $forceReview = $this->story->checkForceReview(); + $needReview = ($account == $product->PO || $objectID > 0 || $this->config->story->needReview == 0 || !$forceReview); $reviewers = $product->reviewer; if(!$reviewers and $product->acl != 'open') $reviewers = $this->loadModel('user')->getProductViewListUsers($product, '', '', '', ''); @@ -295,17 +296,20 @@ class storyZen extends story if(empty($fields['branch']['default'])) $fields['branch']['default'] = $branch; if(empty($fields['branches']['default'])) $fields['branches']['default'] = $branch; if(empty($fields['plans']['default'])) $fields['plans']['default'] = zget($initStory, 'plan', 0); - if(empty($needReview)) $fields['reviewer']['default'] = $product->PO; + + if(empty($needReview)) $fields['reviewer']['default'] = $product->PO; + if($forceReview) $fields['reviewer']['required'] = true; /* 删除不需要的字段。 */ if(empty($branches)) unset($fields['branch'], $fields['branches'], $fields['modules'], $fields['plans']); - $this->view->productID = $productID; - $this->view->product = $product; - $this->view->branch = $branch; - $this->view->branches = $branches; - $this->view->objectID = $objectID; - $this->view->needReview = $needReview; + $this->view->productID = $productID; + $this->view->product = $product; + $this->view->branch = $branch; + $this->view->branches = $branches; + $this->view->objectID = $objectID; + $this->view->forceReview = $forceReview; + $this->view->needReview = $needReview; return $fields; } @@ -393,11 +397,13 @@ class storyZen extends story /* Set Custom. */ $customFields = explode(',', $this->config->story->list->customCreateFields); - $showFields = explode(',', trim($this->config->story->custom->createFields, ',')); + $showFields = trim($this->config->story->custom->createFields, ','); foreach($customFields as $field) { - if(!str_contains($showFields, $field)) $fields[$field]['control'] = ''; + if(!str_contains($showFields, $field)) unset($fields[$field]['control']); } + + return $fields; } /**