52 lines
1.6 KiB
PHP
52 lines
1.6 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
$index_path = __DIR__ . '/../user/index.html';
|
|
$source = file_get_contents($index_path);
|
|
if ($source === false) {
|
|
fwrite(STDERR, "Cannot read user/index.html\n");
|
|
exit(1);
|
|
}
|
|
|
|
$marker = "\n\$params = read_params();";
|
|
$pos = strpos($source, $marker);
|
|
if ($pos === false) {
|
|
fwrite(STDERR, "Cannot find main script marker\n");
|
|
exit(1);
|
|
}
|
|
|
|
$functions = substr($source, 0, $pos);
|
|
$functions = preg_replace('/^#!.*\n/', '', $functions);
|
|
$functions = preg_replace('/^<\?php\s*/', '', $functions);
|
|
eval($functions);
|
|
|
|
function assert_same($expected, $actual, string $message): void
|
|
{
|
|
if ($expected !== $actual) {
|
|
fwrite(STDERR, $message . "\nExpected: " . var_export($expected, true) . "\nActual: " . var_export($actual, true) . "\n");
|
|
exit(1);
|
|
}
|
|
}
|
|
|
|
$tmp_settings = tempnam(sys_get_temp_dir(), 'dbm-settings-');
|
|
if ($tmp_settings === false) {
|
|
fwrite(STDERR, "Cannot create temp settings file\n");
|
|
exit(1);
|
|
}
|
|
|
|
try {
|
|
file_put_contents($tmp_settings, "");
|
|
$defaults = load_settings($tmp_settings);
|
|
assert_same('0', $defaults['Always_enable'] ?? null, 'Always_enable defaults to 0');
|
|
|
|
file_put_contents($tmp_settings, "Always_enable=1\n");
|
|
$settings = load_settings($tmp_settings);
|
|
assert_same('1', $settings['Always_enable'] ?? null, 'Always_enable is loaded from plugin-settings.conf');
|
|
|
|
assert_same(true, is_plugin_enabled_for_user('__db_manager_missing_user__', 'db-manager', $settings), 'Always_enable=1 enables plugin without per-user checkbox state');
|
|
} finally {
|
|
@unlink($tmp_settings);
|
|
}
|
|
|
|
echo "OK\n";
|