Skip to content

Commit 67ad1c6

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.5 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/5.5@57996 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8619fbc commit 67ad1c6

File tree

3 files changed

+33
-25
lines changed

3 files changed

+33
-25
lines changed

tests/phpunit/tests/functions/wpRemoteFopen.php

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

31-
$this->assertInternalType( 'string', $response );
32-
$this->assertEquals( 40148, strlen( $response ) );
31+
$this->assertIsString( $response );
32+
$this->assertSame( 153204, strlen( $response ) );
3333
}
3434
}

tests/phpunit/tests/http/functions.php

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function setUp() {
1616

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

2222
$this->skipTestOnTimeout( $response );
@@ -25,30 +25,38 @@ function test_head_request() {
2525

2626
$this->assertInternalType( 'array', $response );
2727

28-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
29-
$this->assertEquals( '40148', $headers['content-length'] );
30-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
28+
$this->assertSame( 'image/png', $headers['Content-Type'] );
29+
$this->assertSame( '153204', $headers['Content-Length'] );
30+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
3131
}
3232

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

3838
$this->skipTestOnTimeout( $response );
3939
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
4040
}
4141

42-
function test_head_404() {
43-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
42+
/**
43+
* @covers ::wp_remote_head
44+
*/
45+
public function test_head_404() {
46+
$url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
4447
$response = wp_remote_head( $url );
4548

4649
$this->skipTestOnTimeout( $response );
4750
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
4851
}
4952

50-
function test_get_request() {
51-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
53+
/**
54+
* @covers ::wp_remote_get
55+
* @covers ::wp_remote_retrieve_headers
56+
* @covers ::wp_remote_retrieve_response_code
57+
*/
58+
public function test_get_request() {
59+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
5260

5361
$response = wp_remote_get( $url );
5462

@@ -59,14 +67,14 @@ function test_get_request() {
5967
$this->assertInternalType( 'array', $response );
6068

6169
// Should return the same headers as a HEAD request.
62-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
63-
$this->assertEquals( '40148', $headers['content-length'] );
64-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
70+
$this->assertSame( 'image/png', $headers['Content-Type'] );
71+
$this->assertSame( '153204', $headers['Content-Length'] );
72+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
6573
}
6674

6775
function test_get_redirect() {
68-
// This will redirect to asdftestblog1.files.wordpress.com.
69-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
76+
// This will redirect to wordpress.org.
77+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
7078

7179
$response = wp_remote_get( $url );
7280

@@ -75,14 +83,14 @@ function test_get_redirect() {
7583
$headers = wp_remote_retrieve_headers( $response );
7684

7785
// Should return the same headers as a HEAD request.
78-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
79-
$this->assertEquals( '40148', $headers['content-length'] );
80-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
86+
$this->assertSame( 'image/png', $headers['Content-Type'] );
87+
$this->assertSame( '153204', $headers['Content-Length'] );
88+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
8189
}
8290

8391
function test_get_redirect_limit_exceeded() {
84-
// This will redirect to asdftestblog1.files.wordpress.com.
85-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
92+
// This will redirect to wordpress.org.
93+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
8694

8795
// Pretend we've already redirected 5 times.
8896
$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
@@ -335,15 +335,15 @@ public function test_wp_crop_image_url() {
335335
}
336336

337337
$file = wp_crop_image(
338-
'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
338+
'https://s.w.org/screenshots/3.9/dashboard.png',
339339
0,
340340
0,
341341
100,
342342
100,
343343
100,
344344
100,
345345
false,
346-
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.jpg'
346+
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.png'
347347
);
348348

349349
if ( is_wp_error( $file ) && $file->get_error_code() === 'invalid_image' ) {
@@ -379,7 +379,7 @@ public function test_wp_crop_image_url_not_exist() {
379379
}
380380

381381
$file = wp_crop_image(
382-
'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
382+
'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
383383
0,
384384
0,
385385
100,

0 commit comments

Comments
 (0)