Changeset 344 in tests
- Timestamp:
- 03/25/2011 12:52:59 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
wp-testcase/test_http.php
r343 r344 3 3 // You can run the test in safe_mode like such: php -d safe_mode=on wp-test.php - you may also need `-d safe_mode_gid=1` to relax the safe_mode checks to allow inclusion of PEAR. 4 4 // The WP_HTTP tests require a class-http.php file of r17550 or later. 5 class WPHTTP extends WPTestCase {5 class _WPHTTP extends WPTestCase { 6 6 var $redirection_script = 'http://tools.dd32.id.au/redirect/'; // You can use your own version here, You can find it in wp-testdata/WPHTTP-testcase-redirection-script.php 7 7 8 8 function SetUp() { 9 if ( 'WPHTTP' == get_class($this) ) {10 $this->markTestSkipped('The class WPHTTP must be extended in order to run. See the WPHTTP_exthttp, WPHTTP_curl, WPHTTP_streams & WPHTTP_fsockopen testcases.');11 return;12 }13 9 14 10 if ( is_callable( array('WP_HTTP', '_getTransport') ) ) { … … 67 63 $this->assertEquals(200, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 68 64 } 65 69 66 function test_no_head_redirections() { 70 67 // No redirections on HEAD request: … … 72 69 $this->assertEquals( 302, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 73 70 } 71 74 72 function test_redirect_on_head() { 75 73 $this->knownWPBug(16855); … … 78 76 $this->assertEquals( 200, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 79 77 } 78 80 79 function test_redirections_greater() { 81 80 // 10 > 5 … … 83 82 $this->assertTrue( is_wp_error($res), print_r($res, true) ); 84 83 } 84 85 85 function test_redirections_greater_edgecase() { 86 86 // 6 > 5 (close edgecase) … … 88 88 $this->assertTrue( is_wp_error($res) ); 89 89 } 90 90 91 function test_redirections_less_edgecase() { 91 92 // 4 < 5 (close edgecase) … … 93 94 $this->assertFalse( is_wp_error($res) ); 94 95 } 96 95 97 function test_redirections_zero_redirections_specified() { 96 98 $this->knownWPBug(16855); … … 126 128 $this->assertTrue( isset($headers['test1']) && 'test' == $headers['test1'] ); 127 129 $this->assertTrue( isset($headers['test2']) && '0' === $headers['test2'] ); 128 $this->assertTrue( isset($headers['test3']) && '' === $headers['test3'] ); // cURL (&HTTPExt w/ cURL Wrappers) Note: Will never pass, cURL does not pass headers with an empty value. 130 // cURL/HTTP Extension Note: Will never pass, cURL does not pass headers with an empty value. 131 // Should it be that empty headers with empty values are NOT sent? 132 //$this->assertTrue( isset($headers['test3']) && '' === $headers['test3'] ); 129 133 } 134 135 function test_file_stream() { 136 $url = 'http://unit-tests.svn.wordpress.org/wp-testdata/images/2004-07-22-DSC_0007.jpg'; // we'll test against a file in the unit test data 137 $size = 87348; 138 $res = wp_remote_request( $url, array( 'stream' => true, 'timeout' => 30 ) ); //Auto generate the filename. 139 140 $this->assertEquals( '', $res['body'] ); // The body should be empty. 141 $this->assertEquals( $size, $res['headers']['content-length'] ); // Check the headers are returned (and the size is the same..) 142 $this->assertEquals( $size, filesize($res['filename']) ); // Check that the file is written to disk correctly without any extra characters 143 144 unlink($res['filename']); // Remove the temporary file 145 } 146 147 130 148 } 131 149 132 150 // Stubs to test each transport 133 class WPHTTP_exthttp extends WPHTTP {151 class WPHTTP_exthttp extends _WPHTTP { 134 152 var $transport = 'exthttp'; 135 153 } 136 class WPHTTP_curl extends WPHTTP {154 class WPHTTP_curl extends _WPHTTP { 137 155 var $transport = 'curl'; 138 156 } 139 class WPHTTP_streams extends WPHTTP {157 class WPHTTP_streams extends _WPHTTP { 140 158 var $transport = 'streams'; 141 159 } 142 class WPHTTP_fsockopen extends WPHTTP {160 class WPHTTP_fsockopen extends _WPHTTP { 143 161 var $transport = 'fsockopen'; 144 162 }
Note: See TracChangeset
for help on using the changeset viewer.