Skip to content

Commit 7cd0ff4

Browse files
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
1 parent 4ac331d commit 7cd0ff4

File tree

3 files changed

+29
-21
lines changed

3 files changed

+29
-21
lines changed

tests/phpunit/tests/functions/wpRemoteFopen.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ public function test_wp_remote_fopen_bad_url() {
2626
*/
2727
public function test_wp_remote_fopen() {
2828
// This URL gives a direct 200 response.
29-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
29+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
3030
$response = wp_remote_fopen( $url );
3131

3232
$this->assertInternalType( 'string', $response );
33-
$this->assertSame( 40148, strlen( $response ) );
33+
$this->assertSame( 153204, strlen( $response ) );
3434
}
3535
}

tests/phpunit/tests/http/functions.php

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
99

1010
function test_head_request() {
1111
// This URL gives a direct 200 response.
12-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
12+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
1313
$response = wp_remote_head( $url );
1414

1515
$this->skipTestOnTimeout( $response );
@@ -18,30 +18,38 @@ function test_head_request() {
1818

1919
$this->assertInternalType( 'array', $response );
2020

21-
$this->assertSame( 'image/jpeg', $headers['content-type'] );
22-
$this->assertSame( '40148', $headers['content-length'] );
21+
$this->assertSame( 'image/png', $headers['Content-Type'] );
22+
$this->assertSame( '153204', $headers['Content-Length'] );
2323
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
2424
}
2525

2626
function test_head_redirect() {
2727
// This URL will 301 redirect.
28-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
28+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
2929
$response = wp_remote_head( $url );
3030

3131
$this->skipTestOnTimeout( $response );
3232
$this->assertSame( 301, wp_remote_retrieve_response_code( $response ) );
3333
}
3434

35-
function test_head_404() {
36-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
35+
/**
36+
* @covers ::wp_remote_head
37+
*/
38+
public function test_head_404() {
39+
$url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
3740
$response = wp_remote_head( $url );
3841

3942
$this->skipTestOnTimeout( $response );
4043
$this->assertSame( 404, wp_remote_retrieve_response_code( $response ) );
4144
}
4245

43-
function test_get_request() {
44-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
46+
/**
47+
* @covers ::wp_remote_get
48+
* @covers ::wp_remote_retrieve_headers
49+
* @covers ::wp_remote_retrieve_response_code
50+
*/
51+
public function test_get_request() {
52+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
4553

4654
$response = wp_remote_get( $url );
4755

@@ -52,14 +60,14 @@ function test_get_request() {
5260
$this->assertInternalType( 'array', $response );
5361

5462
// Should return the same headers as a HEAD request.
55-
$this->assertSame( 'image/jpeg', $headers['content-type'] );
56-
$this->assertSame( '40148', $headers['content-length'] );
63+
$this->assertSame( 'image/png', $headers['Content-Type'] );
64+
$this->assertSame( '153204', $headers['Content-Length'] );
5765
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
5866
}
5967

6068
function test_get_redirect() {
61-
// This will redirect to asdftestblog1.files.wordpress.com.
62-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
69+
// This will redirect to wordpress.org.
70+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
6371

6472
$response = wp_remote_get( $url );
6573

@@ -68,14 +76,14 @@ function test_get_redirect() {
6876
$headers = wp_remote_retrieve_headers( $response );
6977

7078
// Should return the same headers as a HEAD request.
71-
$this->assertSame( 'image/jpeg', $headers['content-type'] );
72-
$this->assertSame( '40148', $headers['content-length'] );
79+
$this->assertSame( 'image/png', $headers['Content-Type'] );
80+
$this->assertSame( '153204', $headers['Content-Length'] );
7381
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
7482
}
7583

7684
function test_get_redirect_limit_exceeded() {
77-
// This will redirect to asdftestblog1.files.wordpress.com.
78-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
85+
// This will redirect to wordpress.org.
86+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
7987

8088
// Pretend we've already redirected 5 times.
8189
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );

tests/phpunit/tests/image/functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,15 +368,15 @@ public function test_wp_crop_image_file() {
368368
*/
369369
public function test_wp_crop_image_url() {
370370
$file = wp_crop_image(
371-
'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
371+
'https://s.w.org/screenshots/3.9/dashboard.png',
372372
0,
373373
0,
374374
100,
375375
100,
376376
100,
377377
100,
378378
false,
379-
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.jpg'
379+
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.png'
380380
);
381381

382382
if ( is_wp_error( $file ) && $file->get_error_code() === 'invalid_image' ) {
@@ -411,7 +411,7 @@ public function test_wp_crop_image_file_not_exist() {
411411
*/
412412
public function test_wp_crop_image_url_not_exist() {
413413
$file = wp_crop_image(
414-
'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
414+
'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
415415
0,
416416
0,
417417
100,

0 commit comments

Comments
 (0)