* Add unit test for actionModel::updateStageAttribute.

This commit is contained in:
wangxuepeng
2023-10-12 02:00:15 +00:00
parent 169958d9b1
commit 4bfac8f7bc
3 changed files with 55 additions and 4 deletions
+6 -4
View File
@@ -1671,13 +1671,15 @@ class actionModel extends model
* Update stage attribute.
*
* @param string $attribute
* @param array $idList
* @param array $executions
* @access public
* @return int
* @return bool
*/
public function updateStageAttribute(string $attribute, array $stages): int
public function updateStageAttribute(string $attribute, array $executions): bool
{
return $this->dao->update(TABLE_EXECUTION)->set('attribute')->eq($attribute)->where('id')->in($stages)->exec();
$this->dao->update(TABLE_EXECUTION)->set('attribute')->eq($attribute)->where('id')->in($executions)->exec();
return !dao::isError();
}
/**
+20
View File
@@ -658,4 +658,24 @@ class actionTest
return $result[0];
}
/**
* 测试更新阶段的属性。
* Test update stage attribute.
*
* @param string $attributeList
* @param array $executionID
* @access public
* @return array|bool
*/
public function updateStageAttributeTest(string $attribute, array $stages): array|bool
{
$this->objectModel->updateStageAttribute($attribute, $stages);
if(dao::isError()) return dao::getError();
global $tester;
$objects = $tester->dao->select('*')->from(TABLE_EXECUTION)->where('id')->in($stages)->fetchAll();
return $objects;
}
}
@@ -0,0 +1,29 @@
#!/usr/bin/env php
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/action.class.php';
su('admin');
zdTable('project')->gen(5);
/**
title=测试 actionModel->read();
cid=1
pid=1
测试attributeList为0,executionID为0 >> 0
测试attributeList为1,executionID为1 >> 1
测试attributeList为attribute,executionID为2 >> 3,attribute;4,attribute
*/
$attributeList = array(0, 1, 'attribute');
$executionID = array(array(1), array(2), array(3, 4));
$action = new actionTest();
r($action->updateStageAttributeTest($attributeList[0], $executionID[0])) && p('0:id,attribute') && e('1,0'); //测试attributeList为0,executionID为0
r($action->updateStageAttributeTest($attributeList[1], $executionID[1])) && p('0:id,attribute') && e('2,1'); //测试attributeList为1,executionID为1
r($action->updateStageAttributeTest($attributeList[2], $executionID[2])) && p('0:id,attribute;1:id,attribute') && e('3,attribute;4,attribute'); //测试attributeList为attribute,executionID为2