From 2b1b2b93e2920bf648654634aa97c9f4e008c557 Mon Sep 17 00:00:00 2001 From: WordPressFan Date: Tue, 18 Feb 2025 10:35:56 +0200 Subject: [PATCH] continue fixing unit tests 2 --- .../GoogleFonts/CombineV2/optimize.php | 81 +++++++++++++------ .../GoogleFonts/CombineV2/optimize.php | 17 +++- 2 files changed, 71 insertions(+), 27 deletions(-) diff --git a/tests/Fixtures/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php b/tests/Fixtures/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php index 7c827ede94..60fa32521f 100644 --- a/tests/Fixtures/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php +++ b/tests/Fixtures/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php @@ -42,8 +42,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -52,7 +52,11 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&display=swap', + ], + ], ], 'shouldNotCombineMultipleTagsWithTextParam' => [ 'config' => [ @@ -69,8 +73,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -79,7 +83,11 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&display=swap', + ], + ], ], 'shouldCombineMultipleTags' => [ 'config' => [ @@ -97,8 +105,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -106,7 +114,12 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&family=Comfortaa&display=swap', + ], + ], + ], 'shouldCombineMultipleTagsWithMultipleFamiliesInTag' => [ 'config' => [ @@ -125,8 +138,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -135,7 +148,12 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Goldman:wght@700&family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&family=Comfortaa&display=swap', + ], + ], + ], 'shouldReplaceAnotherFontDisplayValueWithSwap' => [ 'config' => [ @@ -154,8 +172,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -164,7 +182,12 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Goldman:wght@700&family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&family=Comfortaa&display=swap', + ], + ], + ], 'shouldReplaceDisplayValueWithFilteredValue' => [ 'config' => [ @@ -183,8 +206,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -193,8 +216,11 @@ - ' - , + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Goldman:wght@700&family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&family=Comfortaa&display=optional', + ] + ], ], 'shouldCombineMultipleTagsNoPreload' => [ 'config' => [ @@ -212,8 +238,8 @@ ', - 'expected' => - ' + 'expected' => [ + 'html' => ' Sample Page @@ -221,7 +247,11 @@ - ' + ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&family=Comfortaa&display=swap', + ], + ], ], 'shouldExcludeFontFromCombine' => [ 'config' => [ @@ -244,7 +274,8 @@ ', - 'expected' => ' + 'expected' => [ + 'html' => ' @@ -261,5 +292,9 @@ </body> </html> ', + 'fonts' => [ + 'https://fonts.googleapis.com/css2?family=Goldman:wght@700&family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&family=MontSerra:ital,wght@0,100;0,400;0,500;1,500;1,900&family=Comfortaa&display=optional', + ], + ], ] ]; diff --git a/tests/Unit/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php b/tests/Unit/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php index b9f57421b4..99c758dd79 100644 --- a/tests/Unit/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php +++ b/tests/Unit/inc/Engine/Optimization/GoogleFonts/CombineV2/optimize.php @@ -51,10 +51,19 @@ public function testShouldCombineV2GoogleFonts( $config, $html, $expected ) { ->andReturn( $config['exclude_locally_host_fonts'] ?? [] ); $combiner = new CombineV2(); + $optimized_html = $combiner->optimize( $html ); + + if ( is_string( $expected ) ) { + $this->assertSame( + $this->format_the_html( $expected ), + $this->format_the_html( $optimized_html ) + ); + } else if ( is_array( $expected ) ) { + $this->assertSame( + $expected['fonts'], + $combiner->get_font_urls() + ); + } - $this->assertSame( - $this->format_the_html( $expected ), - $this->format_the_html( $combiner->optimize( $html ) ) - ); } }