From 36013ff33bbba3f6e266c67254df6c43b6df4405 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Dec 2025 13:54:11 +0100 Subject: [PATCH 1/2] PICKME: Update font tests to use semantic HTML comparison --- .../font-face/wpFontFace/generateAndPrint.php | 8 ++++++-- .../fonts/font-face/wpPrintFontFaces.php | 20 +++++++++++++------ .../wpPrintFontFacesFromStyleVariations.php | 4 ++-- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php b/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php index d10ea500e8707..1f6b07b3cfb0c 100644 --- a/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php +++ b/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php @@ -34,7 +34,11 @@ public function test_should_generate_and_print_given_fonts( array $fonts, $expec $style_element = "\n"; $expected_output = sprintf( $style_element, $expected ); - $this->expectOutputString( $expected_output ); - $font_face->generate_and_print( $fonts ); + $output = get_echo( + function () use ( $font_face, $fonts ) { + $font_face->generate_and_print( $fonts ); + } + ); + $this->assertEqualHTML( $expected_output, $output ); } } diff --git a/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php b/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php index 2fa64559c2049..1d6ef663c5f22 100644 --- a/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php +++ b/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php @@ -37,8 +37,12 @@ public function test_should_not_print_when_no_fonts() { public function test_should_print_given_fonts( array $fonts, $expected ) { $expected_output = $this->get_expected_styles_output( $expected ); - $this->expectOutputString( $expected_output ); - wp_print_font_faces( $fonts ); + $output = get_echo( + function () use ( $fonts ) { + wp_print_font_faces( $fonts ); + } + ); + $this->assertEqualHTML( $expected_output, $output ); } public function test_should_escape_tags() { @@ -60,9 +64,13 @@ public function test_should_escape_tags() { CSS; - $this->expectOutputString( $expected_output ); - wp_print_font_faces( $fonts ); + $output = get_echo( + function () use ( $fonts ) { + wp_print_font_faces( $fonts ); + } + ); + $this->assertEqualHTML( $expected_output, $output ); } public function test_should_print_fonts_in_merged_data() { @@ -71,8 +79,8 @@ public function test_should_print_fonts_in_merged_data() { $expected = $this->get_expected_fonts_for_fonts_block_theme( 'font_face_styles' ); $expected_output = $this->get_expected_styles_output( $expected ); - $this->expectOutputString( $expected_output ); - wp_print_font_faces(); + $output = get_echo( 'wp_print_font_faces' ); + $this->assertEqualHTML( $expected_output, $output ); } private function get_expected_styles_output( $styles ) { diff --git a/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php b/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php index a59ba882a4e86..5dd6304fd2f7b 100644 --- a/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php +++ b/tests/phpunit/tests/fonts/font-face/wpPrintFontFacesFromStyleVariations.php @@ -43,8 +43,8 @@ public function test_should_print_fonts_in_style_variations() { $expected = $this->get_custom_style_variations( 'expected_styles' ); $expected_output = $this->get_expected_styles_output( $expected ); - $this->expectOutputString( $expected_output ); - wp_print_font_faces_from_style_variations(); + $output = get_echo( 'wp_print_font_faces_from_style_variations' ); + $this->assertEqualHTML( $expected_output, $output ); } private function get_expected_styles_output( $styles ) { From b1350b2c2aee79df8965e3eedc29f85d3e3ffa33 Mon Sep 17 00:00:00 2001 From: Jon Surrell Date: Tue, 23 Dec 2025 14:25:43 +0100 Subject: [PATCH 2/2] Use get_echo callback args --- .../fonts/font-face/wpFontFace/generateAndPrint.php | 6 +----- .../tests/fonts/font-face/wpPrintFontFaces.php | 12 ++---------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php b/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php index 1f6b07b3cfb0c..a6454c11d1883 100644 --- a/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php +++ b/tests/phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php @@ -34,11 +34,7 @@ public function test_should_generate_and_print_given_fonts( array $fonts, $expec $style_element = "\n"; $expected_output = sprintf( $style_element, $expected ); - $output = get_echo( - function () use ( $font_face, $fonts ) { - $font_face->generate_and_print( $fonts ); - } - ); + $output = get_echo( array( $font_face, 'generate_and_print' ), array( $fonts ) ); $this->assertEqualHTML( $expected_output, $output ); } } diff --git a/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php b/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php index 1d6ef663c5f22..71cd964ca1bd8 100644 --- a/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php +++ b/tests/phpunit/tests/fonts/font-face/wpPrintFontFaces.php @@ -37,11 +37,7 @@ public function test_should_not_print_when_no_fonts() { public function test_should_print_given_fonts( array $fonts, $expected ) { $expected_output = $this->get_expected_styles_output( $expected ); - $output = get_echo( - function () use ( $fonts ) { - wp_print_font_faces( $fonts ); - } - ); + $output = get_echo( 'wp_print_font_faces', array( $fonts ) ); $this->assertEqualHTML( $expected_output, $output ); } @@ -65,11 +61,7 @@ public function test_should_escape_tags() { CSS; - $output = get_echo( - function () use ( $fonts ) { - wp_print_font_faces( $fonts ); - } - ); + $output = get_echo( 'wp_print_font_faces', array( $fonts ) ); $this->assertEqualHTML( $expected_output, $output ); }