* Add test unit for account browse page.
This commit is contained in:
@@ -14,16 +14,16 @@ class account extends control
|
||||
/**
|
||||
* Browse accouts page.
|
||||
*
|
||||
* @param string $browseType
|
||||
* @param string $param
|
||||
* @param string $orderBy
|
||||
* @param string $browseType
|
||||
* @param string $param
|
||||
* @param string $orderBy
|
||||
* @param int $recTotal
|
||||
* @param int $recPerPage
|
||||
* @param int $pageID
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function browse($browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
|
||||
public function browse(string $browseType = 'all', string $param = '', string $orderBy = 'id_desc', int $recTotal = 0, int $recPerPage = 20, int $pageID = 1)
|
||||
{
|
||||
$this->app->loadLang('serverroom');
|
||||
$browseType = strtolower($browseType);
|
||||
@@ -47,7 +47,6 @@ class account extends control
|
||||
$this->view->param = $param;
|
||||
$this->view->orderBy = $orderBy;
|
||||
$this->view->browseType = $browseType;
|
||||
$this->view->position[] = $this->lang->account->common;
|
||||
|
||||
$this->display();
|
||||
}
|
||||
|
||||
@@ -45,25 +45,22 @@ class accountModel extends model
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getList($browseType = 'all', $param = 0, $orderBy = 't1.id_desc', $pager = null)
|
||||
public function getList(string $browseType = 'all', string $param = '', string $orderBy = 'id_desc', object|null $pager = null)
|
||||
{
|
||||
$query = '';
|
||||
$query = '';
|
||||
if($browseType == 'bysearch')
|
||||
{
|
||||
/* Concatenate the conditions for the query. */
|
||||
if(!$this->session->accountQuery) $this->session->set('accountQuery', ' 1 = 1');
|
||||
if($param)
|
||||
{
|
||||
$query = $this->loadModel('search')->getZinQuery($param);
|
||||
$query = $this->loadModel('search')->getQuery((int)$param);
|
||||
if($query)
|
||||
{
|
||||
$this->session->set('accountQuery', $query->sql);
|
||||
$this->session->set('accountForm', $query->form);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!$this->session->accountQuery) $this->session->set('accountQuery', ' 1 = 1');
|
||||
}
|
||||
$query = $this->session->accountQuery;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
zdTable('user')->gen(5);
|
||||
zdTable('account')->gen(10);
|
||||
zdTable('userquery')->gen(1);
|
||||
|
||||
/**
|
||||
|
||||
title=accountModel->getList();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
*/
|
||||
|
||||
global $tester;
|
||||
$accountModel = $tester->loadModel('account');
|
||||
r(count($accountModel->getList())) && p() && e('10'); // 获取所有数据。
|
||||
r(count($accountModel->getList('bysearch', '0'))) && p() && e('10'); // 根据搜索条件搜索。
|
||||
r(count($accountModel->getList('bysearch', '1'))) && p() && e('0'); // 根据第一个保存条件搜索。
|
||||
|
||||
$accountModel->app->loadClass('pager', $static = true);
|
||||
$pager = new pager(0, 5, 1);
|
||||
r(count($accountModel->getList('all', '', 'id_desc', $pager))) && p() && e('5'); // 分页,每页5条,获取第一页。
|
||||
@@ -378,16 +378,16 @@ class searchModel extends model
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function getQuery($queryID)
|
||||
public function getQuery(int $queryID): object
|
||||
{
|
||||
$query = $this->dao->findByID((int)$queryID)->from(TABLE_USERQUERY)->fetch();
|
||||
$query = $this->dao->findByID($queryID)->from(TABLE_USERQUERY)->fetch();
|
||||
if(!$query) return false;
|
||||
|
||||
/* Decode html encode. */
|
||||
$query->form = htmlspecialchars_decode($query->form, ENT_QUOTES);
|
||||
$query->sql = htmlspecialchars_decode($query->sql, ENT_QUOTES);
|
||||
|
||||
$hasDynamic = strpos($query->form, '$') !== false;
|
||||
$hasDynamic = str_contains($query->form, '$');
|
||||
$query->form = unserialize($query->form);
|
||||
if($hasDynamic)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user