Skip to content

Commit

Permalink
continue fixing unit tests 2
Browse files Browse the repository at this point in the history
  • Loading branch information
wordpressfan committed Feb 18, 2025
1 parent 7df16c8 commit 2b1b2b9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title><link rel="preload" data-rocket-preload as="style" href="https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;display=swap" />
Expand All @@ -52,7 +52,11 @@
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;display=swap',
],
],
],
'shouldNotCombineMultipleTagsWithTextParam' => [
'config' => [
Expand All @@ -69,8 +73,8 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
Expand All @@ -79,7 +83,11 @@
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;display=swap',
],
],
],
'shouldCombineMultipleTags' => [
'config' => [
Expand All @@ -97,16 +105,21 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
<link rel="preload" data-rocket-preload as="style" href="https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap" /><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap" media="print" onload="this.media=\'all\'" /><noscript><link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap" /></noscript>
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap',
],
],

],
'shouldCombineMultipleTagsWithMultipleFamiliesInTag' => [
'config' => [
Expand All @@ -125,8 +138,8 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
Expand All @@ -135,7 +148,12 @@
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Goldman:wght@700&#038;family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&#038;family=Comfortaa&#038;display=swap',
],
],

],
'shouldReplaceAnotherFontDisplayValueWithSwap' => [
'config' => [
Expand All @@ -154,8 +172,8 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
Expand All @@ -164,7 +182,12 @@
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Goldman:wght@700&#038;family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&#038;family=Comfortaa&#038;display=swap',
],
],

],
'shouldReplaceDisplayValueWithFilteredValue' => [
'config' => [
Expand All @@ -183,8 +206,8 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
Expand All @@ -193,8 +216,11 @@
</head>
<body>
</body>
</html>'
,
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Goldman:wght@700&#038;family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&#038;family=Comfortaa&#038;display=optional',
]
],
],
'shouldCombineMultipleTagsNoPreload' => [
'config' => [
Expand All @@ -212,16 +238,20 @@
<body>
</body>
</html>',
'expected' =>
'<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>Sample Page</title>
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap" />
</head>
<body>
</body>
</html>'
</html>',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Crimson+Pro:wght@450&#038;family=Comfortaa&#038;display=swap',
],
],
],
'shouldExcludeFontFromCombine' => [
'config' => [
Expand All @@ -244,7 +274,8 @@
<body>
</body>
</html>',
'expected' => '<!doctype html>
'expected' => [
'html' => '<!doctype html>
<html>
<head>
<title>
Expand All @@ -261,5 +292,9 @@
</body>
</html>
',
'fonts' => [
'https://fonts.googleapis.com/css2?family=Goldman:wght@700&#038;family=Roboto:ital,wght@0,100;0,400;0,500;1,500;1,900&#038;family=MontSerra:ital,wght@0,100;0,400;0,500;1,500;1,900&#038;family=Comfortaa&#038;display=optional',
],
],
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) )
);
}
}

0 comments on commit 2b1b2b9

Please sign in to comment.