-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
tests/Fixtures/inc/Engine/Media/Fonts/Context/Context/isAllowed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldReturnTrueWhenFeatureEnabled' => [ | ||
'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, | ||
], | ||
]; |
34 changes: 34 additions & 0 deletions
34
tests/Fixtures/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
return [ | ||
'testShouldReturnLocalUrl' => [ | ||
'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', | ||
], | ||
]; |
26 changes: 26 additions & 0 deletions
26
tests/Unit/inc/Engine/Media/Fonts/Context/Context/isAllowed.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Unit\inc\Engine\Media\Fonts\Context\Context; | ||
|
||
use WP_Rocket\Tests\Unit\TestCase; | ||
use WP_Rocket\Engine\Media\Fonts\Context\Context; | ||
use Brain\Monkey\Functions; | ||
|
||
class Test_IsAllowed extends TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoExpected($config, $expected) | ||
{ | ||
$context = new Context(); | ||
|
||
Functions\expect('get_option') | ||
->once() | ||
->with('local_google_fonts') | ||
->andReturn($config['local_google_fonts']); | ||
|
||
$this->assertSame($expected, $context->is_allowed($config)); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
tests/Unit/inc/Engine/Media/Fonts/Factory/Fonts/GoogleFontV2/getLocalUrl.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\tests\Unit\inc\Engine\Media\Fonts\Factory\Fonts\GoogleFontV2; | ||
|
||
use WP_Rocket\Engine\Media\Fonts\Factory\Fonts\GoogleFontV2; | ||
use WP_Rocket\Tests\Unit\TestCase; | ||
use Brain\Monkey\Functions; | ||
|
||
class Test_GetLocalUrl extends TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider configTestData | ||
*/ | ||
public function testShouldDoExpected($config, $expected) | ||
{ | ||
$googleFontV1 = new GoogleFontV2($config['font_url']); | ||
|
||
Functions\expect('WP_Rocket\Engine\Media\Fonts\Factory\Fonts\rocket_get_constant') | ||
->once() | ||
->with('WP_ROCKET_CACHE_PATH') | ||
->andReturn('/wp-content/cache/wp-rocket/'); | ||
|
||
$result = $googleFontV1->get_local_url(); | ||
$this->assertEquals($expected, $result); | ||
} | ||
} |