mirror of
https://github.com/Cacti/cacti.git
synced 2026-10-26 21:18:40 +09:00
* fix(plugins): honor version range boundaries and compatibility status Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(plugins): preserve null hook diagnostics and enforce dependency versions Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(plugins): report config failures and confine error attribution Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(plugins): guard entrypoint frames and bind realm filenames Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(plugins): propagate install hook failures on develop Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(plugins): match realm filenames literally Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * docs(changelog): defer release entries to final backlog PR Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test(plugins): add standard GPL headers Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci(coverage): require 80 percent of changed PHP statements Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci: share changed-code coverage contracts and enforce shell policy Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * fix(ci): run request coverage with portable path matching Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * ci: retain bootstrap coverage and validate request dispatch Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test: synchronize native coverage fixture dispatch Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> * test: measure coverage at the exact PR revision Signed-off-by: Thomas Vincent <thomasvincent@gmail.com> --------- Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
75 lines
3.4 KiB
PHP
75 lines
3.4 KiB
PHP
<?php
|
|
/*
|
|
+-------------------------------------------------------------------------+
|
|
| Copyright (C) 2004-2026 The Cacti Group |
|
|
| |
|
|
| This program is free software; you can redistribute it and/or |
|
|
| modify it under the terms of the GNU General Public License |
|
|
| as published by the Free Software Foundation; either version 2 |
|
|
| of the License, or (at your option) any later version. |
|
|
| |
|
|
| This program is distributed in the hope that it will be useful, |
|
|
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
| GNU General Public License for more details. |
|
|
+-------------------------------------------------------------------------+
|
|
| Cacti: The Complete RRDtool-based Graphing Solution |
|
|
+-------------------------------------------------------------------------+
|
|
*/
|
|
|
|
require_once dirname(__DIR__, 2) . '/Helpers/CactiStubs.php';
|
|
require_once dirname(__DIR__, 3) . '/include/global.php';
|
|
require_once dirname(__DIR__, 2) . '/Helpers/FakeMySQLPDO.php';
|
|
|
|
test('plugin installation compares requirements against the installed dependency version (#7968)', function ($required, $installed, $status, $expected) {
|
|
$keys = ['database_hostname', 'database_port', 'database_default', 'database_sessions', 'database_total_queries', 'config', 'database_log', 'database_last_error', 'affected_rows', 'error_logged'];
|
|
$saved = [];
|
|
|
|
foreach ($keys as $key) {
|
|
$saved[$key] = [array_key_exists($key, $GLOBALS), $GLOBALS[$key] ?? null];
|
|
}
|
|
$name = 'dependency_test_' . bin2hex(random_bytes(6));
|
|
$directory = CACTI_PATH_PLUGINS . '/' . $name;
|
|
mkdir($directory);
|
|
|
|
try {
|
|
$db = new FakeMySQLPDO();
|
|
$db->exec('CREATE TABLE settings (name TEXT PRIMARY KEY, value TEXT)');
|
|
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
|
$db->exec('CREATE TABLE plugin_config (directory TEXT, version TEXT, status INTEGER)');
|
|
|
|
if ($installed !== null) {
|
|
$db->prepare('INSERT INTO plugin_config VALUES (?, ?, ?)')->execute(['dependency_fixture', $installed, $status]);
|
|
}
|
|
$GLOBALS['database_hostname'] = 'dependency-test';
|
|
$GLOBALS['database_port'] = 0;
|
|
$GLOBALS['database_default'] = 'dependency-test';
|
|
$GLOBALS['database_sessions'] = ['dependency-test:0:dependency-test' => $db];
|
|
$GLOBALS['database_total_queries'] = 0;
|
|
file_put_contents($directory . '/INFO', "[info]\nrequires = \"$required\"\n");
|
|
$message = '';
|
|
expect(api_plugin_can_install($name, $message))->toBe($expected);
|
|
expect($message === '')->toBe($expected);
|
|
} finally {
|
|
foreach ($saved as $key => [$exists, $value]) {
|
|
if ($exists) {
|
|
$GLOBALS[$key] = $value;
|
|
} else {
|
|
unset($GLOBALS[$key]);
|
|
}
|
|
}
|
|
unlink($directory . '/INFO');
|
|
rmdir($directory);
|
|
}
|
|
})->with([
|
|
['dependency_fixture:1.0.0', '1.2.0', 4, true],
|
|
['dependency_fixture:1.2.0', '1.2.0', 4, true],
|
|
['dependency_fixture:1.3.0', '1.2.0', 4, false],
|
|
['dependency_fixture:>1.2.0', '1.2.0', 4, false],
|
|
['dependency_fixture:>=1.2.0', '1.2.0', 1, true],
|
|
['dependency_fixture', '1.2.0', 4, true],
|
|
['dependency_fixture', null, 0, false],
|
|
['dependency_fixture:1.0.0', '1.2.0', 0, false],
|
|
['dependency_fixture:1.0.0', null, 0, false],
|
|
]);
|