* Refactor reportModel::getUserYearLogins, and modify its unit test.

This commit is contained in:
liumengyi
2023-11-30 14:18:43 +08:00
parent 73b5ea2e4c
commit cc8a5eb282
4 changed files with 31 additions and 21 deletions
+3 -2
View File
@@ -227,14 +227,15 @@ class reportModel extends model
}
/**
* 获取用户今年的登录次数。
* Get user login count in this year.
*
* @param array $accounts
* @param int $year
* @param string $year
* @access public
* @return int
*/
public function getUserYearLogins($accounts, $year)
public function getUserYearLogins(array $accounts, string $year): int
{
return $this->dao->select('count(*) as count')->from(TABLE_ACTION)->where('actor')->in($accounts)->andWhere('LEFT(date, 4)')->eq($year)->andWhere('action')->eq('login')->fetch('count');
}
+10 -12
View File
@@ -2,6 +2,10 @@
<?php
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/report.class.php';
zdTable('action')->config('action')->gen('100');
zdTable('user')->gen(1);
su('admin');
/**
@@ -10,19 +14,13 @@ title=测试 reportModel->getUserYearLogins();
cid=1
pid=1
测试获取本年度 admin 的登录次数 >> 0
测试获取本年度 dev17 的登录次数 >> 0
测试获取本年度 test18 的登录次数 >> 0
测试获取本年度 admin dev17 的登录次数 >> 0
测试获取本年度 admin test18 的登录次数 >> 0
*/
$account = array('admin', 'dev17', 'test18', 'admin,dev17', 'admin,test18');
$account = array(array('admin'), array('dev17'), array('test18'), array('admin', 'dev17'), array('admin', 'test18'));
$report = new reportTest();
r($report->getUserYearLoginsTest($account[0])) && p() && e('0');// 测试获取本年度 admin 的登录次数
r($report->getUserYearLoginsTest($account[1])) && p() && e('0');// 测试获取本年度 dev17 的登录次数
r($report->getUserYearLoginsTest($account[2])) && p() && e('0');// 测试获取本年度 test18 的登录次数
r($report->getUserYearLoginsTest($account[3])) && p() && e('0');// 测试获取本年度 admin dev17 的登录次数
r($report->getUserYearLoginsTest($account[4])) && p() && e('0');// 测试获取本年度 admin test18 的登录次数
r($report->getUserYearLoginsTest($account[0])) && p() && e('9'); // 测试获取本年度 admin 的登录次数
r($report->getUserYearLoginsTest($account[1])) && p() && e('8'); // 测试获取本年度 dev17 的登录次数
r($report->getUserYearLoginsTest($account[2])) && p() && e('8'); // 测试获取本年度 test18 的登录次数
r($report->getUserYearLoginsTest($account[3])) && p() && e('17'); // 测试获取本年度 admin dev17 的登录次数
r($report->getUserYearLoginsTest($account[4])) && p() && e('17'); // 测试获取本年度 admin test18 的登录次数
+6 -7
View File
@@ -300,21 +300,20 @@ class reportTest
}
/**
* 测试获取当前年的用户登录次数。
* Test get user login count in this year.
*
* @param string $accounts
* @param string $accounts
* @access public
* @return int
* @return int|array
*/
public function getUserYearLoginsTest($accounts)
public function getUserYearLoginsTest(array $accounts): int|array
{
$year = date('Y');
$objects = $this->objectModel->getUserYearLogins($accounts, $year);
$count = $this->objectModel->getUserYearLogins($accounts, date('Y'));
if(dao::isError()) return dao::getError();
return $objects;
return $count;
}
/**
+12
View File
@@ -0,0 +1,12 @@
title: action.
desc: action data.
author: Mengyi Liu
version: "1.0"
fields:
- field: action
range: login,productplan,release,project
- field: date
note: "日期"
range: "(-1m)-(0m):1s"
type: timestamp
format: "YYYY-MM-DD hh:mm:ss"