Skip to content

Commit e1167fa

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.1 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/5.1@58000 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 83c416b commit e1167fa

File tree

2 files changed

+47
-28
lines changed

2 files changed

+47
-28
lines changed

tests/phpunit/tests/http/functions.php

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,12 @@ public function setUp() {
1414
parent::setUp();
1515
}
1616

17-
function test_head_request() {
18-
// this url give a direct 200 response
19-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
17+
/**
18+
* @covers ::wp_remote_head
19+
*/
20+
public function test_head_request() {
21+
// This URL gives a direct 200 response.
22+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
2023
$response = wp_remote_head( $url );
2124

2225
$this->skipTestOnTimeout( $response );
@@ -25,30 +28,38 @@ function test_head_request() {
2528

2629
$this->assertInternalType( 'array', $response );
2730

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 ) );
31+
$this->assertSame( 'image/png', $headers['Content-Type'] );
32+
$this->assertSame( '153204', $headers['Content-Length'] );
33+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
3134
}
3235

3336
function test_head_redirect() {
3437
// this url will 301 redirect
35-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
38+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
3639
$response = wp_remote_head( $url );
3740

3841
$this->skipTestOnTimeout( $response );
3942
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
4043
}
4144

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

4652
$this->skipTestOnTimeout( $response );
4753
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
4854
}
4955

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

5364
$response = wp_remote_get( $url );
5465

@@ -58,31 +69,39 @@ function test_get_request() {
5869

5970
$this->assertInternalType( 'array', $response );
6071

61-
// 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 ) );
72+
// Should return the same headers as a HEAD request.
73+
$this->assertSame( 'image/png', $headers['Content-Type'] );
74+
$this->assertSame( '153204', $headers['Content-Length'] );
75+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
6576
}
6677

67-
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';
78+
/**
79+
* @covers ::wp_remote_get
80+
* @covers ::wp_remote_retrieve_headers
81+
* @covers ::wp_remote_retrieve_response_code
82+
*/
83+
public function test_get_redirect() {
84+
// This will redirect to wordpress.org.
85+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
7086

7187
$response = wp_remote_get( $url );
7288

7389
$this->skipTestOnTimeout( $response );
7490

7591
$headers = wp_remote_retrieve_headers( $response );
7692

77-
// 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 ) );
93+
// Should return the same headers as a HEAD request.
94+
$this->assertSame( 'image/png', $headers['Content-Type'] );
95+
$this->assertSame( '153204', $headers['Content-Length'] );
96+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
8197
}
8298

83-
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';
99+
/**
100+
* @covers ::wp_remote_get
101+
*/
102+
public function test_get_redirect_limit_exceeded() {
103+
// This will redirect to wordpress.org.
104+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
86105

87106
// pretend we've already redirected 5 times
88107
$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
$this->assertNotWPError( $file );
349349
$this->assertFileExists( $file );
@@ -374,7 +374,7 @@ public function test_wp_crop_image_url_not_exist() {
374374
}
375375

376376
$file = wp_crop_image(
377-
'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
377+
'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
378378
0,
379379
0,
380380
100,

0 commit comments

Comments
 (0)