From 6c1140dc7f097e85cc3a95cd57a0f39e07dd855d Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 29 Mar 2026 00:36:13 -0600 Subject: [PATCH 1/3] test(functions): add Danger_Functions_Test for wu_drop_tables Adds unit tests for inc/functions/danger.php, the only function file from issue #701 without test coverage. Tests use filter interception to prevent actual table drops while verifying the function exists, applies wu_drop_tables and wu_drop_tables_except filters, and handles an empty table list without throwing exceptions. Closes #701 --- .../Functions/Danger_Functions_Test.php | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 tests/WP_Ultimo/Functions/Danger_Functions_Test.php diff --git a/tests/WP_Ultimo/Functions/Danger_Functions_Test.php b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php new file mode 100644 index 000000000..6d08bbdc8 --- /dev/null +++ b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php @@ -0,0 +1,156 @@ +assertTrue(function_exists('wu_drop_tables')); + } + + /** + * Test wu_drop_tables applies the wu_drop_tables filter. + * + * We intercept via the filter to return an empty array, preventing + * any actual table drops during the test run. + */ + public function test_wu_drop_tables_applies_filter(): void { + + $filter_called = false; + + add_filter( + 'wu_drop_tables', + function ($tables) use (&$filter_called) { + $filter_called = true; + // Return empty array to prevent actual table drops. + return []; + } + ); + + wu_drop_tables(); + + remove_all_filters('wu_drop_tables'); + + $this->assertTrue($filter_called, 'wu_drop_tables filter was not applied'); + } + + /** + * Test wu_drop_tables applies the wu_drop_tables_except filter. + * + * We intercept wu_drop_tables to return an empty list so no tables + * are actually dropped, while still verifying the except filter fires. + */ + public function test_wu_drop_tables_applies_except_filter(): void { + + $except_filter_called = false; + + // Prevent actual drops. + add_filter('wu_drop_tables', '__return_empty_array'); + + add_filter( + 'wu_drop_tables_except', + function ($except) use (&$except_filter_called) { + $except_filter_called = true; + return $except; + } + ); + + wu_drop_tables(); + + remove_all_filters('wu_drop_tables'); + remove_all_filters('wu_drop_tables_except'); + + $this->assertTrue($except_filter_called, 'wu_drop_tables_except filter was not applied'); + } + + /** + * Test wu_drop_tables_except default list contains blogs and blogmeta. + */ + public function test_wu_drop_tables_except_default_contains_core_tables(): void { + + $captured_except = null; + + // Prevent actual drops. + add_filter('wu_drop_tables', '__return_empty_array'); + + add_filter( + 'wu_drop_tables_except', + function ($except) use (&$captured_except) { + $captured_except = $except; + return $except; + } + ); + + wu_drop_tables(); + + remove_all_filters('wu_drop_tables'); + remove_all_filters('wu_drop_tables_except'); + + $this->assertIsArray($captured_except); + $this->assertContains('blogs', $captured_except); + $this->assertContains('blogmeta', $captured_except); + } + + /** + * Test wu_drop_tables runs without exception when table list is empty. + */ + public function test_wu_drop_tables_no_exception_with_empty_list(): void { + + add_filter('wu_drop_tables', '__return_empty_array'); + + $exception_thrown = false; + + try { + wu_drop_tables(); + } catch (\Exception $e) { + $exception_thrown = true; + } + + remove_all_filters('wu_drop_tables'); + + $this->assertFalse($exception_thrown, 'wu_drop_tables threw an unexpected exception'); + } + + /** + * Test wu_drop_tables_except filter can add custom exclusions. + */ + public function test_wu_drop_tables_except_filter_can_add_exclusions(): void { + + $captured_except = null; + + // Prevent actual drops. + add_filter('wu_drop_tables', '__return_empty_array'); + + add_filter( + 'wu_drop_tables_except', + function ($except) use (&$captured_except) { + $except[] = 'custom_table'; + $captured_except = $except; + return $except; + } + ); + + wu_drop_tables(); + + remove_all_filters('wu_drop_tables'); + remove_all_filters('wu_drop_tables_except'); + + $this->assertContains('custom_table', $captured_except); + } +} From efe844b6742fb245ca37bfb60e4a94344e082a17 Mon Sep 17 00:00:00 2001 From: David Stone Date: Sun, 29 Mar 2026 00:54:43 -0600 Subject: [PATCH 2/3] fix(tests): add ABSPATH guard to Danger_Functions_Test Addresses CodeRabbit review on PR #702: adds the standard direct-access guard after the opening Date: Sun, 29 Mar 2026 01:05:10 -0600 Subject: [PATCH 3/3] fix(tests): remove ABSPATH guard causing fatal namespace error Test files do not use ABSPATH guards. The guard on line 2 placed the namespace declaration after a non-declare statement, triggering: 'Fatal error: Namespace declaration statement has to be the very first statement' Fixes #701 --- tests/WP_Ultimo/Functions/Danger_Functions_Test.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/WP_Ultimo/Functions/Danger_Functions_Test.php b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php index 93299a490..6d08bbdc8 100644 --- a/tests/WP_Ultimo/Functions/Danger_Functions_Test.php +++ b/tests/WP_Ultimo/Functions/Danger_Functions_Test.php @@ -1,6 +1,4 @@