Update README and metadata for version 1.1.1; add discovery test for plugin class loading

This commit is contained in:
interlope committed 2026-11-01 18:41:20 +01:00
1 parent 3dfd367814
commit 41e623d5d1
5 files changed
+60 -3

No files matched your search

+3
View File
@@ -130,9 +130,12 @@ No Composer dependencies or YAML extension are required. To run the tests agains
```bash
php -l plugin.php
php -l importer.php
BLUDIT_ROOT=/path/to/bludit-3.22.0 php tests/discovery.php
BLUDIT_ROOT=/path/to/bludit-3.22.0 php tests/import.php
```
The discovery regression test runs Bludit's real `buildPlugins()` with its real `Plugin` base class. Helper classes are loaded from `init()`, after class discovery, so Bludit does not mistake them for plugins.
Tests use temporary local storage and a fake GitHub transport. They exercise real Bludit page creation/editing, asset rewriting and export round trips, rejected paths, escaped previews, stale metadata/configuration, failed downloads and rollback after a failing page hook. They do not modify a live site or contact GitHub.
Optionally exercise a real exported article as a fixture too:
+1 -1
View File
@@ -2,7 +2,7 @@
"author": "spleenftw",
"email": "",
"website": "https://github.com/Spleenftw/bludit-github-sync",
"version": "1.1.0",
"version": "1.1.1",
"releaseDate": "2026-11-01",
"license": "MIT",
"compatible": "3.22.0",
+3 -2
View File
@@ -1,12 +1,13 @@
<?php
require_once __DIR__ . "/importer.php";
class pluginBluditGithub extends Plugin
{
private $importing = false;
public function init()
{
// Bludit discovers every class declared while including plugin.php.
// Load helpers only after that discovery pass has finished.
require_once __DIR__ . "/importer.php";
$this->dbFields = [
'token' => '',
'owner' => '',
+48
View File
@@ -0,0 +1,48 @@
<?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);
}
+5
View File
@@ -40,7 +40,11 @@ class Plugin {
public function workspace() { global $dir; return $dir . 'workspace/'; }
public function post() {}
}
$declaredBeforePlugin = get_declared_classes();
require dirname(__DIR__) . '/plugin.php';
if (array_values(array_diff(get_declared_classes(), $declaredBeforePlugin)) !== ['pluginBluditGithub']) {
throw new RuntimeException('Only the plugin class may be declared during Bludit discovery.');
}
class TestIndex { public $count = 0; public function exists($key) { return in_array($key, ['network', 'uncategorized'], true); } public function reindex() { $this->count++; return true; } }
class TestLog { public function add($args) {} }
class Theme {
@@ -90,6 +94,7 @@ $site = new class { public function sortBy() { return 'date'; } public function
$L = new class { public function g($s) { return $s; } public function getunicodeChars() { return []; } public function currentLanguage() { return 'en'; } };
Session::set('username', 'admin');
$plugin = new TestPlugin();
$plugin->init();
try {
// Parser and filesystem boundaries.
foreach (['../bad', 'a/b', '', 'x%2fy', 'x\\y'] as $slug) { rejects(function () use ($slug) { BluditGithubImport::slug($slug); }, 'folder name'); }