From 43909e4435060d1d180fe5075fd26fd479afb16e Mon Sep 17 00:00:00 2001 From: liugang Date: Sat, 13 Sep 2025 02:22:24 +0800 Subject: [PATCH] + [misc] Add unit tests for adminZen::syncExtensions() 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 --- .../admin/test/lib/admin.unittest.class.php | 30 +++++++++++++++++++ module/admin/test/zen/syncextensions.php | 29 ++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100755 module/admin/test/zen/syncextensions.php diff --git a/module/admin/test/lib/admin.unittest.class.php b/module/admin/test/lib/admin.unittest.class.php index 1344289bf1..8601e47d2a 100644 --- a/module/admin/test/lib/admin.unittest.class.php +++ b/module/admin/test/lib/admin.unittest.class.php @@ -6,6 +6,16 @@ class adminTest global $tester; $this->objectModel = $tester->loadModel('admin'); $this->user = $tester->loadModel('user'); + + // 加载admin控制器基类 + if(!class_exists('admin')) + { + include dirname(__FILE__, 3) . '/control.php'; + } + + // 包含zen文件并实例化 + require_once dirname(__FILE__, 3) . '/zen.php'; + $this->objectZen = new adminZen(); } /** @@ -256,4 +266,24 @@ class adminTest // 对于非空参数,返回1表示执行成功 return 1; } + + /** + * Test syncExtensions method. + * + * @param string $type + * @param int $limit + * @access public + * @return mixed + */ + public function syncExtensionsTest(string $type = 'plugin', int $limit = 5) + { + $reflection = new ReflectionClass($this->objectZen); + $method = $reflection->getMethod('syncExtensions'); + $method->setAccessible(true); + + $result = $method->invoke($this->objectZen, $type, $limit); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/admin/test/zen/syncextensions.php b/module/admin/test/zen/syncextensions.php new file mode 100755 index 0000000000..93d2af28c7 --- /dev/null +++ b/module/admin/test/zen/syncextensions.php @@ -0,0 +1,29 @@ +#!/usr/bin/env php +syncExtensionsTest('plugin', 5)) && p() && e('1'); +r($adminTest->syncExtensionsTest('patch', 5)) && p() && e('1'); +r($adminTest->syncExtensionsTest('plugin', 10)) && p() && e('1'); +r($adminTest->syncExtensionsTest('patch', 1)) && p() && e('1'); +r($adminTest->syncExtensionsTest('plugin', 0)) && p() && e('1'); \ No newline at end of file