Ticket #13841: 13841.unitTest.diff

File 13841.unitTest.diff, 1.7 KB (added by DH-Shredder, 20 months ago)

First pass at Unit Test - Only fails on fsockopen (and fixed by patch on ticket)

  • wp-testcase/test_http.php

     
    44// The WP_HTTP tests require a class-http.php file of r17550 or later. 
    55class _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 
     7        var $timeout_script = 'http://wp-http.dreamhosters.com/timeout/WPHTTP-testcase-timeout-script.php'; // You can use your own version here, You can find it in wp-testdata/WPHTTP-testcase-timeout-script.php 
    78 
    89        function SetUp() { 
    910 
     
    143144 
    144145                unlink($res['filename']); // Remove the temporary file 
    145146        } 
     147 
     148        function test_timeout() { 
     149                $this->knownWPBug(13841); 
     150                // Test that transports timeout within the amount of seconds specified. 
     151                $res = wp_remote_request( $this->timeout_script, array( 'timeout' => 6 ) ); 
     152 
     153                $this->assertTrue( is_wp_error( $res ), "Transfer timed-out within 6 seconds."); 
     154                $this->assertTrue( $res->get_error_code() == "http_request_failed", "Transfer failed with http_request_failed code." ); 
     155        } 
    146156} 
    147157 
    148158// Stubs to test each transport 
  • wp-testdata/WPHTTP-testcase-timeout-script.php

     
     1<?php 
     2 
     3$seconds_to_timeout = 10; 
     4 
     5for ($i = 0; $i < $seconds_to_timeout; $i++ ) { 
     6        sleep( 1 ); 
     7} 
     8 
     9die("Request did not time out within $seconds_to_timeout seconds."); 
     10 
     11?> 
     12 No newline at end of file