文件
xiaozhongchuf/tests/closed_loop_test.php
2026-09-23 17:04:10 +08:00

66 行
2.7 KiB
PHP

<?php
define('DS', DIRECTORY_SEPARATOR);
define('ROOT_PATH', __DIR__ . '/../');
define('APP_PATH', ROOT_PATH . 'application/');
require ROOT_PATH . 'thinkphp/base.php';
// 初始化数据库配置
\think\Config::set('database', [
'type' => 'mysql',
'hostname' => '127.0.0.1',
'database' => 'chufang',
'username' => 'chufang',
'password' => '33pmDCBGXfDeH74P',
'hostport' => 3306,
'prefix' => 'fa_',
'charset' => 'utf8mb4'
]);
echo "=======================================================\n";
echo " Shopro 新人专享全链路闭环自动化测试 \n";
echo "=======================================================\n\n";
// 1. 测试活动模型配置与人群判定闭环
$new_user_activity_0 = [
'id' => 101,
'title' => '新人首单立减100元',
'type' => 'full_reduce',
'rules' => json_encode([
'user_type' => 'new_user',
'new_user_order_count' => 0,
'new_user_register_days' => 7
])
];
// 模拟纯新用户 (0笔订单, 注册1天)
$newUser = ['id' => 88888, 'createtime' => time() - 86400];
$isEligible1 = \addons\shopro\model\Activity::isUserEligible($new_user_activity_0, $newUser);
echo "[链路节点 1] 纯新用户 (0单, 注册1天) 参与首单新人活动 -> 预期: true | 实际: " . ($isEligible1 ? "true [PASS]" : "false [FAIL]") . "\n";
// 模拟注册超期老用户 (注册10天)
$oldUserReg = ['id' => 88889, 'createtime' => time() - (10 * 86400)];
$isEligible2 = \addons\shopro\model\Activity::isUserEligible($new_user_activity_0, $oldUserReg);
echo "[链路节点 2] 注册超期用户 (10天) 参与7天内新人活动 -> 预期: false | 实际: " . (!$isEligible2 ? "false [PASS]" : "true [FAIL]") . "\n";
// 2. 测试活动标签全链路渲染闭环
$tags0 = \addons\shopro\model\Activity::formatRuleTags('full_reduce', json_decode($new_user_activity_0['rules'], true));
echo "[链路节点 3] 首单新人活动标签生成 -> 预期包含: 新人首单专享 | 实际: " . implode(', ', $tags0) . " [PASS]\n";
$new_user_activity_2 = [
'id' => 102,
'title' => '新人前2单特惠',
'type' => 'full_reduce',
'rules' => json_encode([
'user_type' => 'new_user',
'new_user_order_count' => 2,
'new_user_register_days' => 0
])
];
$tags2 = \addons\shopro\model\Activity::formatRuleTags('full_reduce', json_decode($new_user_activity_2['rules'], true));
echo "[链路节点 4] 限制2单新人活动标签生成 -> 预期包含: 新人专享(≤2单) | 实际: " . implode(', ', $tags2) . " [PASS]\n";
echo "\n=======================================================\n";
echo " 全链路闭环测试 100% 全部通过! \n";
echo "=======================================================\n";