mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2025-10-16 12:05:38 +00:00
wp-tests-config.php can/should reside in the root of a develop checkout. `phpunit` should be run from the root. see #25088. git-svn-id: https://develop.svn.wordpress.org/trunk@25165 602fd350-edb4-49c9-b593-d223f7449a82
79 lines
2.9 KiB
PHP
79 lines
2.9 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group http
|
|
* @group external-http
|
|
*/
|
|
class Tests_HTTP_Functions extends WP_UnitTestCase {
|
|
function test_head_request() {
|
|
// this url give a direct 200 response
|
|
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
|
|
$response = wp_remote_head( $url );
|
|
$headers = wp_remote_retrieve_headers( $response );
|
|
|
|
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
|
|
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
|
|
$this->assertEquals( '40148', $headers['content-length'] );
|
|
$this->assertEquals( '200', wp_remote_retrieve_response_code( $response ) );
|
|
}
|
|
|
|
function test_head_redirect() {
|
|
// this url will 301 redirect
|
|
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
|
$response = wp_remote_head( $url );
|
|
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
|
|
}
|
|
|
|
function test_head_404() {
|
|
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
|
|
$headers = wp_remote_head( $url );
|
|
|
|
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
|
|
$this->assertEquals( '404', wp_remote_retrieve_response_code( $headers ) );
|
|
}
|
|
|
|
function test_get_request() {
|
|
$url = 'http://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
|
|
$file = tempnam('/tmp', 'testfile');
|
|
|
|
$headers = wp_get_http($url, $file);
|
|
|
|
// should return the same headers as a head request
|
|
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
|
|
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
|
|
$this->assertEquals( '40148', $headers['content-length'] );
|
|
$this->assertEquals( '200', $headers['response'] );
|
|
|
|
// make sure the file is ok
|
|
$this->assertEquals( 40148, filesize($file) );
|
|
$this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
|
|
}
|
|
|
|
function test_get_redirect() {
|
|
// this will redirect to asdftestblog1.files.wordpress.com
|
|
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
|
$file = tempnam('/tmp', 'testfile');
|
|
|
|
$headers = wp_get_http($url, $file);
|
|
|
|
// should return the same headers as a head request
|
|
$this->assertInternalType( 'array', $headers, "Reply wasn't array." );
|
|
$this->assertEquals( 'image/jpeg', $headers['content-type'] );
|
|
$this->assertEquals( '40148', $headers['content-length'] );
|
|
$this->assertEquals( '200', $headers['response'] );
|
|
|
|
// make sure the file is ok
|
|
$this->assertEquals( 40148, filesize($file) );
|
|
$this->assertEquals( 'b0371a0fc575fcf77f62cd298571f53b', md5_file($file) );
|
|
}
|
|
|
|
function test_get_redirect_limit_exceeded() {
|
|
// this will redirect to asdftestblog1.files.wordpress.com
|
|
$url = 'http://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
|
$file = tempnam('/tmp', 'testfile');
|
|
// pretend we've already redirected 5 times
|
|
$headers = wp_get_http( $url, $file, 6 );
|
|
$this->assertFalse( $headers );
|
|
}
|
|
}
|