mirror of
git://develop.git.wordpress.org/
synced 2025-01-16 20:38:35 +01:00
Tests: Use an image on WordPress.org CDN in external HTTP tests.
Due to some changes on the WP.com side to compress the requested images on the fly, the exact image size in the response could be different between platforms. This commit aims to make the affected tests more reliable. Follow-up to [139/tests], [31258], [34568], [47142], [57903], [57904], [57924]. Merges [57931] to the 4.4 branch. Props peterwilsoncc, jorbin. See #60865. git-svn-id: https://develop.svn.wordpress.org/branches/4.4@58013 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
0bdabb995e
commit
fdc08e69e1
@ -14,9 +14,12 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
function test_head_request() {
|
||||
// this url give a direct 200 response
|
||||
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
|
||||
/**
|
||||
* @covers ::wp_remote_head
|
||||
*/
|
||||
public function test_head_request() {
|
||||
// This URL gives a direct 200 response.
|
||||
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
|
||||
$response = wp_remote_head( $url );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
@ -24,31 +27,42 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
|
||||
$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 ) );
|
||||
$this->assertSame( 'image/png', $headers['content-type'] );
|
||||
$this->assertSame( '153204', $headers['content-length'] );
|
||||
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
function test_head_redirect() {
|
||||
// this url will 301 redirect
|
||||
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
||||
/**
|
||||
* @covers ::wp_remote_head
|
||||
*/
|
||||
public function test_head_redirect() {
|
||||
// This URL will 301 redirect.
|
||||
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
|
||||
$response = wp_remote_head( $url );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
$this->assertEquals( '301', wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
function test_head_404() {
|
||||
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/awefasdfawef.jpg';
|
||||
$response = wp_remote_head( $url );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
/**
|
||||
* @covers ::wp_remote_head
|
||||
*/
|
||||
public function test_head_404() {
|
||||
$url = 'https://wordpress.org/screenshots/3.9/awefasdfawef.jpg';
|
||||
$response = wp_remote_head( $url );
|
||||
|
||||
$this->skipTestOnTimeout( $response );
|
||||
$this->assertInternalType( 'array', $response, "Reply wasn't array." );
|
||||
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
function test_get_request() {
|
||||
$url = 'https://asdftestblog1.files.wordpress.com/2007/09/2007-06-30-dsc_4700-1.jpg';
|
||||
$this->assertEquals( '404', wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::wp_remote_get
|
||||
* @covers ::wp_remote_retrieve_headers
|
||||
* @covers ::wp_remote_retrieve_response_code
|
||||
*/
|
||||
public function test_get_request() {
|
||||
$url = 'https://s.w.org/screenshots/3.9/dashboard.png';
|
||||
|
||||
$response = wp_remote_get( $url );
|
||||
|
||||
@ -56,16 +70,21 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
|
||||
|
||||
$headers = wp_remote_retrieve_headers( $response );
|
||||
|
||||
// should return the same headers as a head request
|
||||
// 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', wp_remote_retrieve_response_code( $response ) );
|
||||
$this->assertSame( 'image/png', $headers['content-type'] );
|
||||
$this->assertSame( '153204', $headers['content-length'] );
|
||||
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
function test_get_redirect() {
|
||||
// this will redirect to asdftestblog1.files.wordpress.com
|
||||
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
||||
/**
|
||||
* @covers ::wp_remote_get
|
||||
* @covers ::wp_remote_retrieve_headers
|
||||
* @covers ::wp_remote_retrieve_response_code
|
||||
*/
|
||||
public function test_get_redirect() {
|
||||
// This will redirect to wordpress.org.
|
||||
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
|
||||
|
||||
$response = wp_remote_get( $url );
|
||||
|
||||
@ -73,16 +92,19 @@ class Tests_HTTP_Functions extends WP_UnitTestCase {
|
||||
|
||||
$headers = wp_remote_retrieve_headers( $response );
|
||||
|
||||
// should return the same headers as a head request
|
||||
// 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', wp_remote_retrieve_response_code( $response ) );
|
||||
$this->assertSame( 'image/png', $headers['content-type'] );
|
||||
$this->assertSame( '153204', $headers['content-length'] );
|
||||
$this->assertSame( 200, wp_remote_retrieve_response_code( $response ) );
|
||||
}
|
||||
|
||||
function test_get_redirect_limit_exceeded() {
|
||||
// this will redirect to asdftestblog1.files.wordpress.com
|
||||
$url = 'https://asdftestblog1.wordpress.com/files/2007/09/2007-06-30-dsc_4700-1.jpg';
|
||||
/**
|
||||
* @covers ::wp_remote_get
|
||||
*/
|
||||
public function test_get_redirect_limit_exceeded() {
|
||||
// This will redirect to wordpress.org.
|
||||
$url = 'https://wp.org/screenshots/3.9/dashboard.png';
|
||||
|
||||
// pretend we've already redirected 5 times
|
||||
$response = wp_remote_get( $url, array( 'redirection' => -1 ) );
|
||||
|
@ -304,9 +304,9 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url() requires openssl.' );
|
||||
}
|
||||
|
||||
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canola.jpg',
|
||||
$file = wp_crop_image( 'https://s.w.org/screenshots/3.9/dashboard.png',
|
||||
0, 0, 100, 100, 100, 100, false,
|
||||
DIR_TESTDATA . '/images/' . rand_str() . '.jpg' );
|
||||
DIR_TESTDATA . '/images/' . rand_str() . '.png' );
|
||||
$this->assertNotInstanceOf( 'WP_Error', $file );
|
||||
$this->assertFileExists( $file );
|
||||
$image = wp_get_image_editor( $file );
|
||||
@ -328,7 +328,7 @@ class Tests_Image_Functions extends WP_UnitTestCase {
|
||||
$this->markTestSkipped( 'Tests_Image_Functions::test_wp_crop_image_url_not_exist() requires openssl.' );
|
||||
}
|
||||
|
||||
$file = wp_crop_image( 'https://asdftestblog1.files.wordpress.com/2008/04/canoladoesnotexist.jpg',
|
||||
$file = wp_crop_image( 'https://wordpress.org/screenshots/3.9/canoladoesnotexist.jpg',
|
||||
0, 0, 100, 100, 100, 100 );
|
||||
$this->assertInstanceOf( 'WP_Error', $file );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user