From ef8bb9a668d9b12c8bcdbc04b5a74df8b425566d Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sun, 15 Mar 2026 16:18:29 -0700 Subject: [PATCH] refactor: DRY audit page layout wrapper --- audit.php | 10 ++---- tests/test_layout_wrapper.php | 65 +++++++++++++++++++++++++++++++++++ ui_helpers.php | 19 ++++++++++ 3 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 tests/test_layout_wrapper.php create mode 100644 ui_helpers.php diff --git a/audit.php b/audit.php index dffed41..f4f3291 100644 --- a/audit.php +++ b/audit.php @@ -24,6 +24,7 @@ chdir('../../'); include_once('./include/auth.php'); +include_once('./plugins/audit/ui_helpers.php'); set_default_action(); @@ -35,9 +36,7 @@ case 'purge': audit_purge(); - top_header(); - audit_log(); - bottom_footer(); + audit_render_with_layout('audit_log'); break; case 'getdata': @@ -132,9 +131,7 @@ break; default: - top_header(); - audit_log(); - bottom_footer(); + audit_render_with_layout('audit_log'); } function audit_purge() { @@ -463,4 +460,3 @@ function audit_log() { content->bottom', $events === array('top_header', 'content', 'bottom_footer')); + +$source = file_get_contents(__DIR__ . '/../audit.php'); + +assert_true( + 'purge/default actions use shared layout helper', + substr_count($source, "audit_render_with_layout('audit_log');") >= 2 +); +assert_true( + 'audit.php includes ui helper file', + strpos($source, "include_once('./plugins/audit/ui_helpers.php');") !== false +); + +echo "\n"; +echo "Results: $pass passed, $fail failed\n"; + +exit($fail > 0 ? 1 : 0); diff --git a/ui_helpers.php b/ui_helpers.php new file mode 100644 index 0000000..767356f --- /dev/null +++ b/ui_helpers.php @@ -0,0 +1,19 @@ +