WordPress.org

Make WordPress Core

Changeset 344 in tests


Ignore:
Timestamp:
03/25/11 00:52:59 (3 years ago)
Author:
dd32
Message:

Mark the WPHTTP baseclass as hidden to prevent it being run when all test cases are run; Add a file streaming testcase.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wp-testcase/test_http.php

    r343 r344  
    33// 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. 
    44// The WP_HTTP tests require a class-http.php file of r17550 or later. 
    5 class WPHTTP extends WPTestCase { 
     5class _WPHTTP extends WPTestCase { 
    66    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 
    77 
    88    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         } 
    139 
    1410        if ( is_callable( array('WP_HTTP', '_getTransport') ) ) { 
     
    6763        $this->assertEquals(200, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 
    6864    } 
     65 
    6966    function test_no_head_redirections() { 
    7067        // No redirections on HEAD request: 
     
    7269        $this->assertEquals( 302, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 
    7370    } 
     71 
    7472    function test_redirect_on_head() { 
    7573        $this->knownWPBug(16855); 
     
    7876        $this->assertEquals( 200, (is_wp_error($res) ? 0 : (int)$res['response']['code']) ); 
    7977    } 
     78 
    8079    function test_redirections_greater() { 
    8180        // 10 > 5 
     
    8382        $this->assertTrue( is_wp_error($res), print_r($res, true) ); 
    8483    } 
     84 
    8585    function test_redirections_greater_edgecase() { 
    8686        // 6 > 5 (close edgecase) 
     
    8888        $this->assertTrue( is_wp_error($res) ); 
    8989    } 
     90 
    9091    function test_redirections_less_edgecase() { 
    9192        // 4 < 5 (close edgecase) 
     
    9394        $this->assertFalse( is_wp_error($res) ); 
    9495    } 
     96 
    9597    function test_redirections_zero_redirections_specified() { 
    9698        $this->knownWPBug(16855); 
     
    126128        $this->assertTrue( isset($headers['test1']) && 'test' == $headers['test1'] ); 
    127129        $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'] ); 
    129133    } 
     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     
    130148} 
    131149 
    132150// Stubs to test each transport 
    133 class WPHTTP_exthttp extends WPHTTP { 
     151class WPHTTP_exthttp extends _WPHTTP { 
    134152    var $transport = 'exthttp'; 
    135153} 
    136 class WPHTTP_curl extends WPHTTP { 
     154class WPHTTP_curl extends _WPHTTP { 
    137155    var $transport = 'curl'; 
    138156} 
    139 class WPHTTP_streams extends WPHTTP { 
     157class WPHTTP_streams extends _WPHTTP { 
    140158    var $transport = 'streams'; 
    141159} 
    142 class WPHTTP_fsockopen extends WPHTTP { 
     160class WPHTTP_fsockopen extends _WPHTTP { 
    143161    var $transport = 'fsockopen'; 
    144162} 
Note: See TracChangeset for help on using the changeset viewer.