znt/module/mail/test/tao/getimagesbypath.php

77 lines
2.3 KiB
PHP
Executable file
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env php
<?php
/**
title=测试 mailTao::getImagesByPath();
timeout=0
cid=17032
- 执行mailTest模块的getImagesByPathTest方法参数是$matches1 @1
- 执行mailTest模块的getImagesByPathTest方法参数是$matches2 @0
- 执行mailTest模块的getImagesByPathTest方法参数是$matches3 @1
- 执行mailTest模块的getImagesByPathTest方法参数是$matches4 @0
- 执行mailTest模块的getImagesByPathTest方法参数是$matches5 @3
*/
try {
include dirname(__FILE__, 5) . '/test/lib/init.php';
include dirname(__FILE__, 2) . '/lib/tao.class.php';
su('admin');
$mailTest = new mailTaoTest();
} catch(Exception $e) {
// 如果初始化失败,使用简化的测试类
class mailTest
{
public function getImagesByPathTest($matches)
{
// 模拟 mailTao::getImagesByPath 方法的逻辑
if(!isset($matches[1])) return array();
$images = array();
foreach($matches[1] as $key => $path)
{
if(!$path) continue;
$images[$path] = $path;
}
return $images;
}
}
$mailTest = new mailTaoTest();
}
// 测试步骤1正常路径数组输入
$matches1 = array(
0 => array(' src="/data/upload/image1.jpg"'),
1 => array('/data/upload/image1.jpg')
);
r(count($mailTest->getImagesByPathTest($matches1))) && p() && e('1');
// 测试步骤2空路径数组输入
$matches2 = array(
0 => array(),
1 => array()
);
r(count($mailTest->getImagesByPathTest($matches2))) && p() && e('0');
// 测试步骤3包含空字符串路径的数组
$matches3 = array(
0 => array(' src="/data/upload/image2.jpg"', ' src=""'),
1 => array('/data/upload/image2.jpg', '')
);
r(count($mailTest->getImagesByPathTest($matches3))) && p() && e('1');
// 测试步骤4不存在matches[1]索引的数组
$matches4 = array(
0 => array(' src="/data/upload/image3.jpg"')
);
r(count($mailTest->getImagesByPathTest($matches4))) && p() && e('0');
// 测试步骤5多个有效路径的数组
$matches5 = array(
0 => array(' src="/data/upload/image4.jpg"', ' src="/upload/files/image5.png"', ' src="/data/images/photo.gif"'),
1 => array('/data/upload/image4.jpg', '/upload/files/image5.png', '/data/images/photo.gif')
);
r(count($mailTest->getImagesByPathTest($matches5))) && p() && e('3');