* Refactor tutorialModel::checkNovice, and modify its unit test.
This commit is contained in:
@@ -12,6 +12,25 @@ declare(strict_types=1);
|
||||
*/
|
||||
class tutorialModel extends model
|
||||
{
|
||||
/**
|
||||
* 检查新手模式配置。
|
||||
* Check novice mode config.
|
||||
*
|
||||
* @access public
|
||||
* @return bool
|
||||
*/
|
||||
public function checkNovice(): bool
|
||||
{
|
||||
$account = $this->app->user->account;
|
||||
if($account == 'guest') return false;
|
||||
if(!empty($this->app->user->modifyPassword)) return false;
|
||||
|
||||
$count = $this->dao->select('count(*) AS count')->from(TABLE_ACTION)->where('actor')->eq($account)->fetch('count');
|
||||
if($count < 10) return true;
|
||||
|
||||
$this->loadModel('setting')->setItem($account . '.common.global.novice', 0);
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 获取新手模式产品键值对。
|
||||
* Get tutorial product pairs.
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/tutorial.class.php';
|
||||
|
||||
zdTable('action')->gen(40);
|
||||
zdTable('user')->gen(5);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
title=测试 tutorialModel->checkNovice();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
检查当account是admin的时候的返回值。 >> 0
|
||||
检查当->app->user->modifyPassword是不为空的时候的返回值。 >> 0
|
||||
检查当account是guest的时候的返回值。 >> 0
|
||||
|
||||
*/
|
||||
|
||||
$tutorial = new tutorialTest();
|
||||
|
||||
$modifyPassword = array(0, 1);
|
||||
|
||||
r($tutorial->checkNoviceTest($modifyPassword[0])) && p() && e('0'); //检查当account是 guest 的时候的返回值 modifyPassword 0。
|
||||
r($tutorial->checkNoviceTest($modifyPassword[1])) && p() && e('0'); //检查当account是 guest 的时候的返回值 modifyPassword 1。
|
||||
|
||||
su('admin');
|
||||
r($tutorial->checkNoviceTest($modifyPassword[0])) && p() && e('0'); //检查当account是 admin 的时候的返回值 modifyPassword 0 动态数量大于 10。
|
||||
r($tutorial->checkNoviceTest($modifyPassword[1])) && p() && e('0'); //检查当account是 admin 的时候的返回值 modifyPassword 1 动态数量大于 10。
|
||||
|
||||
su('user1');
|
||||
r($tutorial->checkNoviceTest($modifyPassword[0])) && p() && e('1'); //检查当account是 user1 的时候的返回值 modifyPassword 0 动态数量小于等于 10。
|
||||
r($tutorial->checkNoviceTest($modifyPassword[1])) && p() && e('0'); //检查当account是 user1 的时候的返回值 modifyPassword 1 动态数量小于等于 10。
|
||||
@@ -8,6 +8,26 @@ class tutorialTest
|
||||
$this->objectModel = $tester->loadModel('tutorial');
|
||||
}
|
||||
|
||||
/**
|
||||
* 测试检查新手模式配置。
|
||||
* Test check novice mode config.
|
||||
*
|
||||
* @param int $modifyPassword
|
||||
* @access public
|
||||
* @return int|array
|
||||
*/
|
||||
public function checkNoviceTest(int $modifyPassword): int|array
|
||||
{
|
||||
global $tester;
|
||||
if($tester->app->user->account != 'guest') $tester->app->user->modifyPassword = $modifyPassword;
|
||||
|
||||
$return = $this->objectModel->checkNovice();
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $return ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tutorial product pairs.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user