Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/Unit/FlowviewConfigArraysTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
*/

/*
* Unit coverage for flowview_config_arrays() in setup.php - wires up the
* plugin's menu entries. It also calls plugin_flowview_check_upgrade() at
* the end, so PHP_SELF is set to a page outside that function's guard
* list to keep it from touching lib/poller.php or the flowview database
* connection.
*/

beforeAll(function () {
require_once __DIR__ . '/../../setup.php';
});

beforeEach(function () {
plugin_test_reset();
$_SERVER['PHP_SELF'] = '/graphs.php';
$GLOBALS['menu'] = array('Import/Export' => array());
});

it('adds the FlowView menu entries under Import/Export', function () {
global $menu;

flowview_config_arrays();

expect($menu)->toHaveKey('FlowView');
expect($menu['FlowView'])->toHaveKey('plugins/flowview/flowview_devices.php');
expect($menu['FlowView'])->toHaveKey('plugins/flowview/flowview_filters.php');
expect($menu['FlowView'])->toHaveKey('plugins/flowview/flowview_schedules.php');
expect($menu['FlowView'])->toHaveKey('plugins/flowview/flowview_databases.php');
});
43 changes: 43 additions & 0 deletions tests/Unit/FlowviewLifecycleTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
*/

/*
* Unit coverage for the plugin lifecycle contract functions in setup.php:
* plugin_flowview_check_config(), plugin_flowview_upgrade(), and
* plugin_flowview_check_upgrade()'s page-guard.
*
* plugin_flowview_check_upgrade() include_once()s Cacti core's real
* lib/poller.php and calls flowview_connect() (a real database connection
* routine) once its page guard passes, so only the guarded (skipped)
* path is exercised here - the same constraint documented for other
* plugins' poller_bottom-style functions in this fleet.
*/

beforeAll(function () {
require_once __DIR__ . '/../../setup.php';
});

beforeEach(function () {
plugin_test_reset();
$_SERVER['PHP_SELF'] = '/graphs.php';
});

it('reports invalid config and raises a message when no config file exists', function () {
expect(plugin_flowview_check_config())->toBeFalse();
expect($GLOBALS['__test_messages'])->not->toBeEmpty();
expect($GLOBALS['__test_messages'][0][0])->toBe('flowview_info');
});

it('always reports no upgrade pending', function () {
expect(plugin_flowview_upgrade())->toBeFalse();
});

it('skips the upgrade check on pages that do not need it', function () {
plugin_flowview_check_upgrade();

expect($GLOBALS['__test_db_calls'])->toBeEmpty();
});
26 changes: 26 additions & 0 deletions tests/Unit/FlowviewNavigationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
*/

/*
* Unit coverage for flowview_draw_navigation_text() in setup.php.
*/

beforeAll(function () {
require_once __DIR__ . '/../../setup.php';
});

it('adds the flowview breadcrumb entries without disturbing existing ones', function () {
$nav = flowview_draw_navigation_text(array('other.php:' => array('title' => 'Other')));

expect($nav)->toHaveKey('other.php:');

foreach (array('flowview.php:', 'flowview.php:view', 'flowview_devices.php:', 'flowview_schedules.php:', 'flowview_filters.php:') as $key) {
expect($nav)->toHaveKey($key);
}

expect($nav['flowview_devices.php:edit']['mapping'])->toBe('index.php:,flowview_devices.php:');
});
23 changes: 23 additions & 0 deletions tests/Unit/FlowviewVersionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
+-------------------------------------------------------------------------+
*/

/*
* Unit coverage for plugin_flowview_version() in setup.php.
*/

beforeAll(function () {
require_once __DIR__ . '/../../setup.php';
});

it('parses the plugin INFO file into an info array', function () {
$info = plugin_flowview_version();

expect($info)->toBeArray();
expect($info)->toHaveKey('name');
expect($info)->toHaveKey('version');
expect($info['name'])->toBe('flowview');
});
31 changes: 31 additions & 0 deletions tests/bootstrap-unit.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,37 @@ function api_plugin_db_add_column($plugin, $table, $data) {

if (!function_exists('api_plugin_db_table_create')) {
function api_plugin_db_table_create($plugin, $table, $data) {
$GLOBALS['__test_db_calls'][] = array('fn' => 'api_plugin_db_table_create', 'sql' => $table, 'params' => $data);
return true;
}
}

$GLOBALS['__test_registered_hooks'] = array();
Comment thread
TheWitness marked this conversation as resolved.

if (!function_exists('api_plugin_register_hook')) {
function api_plugin_register_hook($plugin, $hook, $function, $file, $subtype = '') {
$GLOBALS['__test_registered_hooks'][] = array(
'name' => $plugin,
'hook' => $hook,
'function' => $function,
'file' => $file,
);

return true;
}
}

$GLOBALS['__test_registered_realms'] = array();

if (!function_exists('api_plugin_register_realm')) {
function api_plugin_register_realm($plugin, $file, $description, $enabled) {
$GLOBALS['__test_registered_realms'][] = array(
'name' => $plugin,
'file' => $file,
'description' => $description,
'enabled' => $enabled,
);

return true;
}
}
Expand Down
Loading