Skip to content

Commit 66e3bd6

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 4.7 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/4.7@58006 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 9cee648 commit 66e3bd6

File tree

2 files changed

+79
-57
lines changed

2 files changed

+79
-57
lines changed

tests/phpunit/tests/http/functions.php

Lines changed: 76 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -14,78 +14,100 @@ 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';
20-
$response = wp_remote_head( $url );
21-
22-
$this->skipTestOnTimeout( $response );
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';
23+
$response = wp_remote_head( $url );
24+
25+
$this->skipTestOnTimeout( $response );
2326

2427
$headers = wp_remote_retrieve_headers( $response );
25-
28+
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

33-
function test_head_redirect() {
34-
// this url will 301 redirect
35-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
36-
$response = wp_remote_head( $url );
37-
38-
$this->skipTestOnTimeout( $response );
39-
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
40-
}
36+
/**
37+
* @covers ::wp_remote_head
38+
*/
39+
public function test_head_redirect() {
40+
// This URL will 301 redirect.
41+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
42+
$response = wp_remote_head( $url );
43+
44+
$this->skipTestOnTimeout( $response );
45+
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
46+
}
47+
48+
/**
49+
* @covers ::wp_remote_head
50+
*/
51+
public function test_head_404() {
52+
$url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
53+
$response = wp_remote_head( $url );
54+
55+
$this->skipTestOnTimeout( $response );
56+
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
57+
}
58+
59+
/**
60+
* @covers ::wp_remote_get
61+
* @covers ::wp_remote_retrieve_headers
62+
* @covers ::wp_remote_retrieve_response_code
63+
*/
64+
public function test_get_request() {
65+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
66+
67+
$response = wp_remote_get( $url );
4168

42-
function test_head_404() {
43-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
44-
$response = wp_remote_head( $url );
45-
46-
$this->skipTestOnTimeout( $response );
47-
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
48-
}
49-
50-
function test_get_request() {
51-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
52-
53-
$response = wp_remote_get( $url );
54-
5569
$this->skipTestOnTimeout( $response );
5670

5771
$headers = wp_remote_retrieve_headers( $response );
58-
72+
5973
$this->assertInternalType( 'array', $response );
6074

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 ) );
75+
// Should return the same headers as a HEAD request.
76+
$this->assertSame( 'image/png', $headers['Content-Type'] );
77+
$this->assertSame( '153204', $headers['Content-Length'] );
78+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
6579
}
6680

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';
70-
71-
$response = wp_remote_get( $url );
72-
81+
/**
82+
* @covers ::wp_remote_get
83+
* @covers ::wp_remote_retrieve_headers
84+
* @covers ::wp_remote_retrieve_response_code
85+
*/
86+
public function test_get_redirect() {
87+
// This will redirect to wordpress.org.
88+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
89+
90+
$response = wp_remote_get( $url );
91+
7392
$this->skipTestOnTimeout( $response );
74-
75-
$headers = wp_remote_retrieve_headers( $response );
76-
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+
94+
$headers = wp_remote_retrieve_headers( $response );
95+
96+
// Should return the same headers as a HEAD request.
97+
$this->assertSame( 'image/png', $headers['Content-Type'] );
98+
$this->assertSame( '153204', $headers['Content-Length'] );
99+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
81100
}
82101

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

87-
// pretend we've already redirected 5 times
88-
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );
109+
// pretend we've already redirected 5 times
110+
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );
89111

90112
$this->skipTestOnTimeout( $response );
91113
$this->assertWPError( $response );

tests/phpunit/tests/image/functions.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,9 @@ public function test_wp_crop_image_url() {
311311
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
312312
}
313313

314-
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
314+
$file = wp_crop_image( 'https://s.w.org/screenshots/3.9/dashboard.png',
315315
0, 0, 100, 100, 100, 100, false,
316-
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.jpg' );
316+
DIR_TESTDATA . '/images/' . __FUNCTION__ . '.png' );
317317
$this->assertNotInstanceOf( 'WP_Error', $file );
318318
$this->assertFileExists( $file );
319319
$image = wp_get_image_editor( $file );
@@ -335,7 +335,7 @@ public function test_wp_crop_image_url_not_exist() {
335335
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
336336
}
337337

338-
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
338+
$file = wp_crop_image( 'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
339339
0, 0, 100, 100, 100, 100 );
340340
$this->assertInstanceOf( 'WP_Error', $file );
341341
}

0 commit comments

Comments
 (0)