* Add the score auto test case.
This commit is contained in:
+17
-10
@@ -47,6 +47,8 @@ class scoreModel extends model
|
||||
|
||||
if(is_numeric($param)) $desc .= 'ID:' . $param;
|
||||
|
||||
$object = '';
|
||||
|
||||
switch($module)
|
||||
{
|
||||
case 'user':
|
||||
@@ -65,12 +67,13 @@ class scoreModel extends model
|
||||
if($method == 'close')
|
||||
{
|
||||
$openedBy = $this->dao->findById($param)->from(TABLE_STORY)->fetch('openedBy');
|
||||
$object = true;
|
||||
|
||||
if(!empty($openedBy))
|
||||
{
|
||||
$newRule = $rule;
|
||||
$newRule['score'] = $extended['createID'];
|
||||
$this->saveScore($openedBy, $newRule, $module, $method, $desc, $time);
|
||||
$object = $this->saveScore($openedBy, $newRule, $module, $method, $desc, $time);
|
||||
unset($newRule);
|
||||
}
|
||||
}
|
||||
@@ -93,7 +96,7 @@ class scoreModel extends model
|
||||
|
||||
if(!empty($task->estimate))
|
||||
{
|
||||
$rule['score'] = $rule['score'] + (empty($task->consumed) ? 0 : round($task->consumed / 10 * $task->estimate / $task->consumed));
|
||||
$rule['score'] = $rule['score'] + (empty($task->consumed) ? 0 : round($task->consumed / 10.0 * $task->estimate / $task->consumed));
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -130,6 +133,7 @@ class scoreModel extends model
|
||||
{
|
||||
$desc = $this->lang->score->methods[$module][$method] . ',' . $desc . 'ID:' . $param->id;
|
||||
$timestamp = empty($time) ? time() : strtotime($time);
|
||||
$object = true;
|
||||
|
||||
/* Project PM. */
|
||||
if(!empty($param->PM))
|
||||
@@ -139,7 +143,7 @@ class scoreModel extends model
|
||||
{
|
||||
$rule['score'] += $extended['manager']['onTime'];
|
||||
}
|
||||
$this->saveScore($param->PM, $rule, $module, $method, $desc, $time);
|
||||
$object = $this->saveScore($param->PM, $rule, $module, $method, $desc, $time);
|
||||
}
|
||||
|
||||
/* Project team user. */
|
||||
@@ -154,13 +158,11 @@ class scoreModel extends model
|
||||
|
||||
foreach($teams as $user)
|
||||
{
|
||||
if($user != $param->PM) $this->saveScore($user, $rule, $module, $method, $desc, $time);
|
||||
if($user != $param->PM) $object = $this->saveScore($user, $rule, $module, $method, $desc, $time);
|
||||
}
|
||||
}
|
||||
|
||||
/* When the execution is closed, no more user get score. */
|
||||
return true;
|
||||
}
|
||||
|
||||
break;
|
||||
case 'search':
|
||||
if($method == 'saveQueryAdvanced') $desc = $this->lang->score->methods[$module][$method];
|
||||
@@ -169,7 +171,10 @@ class scoreModel extends model
|
||||
$desc = $this->lang->score->methods[$module][$method];
|
||||
break;
|
||||
}
|
||||
$this->saveScore($user, $rule, $module, $method, $desc, $time);
|
||||
|
||||
$object = $object === '' ? $this->saveScore($user, $rule, $module, $method, $desc, $time) : $object;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -182,8 +187,8 @@ class scoreModel extends model
|
||||
* @param string $desc
|
||||
* @param string $time
|
||||
*
|
||||
* @access private
|
||||
* @return bool
|
||||
* @access public
|
||||
* @return object|bool
|
||||
*/
|
||||
public function saveScore($account = '', $rule = array(), $module = '', $method = '', $desc = '', $time = '')
|
||||
{
|
||||
@@ -222,6 +227,8 @@ class scoreModel extends model
|
||||
$this->dao->insert(TABLE_SCORE)->data($data)->exec();
|
||||
|
||||
$this->dao->update(TABLE_USER)->set("`score`=`score` + " . (int)$rule['score'])->set("`scoreLevel`=`scoreLevel` + " . (int)$rule['score'])->where('account')->eq($account)->exec();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php
|
||||
class scoreTest
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
global $tester;
|
||||
$this->objectModel = $tester->loadModel('score');
|
||||
}
|
||||
|
||||
public function getListByAccountTest($account, $pager, $needCount = false)
|
||||
{
|
||||
$objects = $this->objectModel->getListByAccount($account, $pager);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $needCount ? count($objects) : $objects;
|
||||
}
|
||||
|
||||
public function createTest($module = '', $method = '', $param = '', $account = '', $time = '')
|
||||
{
|
||||
global $tester;
|
||||
|
||||
$object = $this->objectModel->create($module, $method, $param, $account, $time);
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
return dao::getError();
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = (!empty((array) $object) and is_object($object)) ? $object : '';
|
||||
}
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
public function saveScoreTest($account = '', $rule = array(), $module = '', $method = '', $desc = '', $time = '')
|
||||
{
|
||||
$objects = $this->objectModel->saveScore($account, $rule, $module, $method, $desc, $time);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function resetTest($lastID = 0)
|
||||
{
|
||||
$result = $this->objectModel->reset($lastID);
|
||||
while($result['status'] != 'finish')
|
||||
{
|
||||
$result = $this->objectModel->reset($result['lastID']);
|
||||
}
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function fixKeyTest($string)
|
||||
{
|
||||
$objects = $this->objectModel->fixKey($string);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function getNoticeTest()
|
||||
{
|
||||
$objects = $this->objectModel->getNotice();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/score.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 scoreModel->create();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$moduleList = array('user', 'story', 'task', 'bug', 'execution', 'product');
|
||||
$methodList = array('login', 'close', 'finish', 'confirmBug', 'close', 'edit');
|
||||
$accountList = array('admin', 'dev10', 'test10', 'top10');
|
||||
|
||||
$bug = new stdclass();
|
||||
$bug->id = '1';
|
||||
$bug->openedBy = 'admin';
|
||||
$bug->severity = '1';
|
||||
|
||||
$execution = new stdclass();
|
||||
$execution->id = '701';
|
||||
$execution->PM = 'admin';
|
||||
$execution->end = '2022-05-14';
|
||||
|
||||
$score = new scoreTest();
|
||||
|
||||
r($score->createTest($moduleList[1], $methodList[1], '402')) && p('') && e('0'); // 关闭一个不存在创建者的需求
|
||||
r($score->createTest($moduleList[1], $methodList[1], '9')) && p('score') && e('2'); // 关闭一个存在创建者的需求
|
||||
r($score->createTest($moduleList[2], $methodList[2], '601')) && p('') && e('0'); // ID为601 的任务有子任务,完成不计算积分
|
||||
r($score->createTest($moduleList[2], $methodList[2], '2')) && p('score') && e('2'); // ID为2 的任务,优先级为2,消耗4h, 预计1h
|
||||
r($score->createTest($moduleList[3], $methodList[3], $bug)) && p('score') && e('4'); // 确认严重程度为1的bug
|
||||
r($score->createTest($moduleList[4], $methodList[4], $execution, 'admin', '2022-05-11')) && p('score') && e('30'); // 在截止时间内关闭一个项目经理为admin的执行
|
||||
r($score->createTest($moduleList[5], $methodList[5])) && p('') && e('0'); // product模块的edit方法不存在与积分规则中,不计算积分
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/score.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 scoreModel->fixKey();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$actionList = array('created', 'opened', 'bugconfirmed', 'fixed');
|
||||
|
||||
$score = new scoreTest();
|
||||
|
||||
r($score->fixKeyTest($actionList[0])) && p('') && e('create'); // action为created
|
||||
r($score->fixKeyTest($actionList[1])) && p('') && e('create'); // action为opened
|
||||
r($score->fixKeyTest($actionList[2])) && p('') && e('confirmBug'); // action为bugconfirmed
|
||||
r($score->fixKeyTest($actionList[3])) && p('') && e('fixed'); // action为fixed, 不存在于strings中
|
||||
@@ -0,0 +1,24 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/score.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 scoreModel->getListByAccount();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
global $tester;
|
||||
$tester->app->loadClass('pager', $static = true);
|
||||
|
||||
$score = new scoreTest();
|
||||
$accountList = array('admin', 'dev10', 'top10', 'adminn');
|
||||
$pager = new pager(0, 15, 1);
|
||||
|
||||
r($score->getListByAccountTest($accountList[0], $pager)) && p('0:account') && e('admin'); // 查看account为admin,每页展示15条,第一页的第一条数据
|
||||
r($score->getListByAccountTest($accountList[1], $pager, true)) && p('') && e('15'); // 查看account为dev10, 每页展示15条,第一页的数据总量
|
||||
r($score->getListByAccountTest($accountList[2], null)) && p('0:account') && e('top10'); // 查看account为top10, 不传pager(默认分页)的第一条数据
|
||||
r($score->getListByAccountTest($accountList[3], null)) && p('0:account') && e('0'); // 查看account为adminn(不存在的用户)的数据
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/score.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 scoreModel->reset();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$score = new scoreTest();
|
||||
|
||||
r($score->resetTest()) && p('status,number') && e('finish,0'); // 重置积分成功
|
||||
@@ -130,8 +130,12 @@ switch($argv[1])
|
||||
case 'report':
|
||||
ztfRun('model/report');
|
||||
break;
|
||||
case 'score':
|
||||
ztfRun('model/score');
|
||||
break;
|
||||
case 'sso':
|
||||
ztfRun('model/sso');
|
||||
break;
|
||||
case 'setting':
|
||||
ztfRun('model/setting');
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user