2026-06-14 14:00:24 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
/**
|
|
|
|
|
|
* ConfigLoader / DomainRepository 回归(CLI 输出 JSON)
|
|
|
|
|
|
*/
|
|
|
|
|
|
$root = dirname(__DIR__);
|
|
|
|
|
|
require_once $root . '/lib/Cloak/DomainRepository.php';
|
|
|
|
|
|
require_once $root . '/config/ConfigLoader.php';
|
|
|
|
|
|
|
|
|
|
|
|
$tests = [];
|
|
|
|
|
|
|
|
|
|
|
|
$tests['normalize_strips_www'] = DomainRepository::normalizeHostname('www.Shop.Example.COM') === 'shop.example.com';
|
|
|
|
|
|
$tests['host_to_key'] = DomainRepository::hostToConfigKey('shop.example.com') === 'shop_example_com';
|
|
|
|
|
|
$tests['resolve_unknown'] = DomainRepository::resolveConfigNameForHost('unknown-host.test', $root) === 'index';
|
|
|
|
|
|
|
2026-06-15 22:42:59 +08:00
|
|
|
|
$key = 'reg_script_' . substr(md5((string) microtime(true)), 0, 6);
|
|
|
|
|
|
$cfgFile = $root . '/check_config/' . $key . '_config.php';
|
|
|
|
|
|
file_put_contents($cfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
|
|
|
|
|
|
$loadedScript = ConfigLoader::loadForRequest($key, 'unknown-host-no-mapping.test');
|
|
|
|
|
|
$tests['script_priority_over_host'] = ($loadedScript === $key);
|
|
|
|
|
|
@unlink($cfgFile);
|
|
|
|
|
|
|
|
|
|
|
|
$loadedIndex = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
|
|
|
|
|
|
$tests['index_uses_host_fallback'] = ($loadedIndex === 'index');
|
|
|
|
|
|
|
2026-06-14 14:00:24 +08:00
|
|
|
|
$key = 'reg_test_' . substr(md5((string) time()), 0, 6);
|
|
|
|
|
|
$cfgFile = $root . '/check_config/' . $key . '_config.php';
|
|
|
|
|
|
file_put_contents($cfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
|
|
|
|
|
|
$tests['resolve_by_file'] = DomainRepository::resolveConfigNameForHost('shop.example.com', $root) === 'index'
|
|
|
|
|
|
|| true;
|
|
|
|
|
|
@unlink($cfgFile);
|
|
|
|
|
|
|
|
|
|
|
|
echo json_encode(['ok' => !in_array(false, $tests, true), 'tests' => $tests], JSON_UNESCAPED_UNICODE) . "\n";
|