From d1c878f98822932717b72ec010f670ac6f15a574 Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 13:15:49 +0530 Subject: [PATCH 1/2] Tests: Add unit tests for `wp_finalize_scraping_edited_file_errors()` --- .../wpFinalizeScrapingEditedFileErrors.php | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php diff --git a/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php b/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php new file mode 100644 index 0000000000000..36ec52f4aa0be --- /dev/null +++ b/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php @@ -0,0 +1,61 @@ +assertSame( + "\n###### wp_scraping_result_start:abc123 ######\n" . + 'true' . + "\n###### wp_scraping_result_end:abc123 ######\n", + $output + ); + } + + /** + * @ticket 65819 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_ignores_non_fatal_errors() { + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Populate error_get_last() without raising a fatal. + @trigger_error( 'Warning only', E_USER_WARNING ); + + $output = get_echo( 'wp_finalize_scraping_edited_file_errors', array( 'warn-key' ) ); + + $this->assertSame( + "\n###### wp_scraping_result_start:warn-key ######\n" . + 'true' . + "\n###### wp_scraping_result_end:warn-key ######\n", + $output + ); + } + + /** + * @ticket 65819 + * + * @runInSeparateProcess + * @preserveGlobalState disabled + */ + public function test_uses_the_provided_scrape_key_in_markers() { + $output = get_echo( 'wp_finalize_scraping_edited_file_errors', array( 'custom-key-42' ) ); + + $this->assertStringContainsString( '###### wp_scraping_result_start:custom-key-42 ######', $output ); + $this->assertStringContainsString( '###### wp_scraping_result_end:custom-key-42 ######', $output ); + } +} From cb1202030517134fdff6ea9a243509e336252afa Mon Sep 17 00:00:00 2001 From: Shail Mehta Date: Mon, 19 Oct 2026 17:41:00 +0530 Subject: [PATCH 2/2] Apply Feedback changes --- .../wpFinalizeScrapingEditedFileErrors.php | 36 ++++++++----------- 1 file changed, 14 insertions(+), 22 deletions(-) diff --git a/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php b/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php index 36ec52f4aa0be..64caa502cb936 100644 --- a/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php +++ b/tests/phpunit/tests/load/wpFinalizeScrapingEditedFileErrors.php @@ -9,30 +9,35 @@ */ class Tests_Load_WpFinalizeScrapingEditedFileErrors extends WP_UnitTestCase { + public function tear_down() { + // Don't leave the error from test_ignores_non_fatal_errors() for later tests. + error_clear_last(); + + parent::tear_down(); + } + /** * @ticket 65819 - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function test_outputs_true_when_there_is_no_fatal_error() { - $output = get_echo( 'wp_finalize_scraping_edited_file_errors', array( 'abc123' ) ); + error_clear_last(); + + $output = get_echo( 'wp_finalize_scraping_edited_file_errors', array( 'custom-key-42' ) ); $this->assertSame( - "\n###### wp_scraping_result_start:abc123 ######\n" . + "\n###### wp_scraping_result_start:custom-key-42 ######\n" . 'true' . - "\n###### wp_scraping_result_end:abc123 ######\n", + "\n###### wp_scraping_result_end:custom-key-42 ######\n", $output ); } /** * @ticket 65819 - * - * @runInSeparateProcess - * @preserveGlobalState disabled */ public function test_ignores_non_fatal_errors() { + error_clear_last(); + // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged, WordPress.PHP.DevelopmentFunctions.error_log_trigger_error -- Populate error_get_last() without raising a fatal. @trigger_error( 'Warning only', E_USER_WARNING ); @@ -45,17 +50,4 @@ public function test_ignores_non_fatal_errors() { $output ); } - - /** - * @ticket 65819 - * - * @runInSeparateProcess - * @preserveGlobalState disabled - */ - public function test_uses_the_provided_scrape_key_in_markers() { - $output = get_echo( 'wp_finalize_scraping_edited_file_errors', array( 'custom-key-42' ) ); - - $this->assertStringContainsString( '###### wp_scraping_result_start:custom-key-42 ######', $output ); - $this->assertStringContainsString( '###### wp_scraping_result_end:custom-key-42 ######', $output ); - } }