From c283ab718aba6ccfbb3b875ce4edf6a980acbf1b Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 5 Nov 2025 18:51:26 +0800 Subject: [PATCH] + [misc] Add unit tests for commonModel::printBack() method MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- module/common/test/lib/model.class.php | 67 ++++++++++++++++++++++++++ module/common/test/model/printback.php | 29 +++++++++++ 2 files changed, 96 insertions(+) create mode 100755 module/common/test/model/printback.php diff --git a/module/common/test/lib/model.class.php b/module/common/test/lib/model.class.php index 23aa5a40fd..8c140c41dc 100644 --- a/module/common/test/lib/model.class.php +++ b/module/common/test/lib/model.class.php @@ -41,4 +41,71 @@ class commonModelTest extends baseTest if(dao::isError()) return dao::getError(); return $result; } + + /** + * Test printBack method metadata. + * + * @param string $checkType + * @access public + * @return mixed + */ + public function printBackMetaTest(string $checkType) + { + if($checkType == 'exists') + { + return method_exists('commonModel', 'printBack') ? '1' : '0'; + } + + $reflection = new ReflectionMethod('commonModel', 'printBack'); + + if($checkType == 'static') + { + return $reflection->isStatic() ? '1' : '0'; + } + + if($checkType == 'public') + { + return $reflection->isPublic() ? '1' : '0'; + } + + if($checkType == 'paramCount') + { + return (string)$reflection->getNumberOfParameters(); + } + + return '0'; + } + + /** + * Test printBack method. + * + * @param string $backLink + * @param string $class + * @param string $misc + * @param bool $onlyBody + * @access public + * @return mixed + */ + public function printBackTest(string $backLink, string $class = '', string $misc = '', bool $onlyBody = false) + { + if($onlyBody) + { + $_GET['onlybody'] = 'yes'; + } + else + { + unset($_GET['onlybody']); + } + + ob_start(); + $result = commonModel::printBack($backLink, $class, $misc); + $output = ob_get_clean(); + + if(dao::isError()) return dao::getError(); + + // Return different data based on what we're testing + if($onlyBody) return $result; + if(!empty($output)) return $output; + return $result; + } } diff --git a/module/common/test/model/printback.php b/module/common/test/model/printback.php new file mode 100755 index 0000000000..dfb6c8eea0 --- /dev/null +++ b/module/common/test/model/printback.php @@ -0,0 +1,29 @@ +#!/usr/bin/env php +printBackMetaTest('exists')) && p() && e('1'); // 测试步骤1:检查printBack方法是否存在 +r($commonTest->printBackMetaTest('static')) && p() && e('1'); // 测试步骤2:检查printBack方法是否为静态方法 +r($commonTest->printBackMetaTest('public')) && p() && e('1'); // 测试步骤3:检查printBack方法是否为公共方法 +r($commonTest->printBackMetaTest('paramCount')) && p() && e('3'); // 测试步骤4:检查printBack方法参数数量 +r($commonTest->printBackTest('index.php', '', '', true)) && p() && e('0'); // 测试步骤5:在onlybody模式下调用printBack返回false \ No newline at end of file