-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add add_preconnect_cdn() method * Add integration test draft and notes. * Implement preconnect for non-crossorigin cdn-urls * Add fixture, adjust integration test * Revise forcorrect cdn urls, use crossorigin second * Run phpcbf * Update CDN preconnect testcases * Use agnostic scheme when not provided * Rerun phpcs * Clean dns-prefetch out of testcases :) * Add testcase/solution for `test/tests`
- Loading branch information
Showing
4 changed files
with
142 additions
and
4 deletions.
There are no files selected for viewing
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
23 changes: 23 additions & 0 deletions
23
tests/Fixtures/inc/Engine/CDN/Subscriber/add-preconnect-cdn.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,23 @@ | ||
<?php | ||
|
||
return [ | ||
'shouldAddPreconnectLinkForCdn' => [ | ||
'cdn-cnames' => [ | ||
'123456.rocketcdn.me', | ||
'https://my-cdn.cdnservice.com/', | ||
'http://cdn.example.com', | ||
'/some/path/with/no/domain', | ||
'test/tests', | ||
'8901.wicked-fast-cdn.com/path/to/my/files', | ||
'https://another.cdn.com/with/a/path', | ||
], | ||
'expected-html' => <<<HTML | ||
<link rel='dns-prefetch' href='//s.w.org' /> | ||
<link href='//123456.rocketcdn.me' rel='preconnect' /> | ||
<link href='https://my-cdn.cdnservice.com' rel='preconnect' /> | ||
<link href='http://cdn.example.com' rel='preconnect' /> | ||
<link href='//8901.wicked-fast-cdn.com' rel='preconnect' /> | ||
<link href='https://another.cdn.com' rel='preconnect' /> | ||
HTML | ||
], | ||
]; |
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
45 changes: 45 additions & 0 deletions
45
tests/Integration/inc/Engine/CDN/Subscriber/addPreconnectCdn.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,45 @@ | ||
<?php | ||
|
||
namespace WP_Rocket\Tests\Integration\inc\Engine\CDN\Subscriber; | ||
|
||
/** | ||
* @covers \WP_Rocket\Engine\CDN\Subscriber::add_preconnect_cdn | ||
* @uses \WP_Rocket\Engine\CDN\CDN::get_cdn_urls | ||
* @group CDN | ||
*/ | ||
class Test_addPreconnectCdn extends TestCase { | ||
|
||
public function setUp() { | ||
$this->unregisterAllCallbacksExcept( 'wp_resource_hints', 'add_preconnect_cdn', 10 ); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function tearDown() { | ||
$this->restoreWpFilter( 'wp_resource_hints' ); | ||
|
||
parent::tearDown(); | ||
} | ||
|
||
/** | ||
* @dataProvider providerTestData | ||
*/ | ||
public function testShouldAddPreconnectCdn($cnames, $expected) { | ||
$this->cnames = $cnames; | ||
|
||
add_filter( 'pre_get_rocket_option_cdn', [ $this, 'return_true'] ); | ||
add_filter( 'rocket_cdn_cnames', [ $this, 'setCnames' ] ); | ||
|
||
ob_start(); | ||
wp_resource_hints(); | ||
|
||
$this->assertSame( | ||
$this->format_the_html($expected), | ||
$this->format_the_html(ob_get_clean()) | ||
); | ||
} | ||
|
||
public function providerTestData() { | ||
return $this->getTestData( __DIR__, 'add-preconnect-cdn' ); | ||
} | ||
} |