From 7cd0ff48125f308a5b7ac8209eeb6174265748ab Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 15 Apr 2024 12:27:18 +0000 Subject: [PATCH] Tests: Use an image on WordPress.org CDN in external HTTP tests. Due to some changes on the WP.com side to compress the requested images on the fly, the exact image size in the response could be different between platforms. This commit aims to make the affected tests more reliable. Follow-up to [139/tests], [31258], [34568], [47142], [57903], [57904], [57924]. Merges [57931] to the 5.6 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/5.6@57995 602fd350-edb4-49c9-b593-d223f7449a82 --- .../phpunit/tests/functions/wpRemoteFopen.php | 4 +- tests/phpunit/tests/http/functions.php | 40 +++++++++++-------- tests/phpunit/tests/image/functions.php | 6 +-- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/tests/phpunit/tests/functions/wpRemoteFopen.php b/tests/phpunit/tests/functions/wpRemoteFopen.php index 1a4fa19619..68836be27a 100644 --- a/tests/phpunit/tests/functions/wpRemoteFopen.php +++ b/tests/phpunit/tests/functions/wpRemoteFopen.php @@ -26,10 +26,10 @@ class Tests_Functions_wpRemoteFopen extends WP_UnitTestCase { */ public function test_wp_remote_fopen() { // This URL gives a direct 200 response. - $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; + $url = 'https://s.w.org/screenshots/3.9/dashboard.png'; $response = wp_remote_fopen( $url ); $this->assertInternalType( 'string', $response ); - $this->assertSame( 40148, strlen( $response ) ); + $this->assertSame( 153204, strlen( $response ) ); } } diff --git a/tests/phpunit/tests/http/functions.php b/tests/phpunit/tests/http/functions.php index a01c032051..48ee04b704 100644 --- a/tests/phpunit/tests/http/functions.php +++ b/tests/phpunit/tests/http/functions.php @@ -9,7 +9,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { function test_head_request() { // This URL gives a direct 200 response. - $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; + $url = 'https://s.w.org/screenshots/3.9/dashboard.png'; $response = wp_remote_head( $url ); $this->skipTestOnTimeout( $response ); @@ -18,30 +18,38 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertInternalType( 'array', $response ); - $this->assertSame( 'image/jpeg', $headers['content-type'] ); - $this->assertSame( '40148', $headers['content-length'] ); + $this->assertSame( 'image/png', $headers['Content-Type'] ); + $this->assertSame( '153204', $headers['Content-Length'] ); $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } function test_head_redirect() { // This URL will 301 redirect. - $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; + $url = 'https://wp.org/screenshots/3.9/dashboard.png'; $response = wp_remote_head( $url ); $this->skipTestOnTimeout( $response ); $this->assertSame( 301, wp_remote_retrieve_response_code( $response ) ); } - function test_head_404() { - $url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg'; + /** + * @covers ::wp_remote_head + */ + public function test_head_404() { + $url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg'; $response = wp_remote_head( $url ); $this->skipTestOnTimeout( $response ); $this->assertSame( 404, wp_remote_retrieve_response_code( $response ) ); } - function test_get_request() { - $url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg'; + /** + * @covers ::wp_remote_get + * @covers ::wp_remote_retrieve_headers + * @covers ::wp_remote_retrieve_response_code + */ + public function test_get_request() { + $url = 'https://s.w.org/screenshots/3.9/dashboard.png'; $response = wp_remote_get( $url ); @@ -52,14 +60,14 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $this->assertInternalType( 'array', $response ); // Should return the same headers as a HEAD request. - $this->assertSame( 'image/jpeg', $headers['content-type'] ); - $this->assertSame( '40148', $headers['content-length'] ); + $this->assertSame( 'image/png', $headers['Content-Type'] ); + $this->assertSame( '153204', $headers['Content-Length'] ); $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } function test_get_redirect() { - // This will redirect to asdftestblog1.files.wordpress.com. - $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; + // This will redirect to wordpress.org. + $url = 'https://wp.org/screenshots/3.9/dashboard.png'; $response = wp_remote_get( $url ); @@ -68,14 +76,14 @@ class Tests_HTTP_Functions extends WP_UnitTestCase { $headers = wp_remote_retrieve_headers( $response ); // Should return the same headers as a HEAD request. - $this->assertSame( 'image/jpeg', $headers['content-type'] ); - $this->assertSame( '40148', $headers['content-length'] ); + $this->assertSame( 'image/png', $headers['Content-Type'] ); + $this->assertSame( '153204', $headers['Content-Length'] ); $this->assertSame( 200, wp_remote_retrieve_response_code( $response ) ); } function test_get_redirect_limit_exceeded() { - // This will redirect to asdftestblog1.files.wordpress.com. - $url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg'; + // This will redirect to wordpress.org. + $url = 'https://wp.org/screenshots/3.9/dashboard.png'; // Pretend we've already redirected 5 times. $response = wp_remote_get( $url, array( 'redirection' => -1 ) ); diff --git a/tests/phpunit/tests/image/functions.php b/tests/phpunit/tests/image/functions.php index 1694c1e7f1..4b025b6140 100644 --- a/tests/phpunit/tests/image/functions.php +++ b/tests/phpunit/tests/image/functions.php @@ -368,7 +368,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { */ public function test_wp_crop_image_url() { $file = wp_crop_image( - 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg', + 'https://s.w.org/screenshots/3.9/dashboard.png', 0, 0, 100, @@ -376,7 +376,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { 100, 100, false, - DIR_TESTDATA . '/images/' . __FUNCTION__ . '.jpg' + DIR_TESTDATA . '/images/' . __FUNCTION__ . '.png' ); if ( is_wp_error( $file ) && $file->get_error_code() === 'invalid_image' ) { @@ -411,7 +411,7 @@ class Tests_Image_Functions extends WP_UnitTestCase { */ public function test_wp_crop_image_url_not_exist() { $file = wp_crop_image( - 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg', + 'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg', 0, 0, 100,