From 0c6bfccaf74916a323ae161216b9b489d90ef3e8 Mon Sep 17 00:00:00 2001 From: Thomas Vincent Date: Sun, 15 Mar 2026 16:12:46 -0700 Subject: [PATCH] refactor: DRY gexport page layout wrapper --- gexport.php | 14 ++------ tests/test_layout_wrapper.php | 65 +++++++++++++++++++++++++++++++++++ ui_helpers.php | 19 ++++++++++ 3 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 tests/test_layout_wrapper.php create mode 100644 ui_helpers.php diff --git a/gexport.php b/gexport.php index fa23718..a31ed65 100644 --- a/gexport.php +++ b/gexport.php @@ -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'), @@ -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; } @@ -937,4 +930,3 @@ function gexport() { form_end(); } - diff --git a/tests/test_layout_wrapper.php b/tests/test_layout_wrapper.php new file mode 100644 index 0000000..0943dd4 --- /dev/null +++ b/tests/test_layout_wrapper.php @@ -0,0 +1,65 @@ +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 +); + +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..8331a99 --- /dev/null +++ b/ui_helpers.php @@ -0,0 +1,19 @@ +