wordpress-develop/tests/phpunit/tests/admin/includesFile.php
Gary Pendergast a75d153eee Coding Standards: Upgrade WPCS to 1.0.0
WPCS 1.0.0 includes a bunch of new auto-fixers, which drops the number of coding standards issues across WordPress significantly. Prior to running the auto-fixers, there were 15,312 issues detected. With this commit, we now drop to 4,769 issues.

This change includes three notable additions:
- Multiline function calls must now put each parameter on a new line.
- Auto-formatting files is now part of the `grunt precommit` script. 
- Auto-fixable coding standards issues will now cause Travis failures.

Fixes #44600.



git-svn-id: https://develop.svn.wordpress.org/trunk@43571 602fd350-edb4-49c9-b593-d223f7449a82
2018-08-17 01:50:26 +00:00

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->assertEquals( 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->assertEquals( 'D:/root/vhosts/site/httpdocs/', get_home_path() );
$_SERVER['SCRIPT_FILENAME'] = '/Users/foo/public_html/trunk/wp/wp-admin/options-permalink.php';
$this->assertEquals( '/Users/foo/public_html/trunk/', get_home_path() );
$_SERVER['SCRIPT_FILENAME'] = 'S:/home/wordpress/trunk/wp/wp-admin/options-permalink.php';
$this->assertEquals( '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->assertEquals(
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->assertEquals(
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;
}
}