@@ -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 ) );
0 commit comments