Initial import of db-manager
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
<?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";
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
|
||||
TMP_DIR="$(mktemp -d)"
|
||||
trap 'rm -rf "$TMP_DIR"' EXIT
|
||||
|
||||
DB_MANAGER_INSTALL_LIB_ONLY=1 source "$ROOT_DIR/scripts/install.sh"
|
||||
|
||||
id() {
|
||||
echo 0
|
||||
}
|
||||
|
||||
PLUGIN_DIR="$TMP_DIR/plugin"
|
||||
CPIF="$TMP_DIR/custom_package_items.conf"
|
||||
mkdir -p "$PLUGIN_DIR"
|
||||
|
||||
printf 'Always_enable=1\n' > "$PLUGIN_DIR/plugin-settings.conf"
|
||||
bootstrap_custom_package_item
|
||||
if [ -e "$CPIF" ]; then
|
||||
echo "custom_package_items.conf should not be created when Always_enable=1" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
printf 'Always_enable=0\n' > "$PLUGIN_DIR/plugin-settings.conf"
|
||||
bootstrap_custom_package_item
|
||||
if ! grep -q '^db_manager=' "$CPIF"; then
|
||||
echo "db_manager checkbox should be installed when Always_enable=0" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "OK"
|
||||
Reference in New Issue
Block a user