+ Add unit test case for mr->close.
This commit is contained in:
+10
-4
@@ -1024,13 +1024,16 @@ class mrModel extends model
|
||||
*/
|
||||
public function close(object $MR): array
|
||||
{
|
||||
$link = helper::createLink('mr', 'view', "mr={$MR->id}");
|
||||
if($MR->status == 'closed') return array('result' => 'fail', 'message' => $this->lang->mr->repeatedOperation, 'load' => $link);
|
||||
|
||||
$actionID = $this->loadModel('action')->create('mr', $MR->id, 'closed');
|
||||
$rawMR = $this->apiCloseMR($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
$changes = common::createChanges($MR, $rawMR);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
|
||||
if(isset($rawMR->state) && $rawMR->state == 'closed') return array('result' => 'success', 'message' => $this->lang->mr->closeSuccess, 'load' => helper::createLink('mr', 'view', "mr={$MR->id}"));
|
||||
return array('result' => 'fail', 'message' => $this->lang->fail, 'load' => helper::createLink('mr', 'view', "mr={$MR->id}"));
|
||||
if(isset($rawMR->state) && $rawMR->state == 'closed') return array('result' => 'success', 'message' => $this->lang->mr->closeSuccess, 'load' => $link);
|
||||
return array('result' => 'fail', 'message' => $this->lang->fail, 'load' => $link);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1043,13 +1046,16 @@ class mrModel extends model
|
||||
*/
|
||||
public function reopen(object $MR): array
|
||||
{
|
||||
$link = helper::createLink('mr', 'view', "mr={$MR->id}");
|
||||
if($MR->status == 'opened') return array('result' => 'fail', 'message' => $this->lang->mr->repeatedOperation, 'load' => $link);
|
||||
|
||||
$actionID = $this->loadModel('action')->create('mr', $MR->id, 'reopen');
|
||||
$rawMR = $this->apiReopenMR($MR->hostID, $MR->targetProject, $MR->mriid);
|
||||
$changes = common::createChanges($MR, $rawMR);
|
||||
$this->action->logHistory($actionID, $changes);
|
||||
|
||||
if(isset($rawMR->state) && $rawMR->state == 'opened') return array('result' => 'success', 'message' => $this->lang->mr->reopenSuccess, 'load' => helper::createLink('mr', 'view', "mr={$MR->id}"));
|
||||
return array('result' => 'fail', 'message' => $this->lang->fail, 'load' => helper::createLink('mr', 'view', "mr={$MR->id}"));
|
||||
if(isset($rawMR->state) && $rawMR->state == 'opened') return array('result' => 'success', 'message' => $this->lang->mr->reopenSuccess, 'load' => $link);
|
||||
return array('result' => 'fail', 'message' => $this->lang->fail, 'load' => $link);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Regular → Executable
+5
-1
@@ -7,6 +7,10 @@ title=测试 mrModel::approve();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 正常的合并请求审批拒绝属性message @保存成功
|
||||
- 正常的合并请求审批通过属性message @保存成功
|
||||
- 已合并状态的合并请求审批通过属性message @请勿重复操作
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
@@ -23,4 +27,4 @@ $otherMR = 2;
|
||||
r($mrModel->approveTester($openedMR, 'reject')) && p('message') && e('保存成功'); // 正常的合并请求审批拒绝
|
||||
r($mrModel->approveTester($openedMR, 'approve')) && p('message') && e('保存成功'); // 正常的合并请求审批通过
|
||||
|
||||
r($mrModel->approveTester($otherMR, 'approve')) && p('message') && e('请勿重复操作'); // 已合并状态的合并请求审批通过
|
||||
r($mrModel->approveTester($otherMR, 'approve')) && p('message') && e('请勿重复操作'); // 已合并状态的合并请求审批通过
|
||||
Executable
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 mrModel::close();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 正常的合并请求属性message @已关闭合并请求。
|
||||
- 已关闭状态的合并请求属性message @请勿重复操作
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/mr.class.php';
|
||||
|
||||
zdTable('mr')->config('mr')->gen(3);
|
||||
su('admin');
|
||||
|
||||
$mrModel = new mrTest();
|
||||
|
||||
$openedMR = 1;
|
||||
$otherMR = 3;
|
||||
|
||||
r($mrModel->closeTester($openedMR)) && p('message') && e('已关闭合并请求。'); // 正常的合并请求
|
||||
r($mrModel->closeTester($otherMR)) && p('message') && e('请勿重复操作'); // 已关闭状态的合并请求
|
||||
@@ -293,4 +293,36 @@ class mrTest
|
||||
$this->objectModel->dao->update(TABLE_MR)->set('status')->eq($MR->status)->set('approvalStatus')->eq('')->where('id')->eq($MRID)->exec();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test close method.
|
||||
*
|
||||
* @param int $MRID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function closeTester(int $MRID): array
|
||||
{
|
||||
$MR = $this->objectModel->fetchByID($MRID);
|
||||
|
||||
$result = $this->objectModel->close($MR);
|
||||
if($MR->status != 'closed') $this->objectModel->reopen($MR);
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test reopen method.
|
||||
*
|
||||
* @param int $MRID
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function reopenTester(int $MRID): array
|
||||
{
|
||||
$MR = $this->objectModel->fetchByID($MRID);
|
||||
|
||||
$result = $this->objectModel->reopen($MR);
|
||||
if($MR->status != 'opend') $this->objectModel->close($MR);
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user