diff --git a/module/common/test/lib/common.unittest.class.php b/module/common/test/lib/common.unittest.class.php index 22539b1a54..7f15abf8e5 100644 --- a/module/common/test/lib/common.unittest.class.php +++ b/module/common/test/lib/common.unittest.class.php @@ -551,4 +551,46 @@ class commonTest $_SERVER = $originalServer; } } + + /** + * Test checkNotCN method. + * + * @param string $lang + * @access public + * @return mixed + */ + public function checkNotCNTest($lang = '') + { + global $app; + + // 备份原始的app对象 + $originalApp = $app; + + try { + // 创建一个模拟的app对象 + $mockApp = new class($lang) { + private $lang; + + public function __construct($lang = 'zh-cn') + { + $this->lang = $lang ?: 'zh-cn'; + } + + public function getClientLang() + { + return $this->lang; + } + }; + + // 替换全局的app对象 + $app = $mockApp; + + // 调用被测试的方法 + $result = commonModel::checkNotCN(); + return $result ? '1' : '0'; + } finally { + // 恢复原始的app对象 + $app = $originalApp; + } + } } diff --git a/module/common/test/model/checknotcn.php b/module/common/test/model/checknotcn.php new file mode 100755 index 0000000000..e0d3f3a227 --- /dev/null +++ b/module/common/test/model/checknotcn.php @@ -0,0 +1,33 @@ +#!/usr/bin/env php +checkNotCNTest('zh-cn')) && p() && e('0'); // 步骤1:中文简体 +r($commonTest->checkNotCNTest('zh-tw')) && p() && e('0'); // 步骤2:中文繁体 +r($commonTest->checkNotCNTest('en')) && p() && e('1'); // 步骤3:英语 +r($commonTest->checkNotCNTest('de')) && p() && e('1'); // 步骤4:德语 +r($commonTest->checkNotCNTest('fr')) && p() && e('1'); // 步骤5:法语 +r($commonTest->checkNotCNTest('')) && p() && e('0'); // 步骤6:空语言(默认为zh-cn) +r($commonTest->checkNotCNTest('test')) && p() && e('1'); // 步骤7:未知语言 \ No newline at end of file