Skip to content

Commit f4514ac

Browse files
author
Cacti Group
committed
Add unit coverage for graph_buttons and page_head glyph changes
The theme-glyph change touched quicktree_graph_buttons() (setup.php:219) and quicktree_page_head() (setup.php:265-268), which the patch-coverage gate flagged as uncovered. Add QuicktreeGraphButtonsTest and QuicktreePageHeadTest, plus get_md5_include_js/get_md5_include_css/get_selected_theme stubs in the unit bootstrap, to exercise both hooks.
1 parent 79f6c3f commit f4514ac

4 files changed

Lines changed: 144 additions & 0 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- issue: Fix quicktree_show_tab() building an invalid `?location=tabtab`/`?location=tabconsole` URL, an undefined-variable text-domain typo in the QuickTree page's "no graph specified" message, and a misspelled `qucktree` text domain
1010
- security: Migrate quicktree SQL helpers to prepared statements, normalize location handling, and ensure redirects terminate execution
1111
- test: Migrate test suite to Pest with a Cacti-provided test harness and CI workflow
12+
- feature: Give the QuickTree add/remove graph glyphs their own theme-appropriate colors across every packaged Cacti theme, instead of reusing the core deviceUp/deviceDown classes
1213

1314

1415
--- 2.0 ---
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
/*
3+
+-------------------------------------------------------------------------+
4+
| Copyright (C) 2004-2026 The Cacti Group |
5+
+-------------------------------------------------------------------------+
6+
*/
7+
8+
/*
9+
* Coverage for quicktree_graph_buttons(): the 'graph_buttons' hook prints an
10+
* "Add this graph to QuickTree" glyph for the current graph, but only when
11+
* the user is authorized for the quicktree realm.
12+
*/
13+
14+
beforeAll(function () {
15+
require_once __DIR__ . '/../../setup.php';
16+
});
17+
18+
beforeEach(function () {
19+
$GLOBALS['__test_realm_auth'] = true;
20+
});
21+
22+
it('prints an Add-to-QuickTree glyph for the current graph when authorized', function () {
23+
ob_start();
24+
quicktree_graph_buttons(array(1 => array('local_graph_id' => 42, 'rra' => 7)));
25+
$output = ob_get_clean();
26+
27+
expect($output)->toContain('quicktreeAdd');
28+
expect($output)->toContain('fa-plus-circle');
29+
expect($output)->toContain('addQuickTree(42, 7)');
30+
});
31+
32+
it('prints nothing when the user is not authorized for the quicktree realm', function () {
33+
$GLOBALS['__test_realm_auth'] = false;
34+
35+
ob_start();
36+
quicktree_graph_buttons(array(1 => array('local_graph_id' => 42, 'rra' => 7)));
37+
$output = ob_get_clean();
38+
39+
expect($output)->toBe('');
40+
});
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<?php
2+
/*
3+
+-------------------------------------------------------------------------+
4+
| Copyright (C) 2004-2026 The Cacti Group |
5+
+-------------------------------------------------------------------------+
6+
*/
7+
8+
/*
9+
* Coverage for quicktree_page_head(): the 'page_head' hook includes the
10+
* plugin JavaScript and base stylesheet on every page, and additionally
11+
* includes a theme-specific stylesheet when one exists for the selected
12+
* theme.
13+
*/
14+
15+
beforeAll(function () {
16+
require_once __DIR__ . '/../../setup.php';
17+
});
18+
19+
beforeEach(function () {
20+
$GLOBALS['__qt_orig_base'] = $GLOBALS['config']['base_path'];
21+
$GLOBALS['__test_selected_theme'] = 'modern';
22+
});
23+
24+
afterEach(function () {
25+
$GLOBALS['config']['base_path'] = $GLOBALS['__qt_orig_base'];
26+
27+
if (!empty($GLOBALS['__qt_tmp_base']) && is_dir($GLOBALS['__qt_tmp_base'])) {
28+
@unlink($GLOBALS['__qt_tmp_base'] . '/plugins/quicktree/css/modern.css');
29+
@rmdir($GLOBALS['__qt_tmp_base'] . '/plugins/quicktree/css');
30+
@rmdir($GLOBALS['__qt_tmp_base'] . '/plugins/quicktree');
31+
@rmdir($GLOBALS['__qt_tmp_base'] . '/plugins');
32+
@rmdir($GLOBALS['__qt_tmp_base']);
33+
}
34+
35+
$GLOBALS['__qt_tmp_base'] = null;
36+
});
37+
38+
it('includes the plugin JavaScript and base stylesheet', function () {
39+
ob_start();
40+
quicktree_page_head();
41+
$output = ob_get_clean();
42+
43+
expect($output)->toContain('plugins/quicktree/js/quicktree.js');
44+
expect($output)->toContain('plugins/quicktree/css/quicktree.css');
45+
});
46+
47+
it('includes the theme stylesheet when a matching theme file exists', function () {
48+
$base = sys_get_temp_dir() . '/qt_theme_' . uniqid();
49+
mkdir($base . '/plugins/quicktree/css', 0777, true);
50+
file_put_contents($base . '/plugins/quicktree/css/modern.css', '/* test */');
51+
52+
$GLOBALS['__qt_tmp_base'] = $base;
53+
$GLOBALS['config']['base_path'] = $base;
54+
$GLOBALS['__test_selected_theme'] = 'modern';
55+
56+
ob_start();
57+
quicktree_page_head();
58+
$output = ob_get_clean();
59+
60+
expect($output)->toContain('plugins/quicktree/css/modern.css');
61+
});
62+
63+
it('omits the theme stylesheet when no matching theme file exists', function () {
64+
$base = sys_get_temp_dir() . '/qt_theme_' . uniqid();
65+
mkdir($base . '/plugins/quicktree/css', 0777, true);
66+
67+
$GLOBALS['__qt_tmp_base'] = $base;
68+
$GLOBALS['config']['base_path'] = $base;
69+
$GLOBALS['__test_selected_theme'] = 'no-such-theme';
70+
71+
ob_start();
72+
quicktree_page_head();
73+
$output = ob_get_clean();
74+
75+
expect($output)->not->toContain('no-such-theme');
76+
expect($output)->toContain('plugins/quicktree/css/quicktree.css');
77+
});

‎tests/bootstrap-unit.php‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,29 @@ function form_end() {
388388
$GLOBALS['__form_wrapper_events'][] = 'form_end';
389389
}
390390
}
391+
392+
/*
393+
* quicktree_page_head() emits the plugin's JS/CSS includes and selects a
394+
* theme-specific stylesheet. These stubs return the asset paths verbatim so
395+
* specs can assert which includes were printed, and let the selected theme be
396+
* controlled per test.
397+
*/
398+
if (!function_exists('get_md5_include_js')) {
399+
function get_md5_include_js($path) {
400+
return "<script src='$path'></script>";
401+
}
402+
}
403+
404+
if (!function_exists('get_md5_include_css')) {
405+
function get_md5_include_css($path) {
406+
return "<link rel='stylesheet' href='$path'>";
407+
}
408+
}
409+
410+
$GLOBALS['__test_selected_theme'] = 'modern';
411+
412+
if (!function_exists('get_selected_theme')) {
413+
function get_selected_theme() {
414+
return $GLOBALS['__test_selected_theme'];
415+
}
416+
}

0 commit comments

Comments
 (0)