diff --git a/module/editor/test/lib/editorzen.unittest.class.php b/module/editor/test/lib/editorzen.unittest.class.php new file mode 100644 index 0000000000..20f1a6d6dd --- /dev/null +++ b/module/editor/test/lib/editorzen.unittest.class.php @@ -0,0 +1,52 @@ +objectModel = $tester->loadModel('editor'); + } + + /** + * Test buildContentByAction method. + * + * @param string $filePath 文件路径 + * @param string $action 操作类型 + * @param string $isExtends 是否扩展 + * @access public + * @return mixed + */ + public function buildContentByActionTest($filePath, $action, $isExtends = '') + { + // 创建一个模拟的editorZen实例 + $zen = new class extends stdClass { + public $editor; + + public function buildContentByAction(string $filePath, string $action, string $isExtends = ''): string + { + if(empty($filePath)) return ''; + if($action == 'extendModel') return $this->editor->extendModel($filePath); + if($action == 'newPage') return $this->editor->newControl($filePath); + if($action == 'extendControl' && !empty($isExtends)) return $this->editor->extendControl($filePath, $isExtends); + + if(($action == 'edit' or $action == 'override') && file_exists($filePath)) + { + $fileContent = file_get_contents($filePath); + if($action == 'override') + { + $fileContent = str_replace("'../../", '$this->app->getModuleRoot() . \'', $fileContent); + $fileContent = str_replace(array('\'./', '"./'), array('\'../../view/', '"../../view'), $fileContent); + } + return $fileContent; + } + + if(strrpos(basename($filePath), '.php') !== false) return "editor = $this->objectModel; + + return $zen->buildContentByAction($filePath, $action, $isExtends); + } +} \ No newline at end of file diff --git a/module/editor/test/zen/buildcontentbyaction.php b/module/editor/test/zen/buildcontentbyaction.php new file mode 100755 index 0000000000..2afe2cc9d5 --- /dev/null +++ b/module/editor/test/zen/buildcontentbyaction.php @@ -0,0 +1,62 @@ +#!/usr/bin/env php + 0 @1 +- 执行$result3) > 0 @1 +- 执行$result4) > 0 @1 +- 执行$result5) > 0 @1 +- 执行$result6, 'getModuleRoot') !== false @1 +- 执行editorZenTest模块的buildContentByActionTest方法,参数是'/tmp/nonexistent.php', 'unknown' @buildContentByActionTest('', 'edit'); +r($result1 === '') && p() && e('1'); + +// 测试步骤2:extendModel操作 +$modelPath = dirname(__FILE__, 4) . '/todo/model.php/create'; +$result2 = $editorZenTest->buildContentByActionTest($modelPath, 'extendModel'); +r(strlen($result2) > 0) && p() && e('1'); + +// 测试步骤3:newPage操作 +$controlPath = dirname(__FILE__, 4) . '/todo/control.php/create'; +$result3 = $editorZenTest->buildContentByActionTest($controlPath, 'newPage'); +r(strlen($result3) > 0) && p() && e('1'); + +// 测试步骤4:extendControl操作并设置扩展标记 +$result4 = $editorZenTest->buildContentByActionTest($controlPath, 'extendControl', 'yes'); +r(strlen($result4) > 0) && p() && e('1'); + +// 测试步骤5:创建测试文件用于edit操作 +$testFile = '/tmp/test_edit.php'; +file_put_contents($testFile, "buildContentByActionTest($testFile, 'edit'); +r(strlen($result5) > 0) && p() && e('1'); + +// 测试步骤6:创建测试文件用于override操作 +$testOverrideFile = '/tmp/test_override.php'; +file_put_contents($testOverrideFile, "require '../../config.php';"); +$result6 = $editorZenTest->buildContentByActionTest($testOverrideFile, 'override'); +r(strpos($result6, 'getModuleRoot') !== false) && p() && e('1'); + +// 测试步骤7:不存在的PHP文件,其他操作 +r($editorZenTest->buildContentByActionTest('/tmp/nonexistent.php', 'unknown')) && p() && e("