Files
miniapi/tests/evus_correction_route_self_check.php
gaofeng e0aeff2af7 提交
2026-09-01 11:07:13 +08:00

52 lines
2.1 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/../vendor/autoload.php';
use app\miniapi\service\EvusCorrection\EvusCorrectionService;
function miniCorrectionAssertSame(mixed $expected, mixed $actual, string $message): void
{
if ($expected !== $actual) {
throw new RuntimeException($message . PHP_EOL
. 'Expected: ' . var_export($expected, true) . PHP_EOL
. 'Actual: ' . var_export($actual, true));
}
}
$service = new EvusCorrectionService();
miniCorrectionAssertSame(
'https://user.example.com/home/evus_correction/detail',
$service->endpoint('https://user.example.com/home/users/login', 'detail'),
'Detail must use the existing user URL host and isolated upstream controller'
);
miniCorrectionAssertSame(
'https://user.example.com/home/evus_correction/submit',
$service->endpoint('https://user.example.com/home/users/login?source=mini', 'submit'),
'Submit must remove the existing users action and query string'
);
miniCorrectionAssertSame('', $service->endpoint('https://user.example.com/home/users/login', 'delete'), 'Unknown upstream actions must be rejected');
miniCorrectionAssertSame(
['user_id' => 88, 'order_sn' => 'EVUS-1'],
$service->payload(88, ['user_id' => 999, 'order_sn' => 'EVUS-1']),
'Authenticated user ID must override an untrusted client value'
);
$routes = file_get_contents(__DIR__ . '/../route/app.php');
if (!is_string($routes)
|| !str_contains($routes, "Route::get('evus/correction', 'EvusCorrection/detail');")
|| !str_contains($routes, "Route::post('evus/correction/submit', 'EvusCorrection/submit');")
) {
throw new RuntimeException('The miniapi must register explicit correction detail and submit routes');
}
$upload = file_get_contents(__DIR__ . '/../app/miniapi/controller/Upload.php');
if (!is_string($upload)
|| !str_contains($upload, "'evus_correction'")
|| !str_contains($upload, "'evus-correction/' . \$contactUserId . '/' . \$fileName")
) {
throw new RuntimeException('The correction upload scene must require login and use the account-scoped OSS prefix');
}
echo "Miniapi EVUS correction route self-check passed\n";