From 69ddaa2089d91ea6c69bdda06157ca13c8137e72 Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Wed, 14 Feb 2024 14:47:27 +0100 Subject: [PATCH] Updated tests --- Tests/Integration/Iframe/lazyloadIframes.php | 18 -------- .../Unit/Assets/getYoutubeThumbnailScript.php | 46 +++++++++++++------ Tests/Unit/Iframe/lazyloadIframes.php | 22 --------- 3 files changed, 31 insertions(+), 55 deletions(-) diff --git a/Tests/Integration/Iframe/lazyloadIframes.php b/Tests/Integration/Iframe/lazyloadIframes.php index 31ac9f0..afd43a1 100644 --- a/Tests/Integration/Iframe/lazyloadIframes.php +++ b/Tests/Integration/Iframe/lazyloadIframes.php @@ -46,22 +46,4 @@ public function testShouldReturnYoutubeLazyloaded() { $this->iframe->lazyloadIframes( $original, $original, $args ) ); } - - public function testShouldReturnIframeLazyloadedWithYoutubeLazyloadEnabled() { - $args = [ 'youtube' => true ]; - $original = file_get_contents( RLL_COMMON_ROOT . 'Tests/Fixtures/iframe/youtube.html' ); - $expected = file_get_contents( RLL_COMMON_ROOT . 'Tests/Fixtures/iframe/iframelazyloaded.html' ); - - add_filter( 'rocket_lazyload_exclude_youtube_thumbnail', function( $exclusion ) { - $exclusion[] = 'Yirc35yIjfc'; - $exclusion[] = '5x2Cr_4zRXA'; - - return $exclusion; - } ); - - $this->assertSame( - $expected, - $this->iframe->lazyloadIframes( $original, $original, $args ) - ); - } } diff --git a/Tests/Unit/Assets/getYoutubeThumbnailScript.php b/Tests/Unit/Assets/getYoutubeThumbnailScript.php index e646f02..95b0f06 100644 --- a/Tests/Unit/Assets/getYoutubeThumbnailScript.php +++ b/Tests/Unit/Assets/getYoutubeThumbnailScript.php @@ -3,6 +3,7 @@ namespace RocketLazyload\Tests\Unit\Assets; use Brain\Monkey\Functions; +use Brain\Monkey\Filters; use RocketLazyload\Assets; use RocketLazyload\Tests\Unit\TestCase; @@ -27,7 +28,10 @@ protected function set_up() { * @param array $args An array of arguments to configure the inline script. * @param string $expected the expected HTML. */ - public function testShouldReturnYoutubeThumbnailScript( $args, $expected ) { + public function testShouldReturnYoutubeThumbnailScript( $args, $excluded, $expected ) { + Filters\expectApplied( 'rocket_lazyload_exclude_youtube_thumbnail' ) + ->andReturn( $excluded ); + $this->assertSame( $expected, $this->assets->getYoutubeThumbnailScript( $args ) @@ -43,37 +47,43 @@ public function youtubeDataProvider() { return [ [ [], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ 'resolution' => 'mqdefault', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/mqdefault.jpg' ), ], [ [ 'resolution' => 'sddefault', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/sddefault.jpg' ), ], [ [ 'resolution' => 'hqdefault', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ 'resolution' => 'maxresdefault', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/maxresdefault.jpg' ), ], [ [ 'resolution' => 'ultra', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ @@ -81,7 +91,8 @@ public function youtubeDataProvider() { 'lazy_image' => true, 'native' => false, ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ @@ -89,7 +100,8 @@ public function youtubeDataProvider() { 'lazy_image' => true, 'native' => true, ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ @@ -98,16 +110,19 @@ public function youtubeDataProvider() { 'native' => true, 'extension' => 'webp', ], - $this->add_element( '' ), + [], + $this->add_element( '', '[]', 'https://i.ytimg.com/vi_webp/ID/hqdefault.webp' ), ], [ [ 'resolution' => 'hqdefault', 'lazy_image' => true, 'native' => true, - 'extension' => 'webp', ], - "", + [ + 'https://i.ytimg.com/vi/12345/hqdefault.jpg', + ], + $this->add_element( '', '["https:\/\/i.ytimg.com\/vi\/12345\/hqdefault.jpg"]', 'https://i.ytimg.com/vi/ID/hqdefault.jpg' ), ], [ [ @@ -116,12 +131,13 @@ public function youtubeDataProvider() { 'native' => true, 'extension' => 'webp', ], - "" + [], + "" ], ]; } - private function add_element( $element ) { - return ""; + private function add_element( $element, $excluded_patterns, $image_url ) { + return ""; } } diff --git a/Tests/Unit/Iframe/lazyloadIframes.php b/Tests/Unit/Iframe/lazyloadIframes.php index 411a635..3b5fc00 100644 --- a/Tests/Unit/Iframe/lazyloadIframes.php +++ b/Tests/Unit/Iframe/lazyloadIframes.php @@ -3,7 +3,6 @@ namespace RocketLazyload\Tests\Unit\Iframe; use Brain\Monkey\Functions; -use Brain\Monkey\Filters; use RocketLazyload\Iframe; use RocketLazyload\Tests\Unit\TestCase; @@ -72,25 +71,4 @@ public function testShouldReturnYoutubeLazyloaded() { $this->iframe->lazyloadIframes( $original, $original, $args ) ); } - - public function testShouldReturnIframeLazyloadedWithYoutubeLazyloadEnabled() { - $args = [ - 'youtube' => true, - ]; - - Functions\when( 'wp_parse_url' )->alias( function( $url, $component ) { - return parse_url( $url, $component ); - } ); - - Filters\expectApplied( 'rocket_lazyload_exclude_youtube_thumbnail' ) - ->andReturn( ['Yirc35yIjfc', '5x2Cr_4zRXA'] ); - - $original = file_get_contents( RLL_COMMON_ROOT . 'Tests/Fixtures/iframe/youtube.html' ); - $expected = file_get_contents( RLL_COMMON_ROOT . 'Tests/Fixtures/iframe/iframelazyloaded.html' ); - - $this->assertSame( - $expected, - $this->iframe->lazyloadIframes( $original, $original, $args ) - ); - } }