Files
cacti/tests/Unit/Plugin/PluginVersionRangeTest.php
Thomas Vincent cf70ba4cf2 fix(plugins): [develop] restore lifecycle diagnostics, compatibility and error attribution (#8297)
* 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>
2026-10-14 22:53:44 -04:00

69 lines
2.8 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';
test('plugin version constraints preserve comparator boundaries (#7968)', function ($range, $version, $expected) {
expect(plugin_valid_version_range($range, $version))->toBe($expected);
})->with([
['1.2.0', '1.2.0', true],
['1.2.0', '1.3.0', true],
['1.2.0', '1.1.0', false],
['>=1.2.0 <1.4.0', '1.3.0', true],
['>=1.2.0 <1.4.0', '1.2.0', true],
['>=1.2.0 <1.4.0', '1.4.0', false],
['>1.2.0 <=1.4.0', '1.2.0', false],
['>1.2.0 <=1.4.0', '1.4.0', true],
['>1.2.0 <=1.4.0', '1.4.1', false],
['=1.3.0 >=1.2.0', '1.3.0', true],
['=1.3.0 >=1.2.0', '1.3.1', false],
['<1.4.0', '1.3.0', true],
['<=1.4.0', '1.4.0', true],
['>1.2.0', '1.2.0', false],
['>=1.2.0', '1.2.0', true],
['=1.2.0', '1.2.1', false],
[" >=1.2.0\t\t<1.4.0\n", '1.3.0', true],
['>=1.4.0 <1.2.0', '1.3.0', false],
['', '1.3.0', false],
['>=1.2.0 garbage', '1.3.0', false],
['!=1.2.0', '1.3.0', false],
['>= 1.2.0', '1.3.0', false],
]);
test('plugin compatibility and INFO status agree on matching version ranges', function ($range, $compatible) {
$name = 'version_fixture_' . bin2hex(random_bytes(6));
$directory = CACTI_PATH_PLUGINS . '/' . $name;
mkdir($directory);
try {
file_put_contents($directory . '/INFO', "[info]\nname = $name\ncompat = \"$range\"\n");
$info = plugin_load_info_file($directory . '/INFO');
expect($info['status'])->toBe($compatible ? 0 : -1);
expect(plugin_is_compatible($name)['compat'])->toBe($compatible);
} finally {
unlink($directory . '/INFO');
rmdir($directory);
}
})->with([
['>=1.0.0 <2.0.0', true],
['1.0.0', true],
['>=2.0.0 <3.0.0', false],
]);