+ [misc] Add unit tests for searchTao::processRecord() method
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1120,4 +1120,46 @@ class searchTest
|
||||
|
||||
return dao::isError() ? -1 : count($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test markKeywords method directly.
|
||||
*
|
||||
* @param string $content
|
||||
* @param string $keywords
|
||||
* @access public
|
||||
* @return string
|
||||
*/
|
||||
public function markKeywordsDirectTest(string $content, string $keywords): string
|
||||
{
|
||||
// 使用反射访问私有方法
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('markKeywords');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->objectTao, array($content, $keywords));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Test processRecord method.
|
||||
*
|
||||
* @param object $record
|
||||
* @param array $objectList
|
||||
* @access public
|
||||
* @return object
|
||||
*/
|
||||
public function processRecordTest(object $record, array $objectList): object
|
||||
{
|
||||
// 使用反射访问私有方法
|
||||
$reflection = new ReflectionClass($this->objectTao);
|
||||
$method = $reflection->getMethod('processRecord');
|
||||
$method->setAccessible(true);
|
||||
|
||||
$result = $method->invokeArgs($this->objectTao, array($record, $objectList));
|
||||
if(dao::isError()) return dao::getError();
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/search.unittest.class.php';
|
||||
|
||||
su('admin');
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchTao::markKeywords();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 执行searchTest模块的markKeywordsDirectTest方法,参数是'This is a test content', 'test' @This is a <span class='text-danger'>test </span> content
|
||||
- 执行searchTest模块的markKeywordsDirectTest方法,参数是'This contains key1 and key2 words', 'key1 key2' @This contains <span class='text-danger'>key1 </span> and <span class='text-danger'>key2 </span> words
|
||||
- 执行searchTest模块的markKeywordsDirectTest方法,参数是'这是一个测试内容', '测试' @这是一个<span class='text-danger'>测试 </span> 内容
|
||||
- 执行searchTest模块的markKeywordsDirectTest方法,参数是'Product version 12345 released', '12345' @Product version <span class='text-danger'>12345 </span> released
|
||||
- 执行searchTest模块的markKeywordsDirectTest方法,参数是'No keywords here', '' @No keywords here
|
||||
|
||||
*/
|
||||
|
||||
$searchTest = new searchTest();
|
||||
|
||||
r($searchTest->markKeywordsDirectTest('This is a test content', 'test')) && p() && e("This is a <span class='text-danger'>test </span> content ");
|
||||
r($searchTest->markKeywordsDirectTest('This contains key1 and key2 words', 'key1 key2')) && p() && e("This contains <span class='text-danger'>key1 </span> and <span class='text-danger'>key2 </span> words ");
|
||||
r($searchTest->markKeywordsDirectTest('这是一个测试内容', '测试')) && p() && e("这是一个<span class='text-danger'>测试 </span> 内容 ");
|
||||
r($searchTest->markKeywordsDirectTest('Product version 12345 released', '12345')) && p() && e("Product version <span class='text-danger'>12345 </span> released ");
|
||||
r($searchTest->markKeywordsDirectTest('No keywords here', '')) && p() && e('No keywords here');
|
||||
Executable
+57
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/**
|
||||
|
||||
title=测试 searchTao::processRecord();
|
||||
timeout=0
|
||||
cid=0
|
||||
|
||||
- 步骤1:测试任务记录URL包含task模块 @1
|
||||
- 步骤2:测试kanban项目URL包含index方法 @1
|
||||
- 步骤3:测试执行记录的额外类型 @sprint
|
||||
- 步骤4:测试需求记录URL包含storyView方法 @1
|
||||
- 步骤5:测试文档记录URL包含doc模块 @1
|
||||
|
||||
*/
|
||||
|
||||
// 1. 导入依赖(路径固定,不可修改)
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/search.unittest.class.php';
|
||||
|
||||
// 2. zendata数据准备(根据需要配置)
|
||||
$taskTable = zenData('task');
|
||||
$taskTable->id->range('1-10');
|
||||
$taskTable->project->range('1-3');
|
||||
$taskTable->name->range('任务{1-10}');
|
||||
$taskTable->status->range('wait{3},doing{4},done{3}');
|
||||
$taskTable->gen(10);
|
||||
|
||||
$projectTable = zenData('project');
|
||||
$projectTable->id->range('1-10');
|
||||
$projectTable->name->range('项目{1-10}');
|
||||
$projectTable->model->range('waterfall{3},scrum{3},kanban{2}');
|
||||
$projectTable->multiple->range('1{8},0{2}');
|
||||
$projectTable->gen(10);
|
||||
|
||||
// 3. 用户登录(选择合适角色)
|
||||
su('admin');
|
||||
|
||||
// 4. 创建测试实例(变量名与模块名一致)
|
||||
$searchTest = new searchTest();
|
||||
|
||||
// 5. 强制要求:必须包含至少5个测试步骤
|
||||
$taskResult = $searchTest->processRecordTest((object)array('objectType' => 'task', 'objectID' => 1), array());
|
||||
r(strpos($taskResult->url, 'm=task') !== false) && p() && e('1'); // 步骤1:测试任务记录URL包含task模块
|
||||
|
||||
$projectResult = $searchTest->processRecordTest((object)array('objectType' => 'project', 'objectID' => 3), array('project' => array(3 => (object)array('model' => 'kanban'))));
|
||||
r(strpos($projectResult->url, 'f=index') !== false) && p() && e('1'); // 步骤2:测试kanban项目URL包含index方法
|
||||
|
||||
$executionResult = $searchTest->processRecordTest((object)array('objectType' => 'execution', 'objectID' => 2), array('execution' => array(2 => (object)array('type' => 'sprint', 'project' => 1))));
|
||||
r($executionResult->extraType) && p() && e('sprint'); // 步骤3:测试执行记录的额外类型
|
||||
|
||||
$storyResult = $searchTest->processRecordTest((object)array('objectType' => 'story', 'objectID' => 1), array('story' => array(1 => (object)array('type' => 'story', 'lib' => 0))));
|
||||
r(strpos($storyResult->url, 'f=storyView') !== false) && p() && e('1'); // 步骤4:测试需求记录URL包含storyView方法
|
||||
|
||||
$docResult = $searchTest->processRecordTest((object)array('objectType' => 'doc', 'objectID' => 7), array('doc' => array(7 => (object)array('assetLib' => 0))));
|
||||
r(strpos($docResult->url, 'm=doc') !== false) && p() && e('1'); // 步骤5:测试文档记录URL包含doc模块
|
||||
Reference in New Issue
Block a user