Files

49 lines
2.7 KiB
PHP

<?php
if (PHP_SAPI !== 'cli') { http_response_code(403); exit; }
// Exercise Bludit's actual class-discovery loop, real Plugin base and constructor.
error_reporting(E_ALL);
set_error_handler(function ($level, $message, $file, $line) {
if (!(error_reporting() & $level)) { return false; }
throw new ErrorException($message, 0, $level, $file, $line);
});
$root = getenv('BLUDIT_ROOT');
if (!$root || !is_file($root . '/bl-kernel/boot/rules/60.plugins.php')) {
throw new RuntimeException('Set BLUDIT_ROOT to a Bludit 3.x source checkout.');
}
$dir = sys_get_temp_dir() . '/bludit-discovery-test-' . bin2hex(random_bytes(8)) . '/';
define('BLUDIT', true);
define('DS', DIRECTORY_SEPARATOR);
define('CHARSET', 'UTF-8');
define('DEBUG_MODE', false);
define('LOG_TYPE_INFO', 'INFO');
define('CHECK_SYMBOLIC_LINKS', true);
define('DEFAULT_LANGUAGE_FILE', 'en.json');
define('PATH_PLUGINS', $dir . 'plugins/');
define('PATH_PLUGINS_DATABASES', $dir . 'database/');
define('PATH_WORKSPACES', $dir . 'workspaces/');
foreach (['plugins/bludit-github/languages', 'database/bludit-github', 'workspaces/bludit-github'] as $sub) {
mkdir($dir . $sub, 0700, true);
}
$source = getenv('PLUGIN_SOURCE') ?: dirname(__DIR__);
foreach (['plugin.php', 'importer.php', 'metadata.json', 'languages/en.json'] as $file) {
copy($source . '/' . $file, PATH_PLUGINS . 'bludit-github/' . $file);
}
file_put_contents(PATH_PLUGINS_DATABASES . 'bludit-github/db.php', "<?php defined('BLUDIT') or die('Bludit CMS.'); ?>\n{}");
foreach (['filesystem', 'sanitize', 'session', 'log'] as $helper) { require $root . '/bl-kernel/helpers/' . $helper . '.class.php'; }
require $root . '/bl-kernel/abstract/dbjson.class.php';
require $root . '/bl-kernel/abstract/plugin.class.php';
$site = new class { public function language() { return 'en'; } };
$L = new class { public function add($words) {} };
try {
require $root . '/bl-kernel/boot/rules/60.plugins.php';
if (array_keys($plugins['all']) !== ['pluginBluditGithub'] || array_keys($pluginsInstalled) !== ['pluginBluditGithub']) {
throw new RuntimeException('A helper was discovered as a plugin or the real plugin was not installed.');
}
if (!class_exists('BluditGithubImport', false)) { throw new RuntimeException('Import helper was not loaded during initialization.'); }
// Uninstalled plugins are discovered too; loading must also work before installation.
if ($plugins['all']['pluginBluditGithub']->directoryName() !== 'bludit-github') { throw new RuntimeException('Directory identity changed.'); }
echo "PASS: real Bludit 3.x plugin discovery, installed Plugin constructor, metadata and language loading\n";
} finally {
Filesystem::deleteRecursive($dir);
}