146 行
5.9 KiB
PHP
146 行
5.9 KiB
PHP
<?php
|
||
|
||
namespace tests\partner;
|
||
|
||
define('APP_PATH', __DIR__ . '/../../application/');
|
||
define('ROOT_PATH', dirname(realpath(APP_PATH)) . '/');
|
||
require_once __DIR__ . '/../../thinkphp/base.php';
|
||
require_once __DIR__ . '/../../thinkphp/helper.php';
|
||
require_once __DIR__ . '/../../application/common.php';
|
||
|
||
\think\Config::set(\think\Config::load(APP_PATH . 'config.php'));
|
||
\think\Config::set(include APP_PATH . 'database.php', 'database');
|
||
\think\Loader::addNamespace('app', APP_PATH);
|
||
require_once __DIR__ . '/../../addons/shopro/helper/helper.php';
|
||
|
||
use app\admin\controller\shopro\commission\Agent;
|
||
use think\Request;
|
||
use think\Db;
|
||
|
||
class AgentDetailTest
|
||
{
|
||
private $passed = 0;
|
||
private $failed = 0;
|
||
|
||
public function run()
|
||
{
|
||
echo "========================================================\n";
|
||
echo " 分销商详情新页面/选项卡及接口规范专项测试 \n";
|
||
echo "========================================================\n\n";
|
||
|
||
$this->testDetailNonExistUser();
|
||
$this->testDetailParamIntegrity();
|
||
$this->testDetailViewFileExists();
|
||
$this->testJsSyntaxAndAddtabsDefinition();
|
||
|
||
echo "\n--------------------------------------------------------\n";
|
||
echo "测试执行结果: 通过 {$this->passed} 项, 失败 {$this->failed} 项\n";
|
||
echo "========================================================\n";
|
||
return $this->failed === 0 ? 0 : 1;
|
||
}
|
||
|
||
private function assert($condition, $testName, $detail = '')
|
||
{
|
||
if ($condition) {
|
||
echo " [PASS] {$testName}\n";
|
||
$this->passed++;
|
||
} else {
|
||
echo " [FAIL] {$testName} - {$detail}\n";
|
||
$this->failed++;
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 测试 1:查询不存在的分销商详情返回错误
|
||
*/
|
||
public function testDetailNonExistUser()
|
||
{
|
||
try {
|
||
$agent = new Agent();
|
||
$request = Request::create('shopro/commission/agent/detail', 'GET', ['id' => 999999999], [], [], ['HTTP_X_REQUESTED_WITH' => 'xmlhttprequest']);
|
||
Request::instance($request);
|
||
|
||
try {
|
||
$agent->detail(999999999);
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
$response = $e->getResponse();
|
||
$data = $response->getData();
|
||
$this->assert(isset($data['code']) && $data['code'] === 0, '未找到分销商时返回业务错误状态', json_encode($data, JSON_UNESCAPED_UNICODE));
|
||
return;
|
||
}
|
||
$this->assert(false, '未找到分销商时应抛出错误响应');
|
||
} catch (\Throwable $e) {
|
||
$this->assert(true, '未找到分销商异常正常拦截: ' . $e->getMessage());
|
||
}
|
||
}
|
||
|
||
/**
|
||
* 测试 2:分销商详情视图文件存在且包含顶部返回与新选项卡样式
|
||
*/
|
||
public function testDetailViewFileExists()
|
||
{
|
||
$viewFile = ROOT_PATH . 'application/admin/view/shopro/commission/agent/detail.html';
|
||
$this->assert(file_exists($viewFile), '分销商详情视图文件 detail.html 存在');
|
||
|
||
$content = file_get_contents($viewFile);
|
||
$hasHeaderBar = strpos($content, 'detail-header-bar') !== false;
|
||
$hasBackBtn = strpos($content, 'onBack') !== false;
|
||
$hasFullHeight = strpos($content, 'height: 100vh') !== false;
|
||
|
||
$this->assert($hasHeaderBar, 'detail.html 包含 detail-header-bar 顶部栏');
|
||
$this->assert($hasBackBtn, 'detail.html 包含 onBack 返回按钮');
|
||
$this->assert($hasFullHeight, 'detail.html 样式适配选项卡 height: 100vh 满屏展示');
|
||
}
|
||
|
||
/**
|
||
* 测试 3:检查 agent.js 中 addtabs 逻辑与 onDetail 定义
|
||
*/
|
||
public function testJsSyntaxAndAddtabsDefinition()
|
||
{
|
||
$jsFile = ROOT_PATH . 'public/assets/js/backend/shopro/commission/agent.js';
|
||
$this->assert(file_exists($jsFile), 'agent.js 文件存在');
|
||
|
||
$content = file_get_contents($jsFile);
|
||
$hasAddtabs = strpos($content, 'Backend.api.addtabs(url, title)') !== false;
|
||
$hasOnBack = strpos($content, 'top.Backend.api.closetabs') !== false;
|
||
$hasQueryAgentId = strpos($content, 'queryAgentId') !== false;
|
||
|
||
$this->assert($hasAddtabs, 'agent.js 包含 Backend.api.addtabs 新页面选项卡打开逻辑');
|
||
$this->assert($hasOnBack, 'agent.js detail 包含 closetabs/Layer.close 智能返回逻辑');
|
||
$this->assert($hasQueryAgentId, 'agent.js detail 包含 queryAgentId 多模式参数兼容解析');
|
||
}
|
||
|
||
/**
|
||
* 测试 4:分销商详情存在时的字段完整性校验(如果有测试分销商)
|
||
*/
|
||
public function testDetailParamIntegrity()
|
||
{
|
||
$agentRow = Db::name('shopro_commission_agent')->find();
|
||
if (!$agentRow) {
|
||
$this->assert(true, '当前数据库暂无分销商数据,跳过数据字段验证');
|
||
return;
|
||
}
|
||
|
||
try {
|
||
$agent = new Agent();
|
||
$request = Request::create('shopro/commission/agent/detail', 'GET', ['id' => $agentRow['user_id']], [], [], ['HTTP_X_REQUESTED_WITH' => 'xmlhttprequest']);
|
||
Request::instance($request);
|
||
|
||
try {
|
||
$agent->detail($agentRow['user_id']);
|
||
} catch (\think\exception\HttpResponseException $e) {
|
||
$response = $e->getResponse();
|
||
$data = $response->getData();
|
||
$this->assert($data['code'] === 1 || $data['code'] === 0, '详情响应格式符合规范 (code/msg/data)');
|
||
$this->assert(isset($data['data']['user_id']), '详情数据包含 user_id');
|
||
$this->assert(isset($data['data']['active_status_text']), '详情数据包含成员自购活跃状态扩展字段');
|
||
}
|
||
} catch (\Throwable $e) {
|
||
$this->assert(false, '详情接口测试执行异常: ' . $e->getMessage());
|
||
}
|
||
}
|
||
}
|
||
|
||
$test = new AgentDetailTest();
|
||
exit($test->run());
|