修复配置获取
This commit is contained in:
@@ -22,6 +22,37 @@ $tests['script_priority_over_host'] = ($loadedScript === $key);
|
||||
$loadedIndex = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
|
||||
$tests['index_uses_host_fallback'] = ($loadedIndex === 'index');
|
||||
|
||||
$uriKey = 'reg_uri_' . substr(md5((string) microtime(true)), 0, 6);
|
||||
$uriCfgFile = $root . '/check_config/' . $uriKey . '_config.php';
|
||||
file_put_contents($uriCfgFile, "<?php define('SHOW_SITE_MODE_SWITCH','ip_check');\n");
|
||||
$prevUri = $_SERVER['REQUEST_URI'] ?? null;
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '?utm_campaign=test&fbclid=abc';
|
||||
$loadedUri = ConfigLoader::loadForRequest('index', 'unknown-host-no-mapping.test');
|
||||
$tests['uri_slug_over_index_script'] = ($loadedUri === $uriKey);
|
||||
$tests['uri_parse_strips_query'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '.php?utm=1';
|
||||
$fromPhp = ConfigLoader::resolveConfigNameFromRequestUri($root);
|
||||
$_SERVER['REQUEST_URI'] = '/' . $uriKey . '?utm=1';
|
||||
$fromPretty = ConfigLoader::resolveConfigNameFromRequestUri($root);
|
||||
return $fromPhp === $uriKey && $fromPretty === $uriKey;
|
||||
})();
|
||||
$tests['fingerprint_from_page_url'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$pageUrl = 'https://shop.example.com/' . $uriKey . '?utm=1&fbclid=abc';
|
||||
$loaded = ConfigLoader::loadForFingerprint($pageUrl, 'shop.example.com');
|
||||
return $loaded === $uriKey;
|
||||
})();
|
||||
$tests['fingerprint_prefers_explicit_config'] = (function () use ($root, $uriKey, $uriCfgFile) {
|
||||
$pageUrl = 'https://other.example.com/wrong-slug?utm=1';
|
||||
$loaded = ConfigLoader::loadForFingerprint($pageUrl, 'other.example.com', $uriKey);
|
||||
return $loaded === $uriKey;
|
||||
})();
|
||||
if ($prevUri === null) {
|
||||
unset($_SERVER['REQUEST_URI']);
|
||||
} else {
|
||||
$_SERVER['REQUEST_URI'] = $prevUri;
|
||||
}
|
||||
@unlink($uriCfgFile);
|
||||
|
||||
$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");
|
||||
|
||||
Reference in New Issue
Block a user