* [misc] fix unittest error of the storyTao::getModules4ExecutionStories method.

This commit is contained in:
liugang
2025-06-19 08:41:27 +08:00
parent ff6f16128a
commit 8bb238ae40
2 changed files with 12 additions and 4 deletions
+8 -1
View File
@@ -484,10 +484,17 @@ class storyTao extends storyModel
protected function getModules4ExecutionStories(string $type, string $param): array
{
$moduleID = (int)($type == 'bymodule' && $param !== '' ? $param : $this->cookie->storyModuleParam);
if(!$moduleID || strpos('allstory,unclosed,bymodule', $type) === false) return [];
if(empty($moduleID))
{
if(!empty($type) && strpos('allstory,unclosed,bymodule', $type) !== false) return $this->dao->select('id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('type')->eq('story')->fetchPairs();
return [];
}
/* 从缓存中获取模块路径然后在 LIKE 查询中使用左匹配以利用索引提高性能。Find the path of the module from cache and use left match in like query to improve performance. */
$path = $this->mao->select('path')->from(TABLE_MODULE)->where('id')->eq($moduleID)->fetch('path');
if(empty($path)) return [];
return $this->dao->select('id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('path')->like("$path%")->fetchPairs();
}
@@ -4,12 +4,13 @@
/**
title=测试 storyModel->getModules4ExecutionStories();
timeout=0
cid=0
- 不传入数据。 @0
- 传入 type=byproduct,不传入 param 参数。 @0
- 传入 type=byproduct 和 param 参数。 @0
- 传入 type=bymodule,不传入 param 参数。 @0
- 传入 type=bymodule,不传入 param 参数。属性2 @2
- 传入 type=bymodule 和 param 参数。属性1 @1
- 设置COOKIE,传入 type=byproduct,不传入 param 参数。属性2 @2
- 设置COOKIE,传入 type=byproduct 和 param 参数。属性2 @2
@@ -28,11 +29,11 @@ $storyModel = $tester->loadModel('story');
r($storyModel->getModules4ExecutionStories('', '')) && p() && e('0'); //不传入数据。
r($storyModel->getModules4ExecutionStories('byproduct', '')) && p() && e('0'); //传入 type=byproduct,不传入 param 参数。
r($storyModel->getModules4ExecutionStories('byproduct', '1')) && p() && e('0'); //传入 type=byproduct 和 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '')) && p() && e('0'); //传入 type=bymodule,不传入 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '')) && p(2) && e('2'); //传入 type=bymodule,不传入 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '1')) && p(1) && e('1'); //传入 type=bymodule 和 param 参数。
$_COOKIE['storyModuleParam'] = 2;
r($storyModel->getModules4ExecutionStories('byproduct', '')) && p(2) && e('2'); //设置COOKIE,传入 type=byproduct,不传入 param 参数。
r($storyModel->getModules4ExecutionStories('byproduct', '1')) && p(2) && e('2'); //设置COOKIE,传入 type=byproduct 和 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '')) && p(2) && e('2'); //设置COOKIE,传入 type,不传入 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '1')) && p(1) && e('1'); //设置COOKIE,传入 type=bymodule 和 param 参数。
r($storyModel->getModules4ExecutionStories('bymodule', '1')) && p(1) && e('1'); //设置COOKIE,传入 type=bymodule 和 param 参数。