Skip to content

Commit 0bbc713

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.1 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/4.1@58016 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 7bd333d commit 0bbc713

File tree

2 files changed

+80
-58
lines changed

2 files changed

+80
-58
lines changed

tests/phpunit/tests/http/functions.php

Lines changed: 77 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -13,78 +13,100 @@ public function setUp() {
1313
parent::setUp();
1414
}
1515

16-
function test_head_request() {
17-
// this url give a direct 200 response
18-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
19-
$response = wp_remote_head( $url );
20-
21-
$this->skipTestOnTimeout( $response );
22-
23-
$headers = wp_remote_retrieve_headers( $response );
24-
16+
/**
17+
* @covers ::wp_remote_head
18+
*/
19+
public function test_head_request() {
20+
// This URL gives a direct 200 response.
21+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
22+
$response = wp_remote_head( $url );
23+
24+
$this->skipTestOnTimeout( $response );
25+
26+
$headers = wp_remote_retrieve_headers( $response );
27+
2528
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
26-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
27-
$this->assertEquals( '40148', $headers['content-length'] );
28-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
29-
}
30-
31-
function test_head_redirect() {
32-
// this url will 301 redirect
33-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
34-
$response = wp_remote_head( $url );
35-
36-
$this->skipTestOnTimeout( $response );
37-
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
29+
$this->assertSame( 'image/png', $headers['content-type'] );
30+
$this->assertSame( '153204', $headers['content-length'] );
31+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
3832
}
3933

40-
function test_head_404() {
41-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
34+
/**
35+
* @covers ::wp_remote_head
36+
*/
37+
public function test_head_redirect() {
38+
// This URL will 301 redirect.
39+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
40+
$response = wp_remote_head( $url );
41+
42+
$this->skipTestOnTimeout( $response );
43+
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
44+
}
45+
46+
/**
47+
* @covers ::wp_remote_head
48+
*/
49+
public function test_head_404() {
50+
$url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
4251
$response = wp_remote_head( $url );
4352

4453
$this->skipTestOnTimeout( $response );
45-
$this->assertInternalType( 'array', $response, "Reply wasn't array." );
54+
$this->assertInternalType( 'array', $response, "Reply wasn't array." );
4655
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
4756
}
4857

49-
function test_get_request() {
50-
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
51-
52-
$response = wp_remote_get( $url );
53-
54-
$this->skipTestOnTimeout( $response );
55-
56-
$headers = wp_remote_retrieve_headers( $response );
57-
58-
// should return the same headers as a head request
58+
/**
59+
* @covers ::wp_remote_get
60+
* @covers ::wp_remote_retrieve_headers
61+
* @covers ::wp_remote_retrieve_response_code
62+
*/
63+
public function test_get_request() {
64+
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
65+
66+
$response = wp_remote_get( $url );
67+
68+
$this->skipTestOnTimeout( $response );
69+
70+
$headers = wp_remote_retrieve_headers( $response );
71+
72+
// Should return the same headers as a HEAD request.
5973
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
60-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
61-
$this->assertEquals( '40148', $headers['content-length'] );
62-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
74+
$this->assertSame( 'image/png', $headers['content-type'] );
75+
$this->assertSame( '153204', $headers['content-length'] );
76+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
6377
}
6478

65-
function test_get_redirect() {
66-
// this will redirect to asdftestblog1.files.wordpress.com
67-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
68-
69-
$response = wp_remote_get( $url );
70-
79+
/**
80+
* @covers ::wp_remote_get
81+
* @covers ::wp_remote_retrieve_headers
82+
* @covers ::wp_remote_retrieve_response_code
83+
*/
84+
public function test_get_redirect() {
85+
// This will redirect to wordpress.org.
86+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
87+
88+
$response = wp_remote_get( $url );
89+
7190
$this->skipTestOnTimeout( $response );
72-
73-
$headers = wp_remote_retrieve_headers( $response );
74-
75-
// should return the same headers as a head request
91+
92+
$headers = wp_remote_retrieve_headers( $response );
93+
94+
// Should return the same headers as a HEAD request.
7695
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
77-
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
78-
$this->assertEquals( '40148', $headers['content-length'] );
79-
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
96+
$this->assertSame( 'image/png', $headers['content-type'] );
97+
$this->assertSame( '153204', $headers['content-length'] );
98+
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
8099
}
81100

82-
function test_get_redirect_limit_exceeded() {
83-
// this will redirect to asdftestblog1.files.wordpress.com
84-
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
101+
/**
102+
* @covers ::wp_remote_get
103+
*/
104+
public function test_get_redirect_limit_exceeded() {
105+
// This will redirect to wordpress.org.
106+
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
85107

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

89111
$this->skipTestOnTimeout( $response );
90112
$this->assertTrue( is_wp_error( $response ) );

tests/phpunit/tests/image/functions.php

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

299-
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
299+
$file = wp_crop_image( 'https://s.w.org/screenshots/3.9/dashboard.png',
300300
0, 0, 100, 100, 100, 100, false,
301-
DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
301+
DIR_TESTDATA . '/images/' . rand_str() . '.png' );
302302
$this->assertNotInstanceOf( 'WP_Error', $file );
303303
$this->assertFileExists( $file );
304304
$image = wp_get_image_editor( $file );
@@ -320,7 +320,7 @@ public function test_wp_crop_image_url_not_exist() {
320320
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
321321
}
322322

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

0 commit comments

Comments
 (0)