diff --git a/tests/Fixtures/inc/Engine/Media/Fonts/Context/Context/isAllowed.php b/tests/Fixtures/inc/Engine/Media/Fonts/Context/Context/isAllowed.php new file mode 100644 index 0000000000..27932a1790 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/Fonts/Context/Context/isAllowed.php @@ -0,0 +1,18 @@ + [ + 'config' => [ + 'local_google_fonts' => false, + 'rocket_self_host_fonts' => true, + ], + 'expected' => true, + ], + 'testShouldReturnFalseWhenFeatureDisabled' => [ + 'config' => [ + 'local_google_fonts' => true, + 'rocket_self_host_fonts' => false, + ], + 'expected' => false, + ], +]; diff --git a/tests/Fixtures/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php b/tests/Fixtures/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php new file mode 100644 index 0000000000..ccae42b1d3 --- /dev/null +++ b/tests/Fixtures/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php @@ -0,0 +1,34 @@ + [ + 'config' => [ + 'font_url' => 'https://fonts.googleapis.com/css2?family=Roboto', + ], + 'expected' => '/wp-content/cache/wp-rocket/fonts/google-fonts/2/b7488900b01c2ffa45c4faf5876bd050.css', + ], + 'testShouldReturnLocalUrlWithVersion' => [ + 'config' => [ + 'font_url' => 'https://fonts.googleapis.com/css2?family=Roboto&ver=1.0', + ], + 'expected' => '/wp-content/cache/wp-rocket/fonts/google-fonts/2/bd7d7cead547593f5d4c8a439f32e209.css', + ], + 'testShouldReturnLocalUrlWithSubset' => [ + 'config' => [ + 'font_url' => 'https://fonts.googleapis.com/css2?family=Roboto:300,400,500&subset=latin,latin-ext', + ], + 'expected' => '/wp-content/cache/wp-rocket/fonts/google-fonts/2/b6eed853c9ca4324a5fd627ea3465c48.css', + ], + 'testShouldReturnLocalUrlWithMultipleFonts' => [ + 'config' => [ + 'font_url' => 'https://fonts.googleapis.com/css2?family=Roboto|Open+Sans', + ], + 'expected' => '/wp-content/cache/wp-rocket/fonts/google-fonts/2/3d7fe3a1467a88318d3fb6e4ced0b127.css', + ], + 'testShouldReturnLocalUrlWithMultipleFontsAndVersion' => [ + 'config' => [ + 'font_url' => 'https://fonts.googleapis.com/css2?family=Roboto|Open+Sans&ver=1.0', + ], + 'expected' => '/wp-content/cache/wp-rocket/fonts/google-fonts/2/3fbdd05b1bf26933207aeb7d3d910d30.css', + ], +]; diff --git a/tests/Unit/inc/Engine/Media/Fonts/Context/Context/isAllowed.php b/tests/Unit/inc/Engine/Media/Fonts/Context/Context/isAllowed.php new file mode 100644 index 0000000000..033140deda --- /dev/null +++ b/tests/Unit/inc/Engine/Media/Fonts/Context/Context/isAllowed.php @@ -0,0 +1,26 @@ +once() + ->with('local_google_fonts') + ->andReturn($config['local_google_fonts']); + + $this->assertSame($expected, $context->is_allowed($config)); + } +} diff --git a/tests/Unit/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php b/tests/Unit/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php new file mode 100644 index 0000000000..50de9eac86 --- /dev/null +++ b/tests/Unit/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php @@ -0,0 +1,27 @@ +once() + ->with('WP_ROCKET_CACHE_PATH') + ->andReturn('/wp-content/cache/wp-rocket/'); + + $result = $googleFontV1->get_local_url(); + $this->assertEquals($expected, $result); + } +}