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
14 changes: 3 additions & 11 deletions gexport.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
chdir('../../');
include('./include/auth.php');
include_once('./plugins/gexport/functions.php');
include_once('./plugins/gexport/ui_helpers.php');

$export_actions = array(
'1' => __('Delete', 'gexport'),
Expand All @@ -51,19 +52,11 @@

break;
case 'edit':
top_header();

export_edit();

bottom_footer();
gexport_render_with_layout('export_edit');

break;
default:
top_header();

gexport();

bottom_footer();
gexport_render_with_layout('gexport');

break;
}
Expand Down Expand Up @@ -937,4 +930,3 @@ function gexport() {

form_end();
}

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 gexport.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();
$runs = 0;

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

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

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

assert_true(
'edit action uses shared layout helper',
strpos($source, "gexport_render_with_layout('export_edit');") !== false
);
assert_true(
'default action uses shared layout helper',
strpos($source, "gexport_render_with_layout('gexport');") !== false
Comment on lines +55 to +59
);
Comment on lines +53 to +60

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. |
+-------------------------------------------------------------------------+
Comment on lines +9 to +10
*/

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