Skip to content
Open
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
9 changes: 3 additions & 6 deletions maint.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
chdir('../../');
include_once('./include/auth.php');
include_once($config['base_path'] . '/plugins/maint/functions.php');
include_once($config['base_path'] . '/plugins/maint/ui_helpers.php');

define('MAINT_HOST_FILTER_LOC_ANY', '__any'); // internal value unlikely in data
define('MAINT_HOST_FILTER_LOC_NONE', '__none');
Expand Down Expand Up @@ -99,15 +100,11 @@

break;
case 'edit':
top_header();
schedule_edit();
bottom_footer();
maint_render_with_layout('schedule_edit');

break;
default:
top_header();
schedules();
bottom_footer();
maint_render_with_layout('schedules');

break;
}
Expand Down
65 changes: 65 additions & 0 deletions tests/test_layout_wrapper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/*
+-------------------------------------------------------------------------+
| Copyright (C) 2004-2026 The Cacti Group |
| |
| Regression checks for shared layout wrapper routing in maint.php |
| |
| Run: php tests/test_layout_wrapper.php |
+-------------------------------------------------------------------------+
*/

$pass = 0;
$fail = 0;
$events = array();

function assert_true($label, $value) {
global $pass, $fail;

if ($value) {
echo "PASS $label\n";
$pass++;
} else {
echo "FAIL $label\n";
$fail++;
}
}

function top_header() {
global $events;
$events[] = 'top_header';
}

function bottom_footer() {
global $events;
$events[] = 'bottom_footer';
}

require_once __DIR__ . '/../ui_helpers.php';

$events = array();
$callback_runs = 0;

maint_render_with_layout(function () use (&$events, &$callback_runs) {
$events[] = 'content';
$callback_runs++;
});

assert_true('layout callback executes once', $callback_runs === 1);
assert_true('layout call order is top->content->bottom', $events === array('top_header', 'content', 'bottom_footer'));

$source = file_get_contents(__DIR__ . '/../maint.php');

assert_true(
'edit action uses shared layout helper',
strpos($source, "maint_render_with_layout('schedule_edit');") !== false
);
assert_true(
'default action uses shared layout helper',
strpos($source, "maint_render_with_layout('schedules');") !== false
);

echo "\n";
echo "Results: $pass passed, $fail failed\n";

exit($fail > 0 ? 1 : 0);
19 changes: 19 additions & 0 deletions ui_helpers.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?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. |
+-------------------------------------------------------------------------+
*/

if (!function_exists('maint_render_with_layout')) {
function maint_render_with_layout($renderer) {
top_header();
call_user_func($renderer);
bottom_footer();
}
}
Loading