mirror of
https://github.com/gosticks/wordpress-develop.git
synced 2026-07-27 04:20:14 +00:00
This ensures that not only the return values match the expected results, but also that their type is the same. Going forward, stricter type checking by using `assertSame()` should generally be preferred to `assertEquals()` where appropriate, to make the tests more reliable. Props johnbillion, jrf, SergeyBiryukov. See #38266. git-svn-id: https://develop.svn.wordpress.org/trunk@48937 602fd350-edb4-49c9-b593-d223f7449a82
81 lines
2.3 KiB
PHP
81 lines
2.3 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @group file
|
|
* @group admin
|
|
*/
|
|
class Tests_Admin_includesFile extends WP_UnitTestCase {
|
|
|
|
/**
|
|
* @ticket 20449
|
|
*/
|
|
function test_get_home_path() {
|
|
$home = get_option( 'home' );
|
|
$siteurl = get_option( 'siteurl' );
|
|
$sfn = $_SERVER['SCRIPT_FILENAME'];
|
|
$this->assertSame( str_replace( '\\', '/', ABSPATH ), get_home_path() );
|
|
|
|
update_option( 'home', 'http://localhost' );
|
|
update_option( 'siteurl', 'http://localhost/wp' );
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = 'D:\root\vhosts\site\httpdocs\wp\wp-admin\options-permalink.php';
|
|
$this->assertSame( 'D:/root/vhosts/site/httpdocs/', get_home_path() );
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = '/Users/foo/public_html/trunk/wp/wp-admin/options-permalink.php';
|
|
$this->assertSame( '/Users/foo/public_html/trunk/', get_home_path() );
|
|
|
|
$_SERVER['SCRIPT_FILENAME'] = 'S:/home/wordpress/trunk/wp/wp-admin/options-permalink.php';
|
|
$this->assertSame( 'S:/home/wordpress/trunk/', get_home_path() );
|
|
|
|
update_option( 'home', $home );
|
|
update_option( 'siteurl', $siteurl );
|
|
$_SERVER['SCRIPT_FILENAME'] = $sfn;
|
|
}
|
|
|
|
/**
|
|
* @ticket 43329
|
|
*/
|
|
public function test_download_url_non_200_response_code() {
|
|
add_filter( 'pre_http_request', array( $this, '_fake_download_url_non_200_response_code' ), 10, 3 );
|
|
|
|
$error = download_url( 'test_download_url_non_200' );
|
|
$this->assertWPError( $error );
|
|
$this->assertSame(
|
|
array(
|
|
'code' => 418,
|
|
'body' => 'This is an unexpected error message from your favorite server.',
|
|
),
|
|
$error->get_error_data()
|
|
);
|
|
|
|
add_filter( 'download_url_error_max_body_size', array( $this, '__return_5' ) );
|
|
|
|
$error = download_url( 'test_download_url_non_200' );
|
|
$this->assertWPError( $error );
|
|
$this->assertSame(
|
|
array(
|
|
'code' => 418,
|
|
'body' => 'This ',
|
|
),
|
|
$error->get_error_data()
|
|
);
|
|
|
|
remove_filter( 'download_url_error_max_body_size', array( $this, '__return_5' ) );
|
|
remove_filter( 'pre_http_request', array( $this, '_fake_download_url_non_200_response_code' ) );
|
|
}
|
|
|
|
public function _fake_download_url_non_200_response_code( $response, $args, $url ) {
|
|
file_put_contents( $args['filename'], 'This is an unexpected error message from your favorite server.' );
|
|
return array(
|
|
'response' => array(
|
|
'code' => 418,
|
|
'message' => "I'm a teapot!",
|
|
),
|
|
);
|
|
}
|
|
|
|
public function __return_5() {
|
|
return 5;
|
|
}
|
|
}
|