* Add unit test of search module.
This commit is contained in:
+95
-54
@@ -12,7 +12,7 @@ class searchTest
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryTest($queryID)
|
||||
{
|
||||
@@ -37,7 +37,7 @@ class searchTest
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getByIDTest($queryID)
|
||||
{
|
||||
@@ -53,7 +53,7 @@ class searchTest
|
||||
*
|
||||
* @param int $queryID
|
||||
* @access public
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function deleteQueryTest($queryID)
|
||||
{
|
||||
@@ -69,9 +69,9 @@ class searchTest
|
||||
/**
|
||||
* Test get query pairs.
|
||||
*
|
||||
* @param int $module
|
||||
* @param string $module
|
||||
* @access public
|
||||
* @return void
|
||||
* @return array
|
||||
*/
|
||||
public function getQueryPairsTest($module)
|
||||
{
|
||||
@@ -85,10 +85,10 @@ class searchTest
|
||||
/**
|
||||
* Test get list.
|
||||
*
|
||||
* @param int $keywords
|
||||
* @param int $type
|
||||
* @param string $keywords
|
||||
* @param sreing $type
|
||||
* @access public
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function getListTest($keywords, $type)
|
||||
{
|
||||
@@ -119,10 +119,10 @@ class searchTest
|
||||
/**
|
||||
* Test save index.
|
||||
*
|
||||
* @param int $objectType
|
||||
* @param string $objectType
|
||||
* @param int $objectID
|
||||
* @access public
|
||||
* @return void
|
||||
* @return bool
|
||||
*/
|
||||
public function saveIndexTest($objectType, $objectID)
|
||||
{
|
||||
@@ -150,7 +150,7 @@ class searchTest
|
||||
*
|
||||
* @param string $word
|
||||
* @access public
|
||||
* @return void
|
||||
* @return int
|
||||
*/
|
||||
public function saveDictTest($word)
|
||||
{
|
||||
@@ -171,69 +171,110 @@ class searchTest
|
||||
/**
|
||||
* Test decode.
|
||||
*
|
||||
* @param int $string
|
||||
* @param int $key
|
||||
* @access public
|
||||
* @return void
|
||||
* @return string
|
||||
*/
|
||||
public function decodeTest($string)
|
||||
public function decodeTest($key)
|
||||
{
|
||||
$objects = $this->objectModel->decode($string);
|
||||
global $tester;
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
$result = array();
|
||||
while(!isset($result['finished']))
|
||||
{
|
||||
if(empty($result))
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex($result['type'], $result['lastID']);
|
||||
}
|
||||
}
|
||||
|
||||
$objects = $this->objectModel->decode($key);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function getSummaryTest($content, $words)
|
||||
/**
|
||||
* Test get summary.
|
||||
*
|
||||
* @param int $indexID
|
||||
* @param string $words
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public function getSummaryTest($indexID, $words)
|
||||
{
|
||||
$objects = $this->objectModel->getSummary($content, $words);
|
||||
global $tester;
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
$result = array();
|
||||
while(!isset($result['finished']))
|
||||
{
|
||||
if(empty($result))
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex($result['type'], $result['lastID']);
|
||||
}
|
||||
}
|
||||
|
||||
$searchIndex = $tester->dao->select('*')->from(TABLE_SEARCHINDEX)->where('id')->eq($indexID)->fetch();
|
||||
|
||||
$objects = $this->objectModel->getSummary($searchIndex->content, $words);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function checkPrivTest($results)
|
||||
/**
|
||||
* Test mark keywords.
|
||||
*
|
||||
* @param int $indexID
|
||||
* @param string $keywords
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function markKeywordsTest($indexID, $keywords)
|
||||
{
|
||||
$objects = $this->objectModel->checkPriv($results);
|
||||
global $tester;
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
$result = array();
|
||||
while(!isset($result['finished']))
|
||||
{
|
||||
if(empty($result))
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex();
|
||||
}
|
||||
else
|
||||
{
|
||||
$result = $this->objectModel->buildAllIndex($result['type'], $result['lastID']);
|
||||
}
|
||||
}
|
||||
|
||||
$searchIndex = $tester->dao->select('*')->from(TABLE_SEARCHINDEX)->where('id')->eq($indexID)->fetch();
|
||||
|
||||
$objects = $this->objectModel->markKeywords($searchIndex->content, $keywords);
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function markKeywordsTest($content, $keywords)
|
||||
{
|
||||
$objects = $this->objectModel->markKeywords($content, $keywords);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function buildAllIndexTest($type = '', $lastID = 0)
|
||||
{
|
||||
$objects = $this->objectModel->buildAllIndex($type = '', $lastID = 0);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function deleteIndexTest($objectType, $objectID)
|
||||
{
|
||||
$objects = $this->objectModel->deleteIndex($objectType, $objectID);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
public function appendFilesTest($object)
|
||||
{
|
||||
$objects = $this->objectModel->appendFiles($object);
|
||||
|
||||
if(dao::isError()) return dao::getError();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHINDEX)->exec();
|
||||
$tester->dao->delete()->from(TABLE_SEARCHDICT)->exec();
|
||||
|
||||
return $objects;
|
||||
}
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/search.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchModel->appendFiles();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->appendFilesTest()) && p() && e();
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/search.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchModel->buildAllIndex();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->buildAllIndexTest()) && p() && e();
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/search.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchModel->checkPriv();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->checkPrivTest()) && p() && e();
|
||||
@@ -14,4 +14,4 @@ pid=1
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->decodeTest()) && p() && e();
|
||||
r($search->decodeTest(20135)) && p() && e('产'); //测试将搜索字转化为正确的汉字
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(dirname(dirname(__FILE__))) . '/lib/init.php';
|
||||
include dirname(dirname(dirname(__FILE__))) . '/class/search.class.php';
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchModel->deleteIndex();
|
||||
cid=1
|
||||
pid=1
|
||||
|
||||
*/
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->deleteIndexTest()) && p() && e();
|
||||
@@ -39,7 +39,7 @@ $searchWords = array('任务','bug','用例','文档','待办','版本','用例
|
||||
r($search->getListTest($searchWords[0], $searchType[0])) && p() && e('1246'); //测试在全部类型中搜索带有任务字体的条数
|
||||
r($search->getListTest($searchWords[0], $searchType[1])) && p() && e('910'); //测试在任务类型中搜索带有任务字体的条数
|
||||
r($search->getListTest($searchWords[1], $searchType[2])) && p() && e('239'); //测试在bug类型中搜索带有bug字体的条数
|
||||
r($search->getListTest($searchWords[2], $searchType[3])) && p() && e('208'); //测试在用例类型中搜索带有用例字体的条数
|
||||
r($search->getListTest($searchWords[2], $searchType[3])) && p() && e('97'); //测试在用例类型中搜索带有用例字体的条数
|
||||
r($search->getListTest($searchWords[3], $searchType[4])) && p() && e('900'); //测试在文档类型中搜索带有文档字体的条数
|
||||
r($search->getListTest($searchWords[4], $searchType[5])) && p() && e('1680'); //测试在待办类型中搜索带有待办字体的条数
|
||||
r($search->getListTest($searchWords[5], $searchType[6])) && p() && e('20'); //测试在版本类型中搜索带有版本字体的条数
|
||||
|
||||
@@ -14,4 +14,6 @@ pid=1
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->getSummaryTest()) && p() && e();
|
||||
r($search->getSummaryTest(1, 0)) && p() && e('【步骤】【结果】【期望】'); //测试搜索的内容中不带关键字的结果展示
|
||||
r($search->getSummaryTest(1, 39588)) && p() && e("【步<span class='text-danger'>骤</span> 】【结果】【期望】"); //测试搜索的内容中带关键字的结果展示
|
||||
|
||||
|
||||
@@ -14,4 +14,4 @@ pid=1
|
||||
|
||||
$search = new searchTest();
|
||||
|
||||
r($search->markKeywordsTest()) && p() && e();
|
||||
r($search->markKeywordsTest(1, 39588)) && p() && e("12304 27493 <span class='text-danger'>骤</span> 12305 12304 32467 26524 12305 12304 26399 26395 12305"); //测试查找带骤字的bug
|
||||
|
||||
Reference in New Issue
Block a user