From 73daa517b062eb24c1408c55b29327b67d1938b8 Mon Sep 17 00:00:00 2001 From: liugang Date: Wed, 24 Sep 2025 02:23:17 +0800 Subject: [PATCH] * [misc] Enhance unit tests for mailTao::replaceImageURL() 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/mail/test/lib/mail.unittest.class.php | 18 ++++++++++ module/mail/test/tao/replaceimageurl.php | 37 +++++++++++--------- 2 files changed, 38 insertions(+), 17 deletions(-) mode change 100644 => 100755 module/mail/test/tao/replaceimageurl.php diff --git a/module/mail/test/lib/mail.unittest.class.php b/module/mail/test/lib/mail.unittest.class.php index 7442129a28..4174092992 100755 --- a/module/mail/test/lib/mail.unittest.class.php +++ b/module/mail/test/lib/mail.unittest.class.php @@ -728,4 +728,22 @@ class mailTest return $result; } } + + /** + * Test replaceImageURL method. + * + * @param string $body + * @param array $images + * @access public + * @return string + */ + public function replaceImageURLTest($body, $images = array()) + { + $method = new ReflectionMethod($this->objectTao, 'replaceImageURL'); + $method->setAccessible(true); + $result = $method->invoke($this->objectTao, $body, $images); + if(dao::isError()) return dao::getError(); + + return $result; + } } diff --git a/module/mail/test/tao/replaceimageurl.php b/module/mail/test/tao/replaceimageurl.php old mode 100644 new mode 100755 index adfffb2898..003301a254 --- a/module/mail/test/tao/replaceimageurl.php +++ b/module/mail/test/tao/replaceimageurl.php @@ -3,28 +3,31 @@ /** -title=测试 mailModel->replaceImageURL(); +title=测试 mailTao::replaceImageURL(); +timeout=0 cid=0 -- 图片链接为 {1.png} @ -- 图片链接为 data/upload @ -- 图片链接为 /file-read-1.png @ +- 步骤1:空图片数组保持原内容 @ +- 步骤2:单个图片URL替换 @ +- 步骤3:多个图片URL替换 @ +- 步骤4:包含空文件路径 @ +- 步骤5:复杂HTML内容 @

Text

Link +- 步骤6:不存在的URL保持不变 @ +- 步骤7:边界情况测试 @0 */ + include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/mail.unittest.class.php'; + su('admin'); -global $tester; -$mailModel = $tester->loadModel('mail'); -$mailModel->app->user->account = 'admin'; -$mailModel->config->requestType = 'PATH_INFO'; -$mailModel->config->webRoot = '/'; -$mailModel->config->mail->domain = 'http://pms.zentao.net'; +$mailTest = new mailTest(); -$body1 = ''; -$body2 = ''; -$body3 = ''; - -r($mailModel->replaceImageURL($body1, array())) && p() && e(''); //图片链接为 {1.png} -r($mailModel->replaceImageURL($body2, array())) && p() && e(''); //图片链接为 data/upload -r($mailModel->replaceImageURL($body3, array())) && p() && e(''); //图片链接为 /file-read-1.png +r($mailTest->replaceImageURLTest('', array())) && p() && e(''); // 步骤1:空图片数组保持原内容 +r($mailTest->replaceImageURLTest('', array('/image1.jpg' => 'file1.jpg'))) && p() && e(''); // 步骤2:单个图片URL替换 +r($mailTest->replaceImageURLTest('', array('/img1.png' => 'pic1.png', '/img2.gif' => 'pic2.gif'))) && p() && e(''); // 步骤3:多个图片URL替换 +r($mailTest->replaceImageURLTest('', array('/valid.jpg' => 'valid.jpg', '/empty.jpg' => ''))) && p() && e(''); // 步骤4:包含空文件路径 +r($mailTest->replaceImageURLTest('

Text

Link', array('/logo.png' => 'logo.png'))) && p() && e('

Text

Link'); // 步骤5:复杂HTML内容 +r($mailTest->replaceImageURLTest('', array('/other.jpg' => 'other.jpg'))) && p() && e(''); // 步骤6:不存在的URL保持不变 +r($mailTest->replaceImageURLTest('', array())) && p() && e('0'); // 步骤7:边界情况测试 \ No newline at end of file