Code is Poetry.

WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.



git-svn-id: https://develop.svn.wordpress.org/trunk@42343 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Gary Pendergast
2017-11-30 23:09:33 +00:00
parent ec6a089f98
commit 8f95800d52
1103 changed files with 105981 additions and 78187 deletions

View File

@@ -18,8 +18,8 @@ class Tests_Basic extends WP_UnitTestCase {
}
function test_package_json() {
$package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
$package_json = json_decode( $package_json, true );
$package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
$package_json = json_decode( $package_json, true );
list( $version ) = explode( '-', $GLOBALS['wp_version'] );
// package.json uses x.y.z, so fill cleaned $wp_version for .0 releases
if ( 1 == substr_count( $version, '.' ) ) {
@@ -37,35 +37,40 @@ class Tests_Basic extends WP_UnitTestCase {
$this->assertArrayHasKey( 'node', $package_json['engines'] );
$node = $package_json['engines']['node'];
$this->assertRegExp( '~^=?\d+\.\d+\.\d+$~', $node, "package.json's node version cannot be a range." );
}
}
// two tests for a lame bug in PHPUnit that broke the $GLOBALS reference
function test_globals() {
global $test_foo;
$test_foo = array('foo', 'bar', 'baz');
$test_foo = array( 'foo', 'bar', 'baz' );
function test_globals_foo() {
unset($GLOBALS['test_foo'][1]);
unset( $GLOBALS['test_foo'][1] );
}
test_globals_foo();
$this->assertEquals($test_foo, array(0=>'foo', 2=>'baz'));
$this->assertEquals($test_foo, $GLOBALS['test_foo']);
$this->assertEquals(
$test_foo, array(
0 => 'foo',
2 => 'baz',
)
);
$this->assertEquals( $test_foo, $GLOBALS['test_foo'] );
}
function test_globals_bar() {
global $test_bar;
$test_bar = array('a', 'b', 'c');
$this->assertEquals($test_bar, $GLOBALS['test_bar']);
$test_bar = array( 'a', 'b', 'c' );
$this->assertEquals( $test_bar, $GLOBALS['test_bar'] );
}
// test some helper utility functions
function test_strip_ws() {
$this->assertEquals('', strip_ws(''));
$this->assertEquals('foo', strip_ws('foo'));
$this->assertEquals('', strip_ws("\r\n\t \n\r\t"));
$this->assertEquals( '', strip_ws( '' ) );
$this->assertEquals( 'foo', strip_ws( 'foo' ) );
$this->assertEquals( '', strip_ws( "\r\n\t \n\r\t" ) );
$in = "asdf\n";
$in .= "asdf asdf\n";
@@ -83,9 +88,9 @@ class Tests_Basic extends WP_UnitTestCase {
$expected .= "asdf\n";
$expected .= "asdf\n";
$expected .= "foo bar\n";
$expected .= "foo";
$expected .= 'foo';
$this->assertEquals($expected, strip_ws($in));
$this->assertEquals( $expected, strip_ws( $in ) );
}
@@ -103,20 +108,20 @@ EOF;
<p>If a new user is created by WordPress, the password will be set, by default, to "changeme". Quite suggestive, eh? ;)</p>
<ol id="authors"><form action="?import=wordpress&amp;step=2&amp;id=" method="post"><input type="hidden" name="_wpnonce" value="***" /><input type="hidden" name="_wp_http_referer" value="wp-test.php" /><li>Current author: <strong>Alex Shiels</strong><br />Create user <input type="text" value="Alex Shiels" name="user[]" maxlength="30"> <br /> or map to existing<select name="userselect[0]">
EOF;
$this->assertEquals($expected, mask_input_value($in));
$this->assertEquals( $expected, mask_input_value( $in ) );
}
/**
* @ticket 17884
*/
function test_setting_nonexistent_arrays() {
$page = 1;
$page = 1;
$field = 'settings';
$empty_array[$page][$field] = 'foo';
$empty_array[ $page ][ $field ] = 'foo';
// Assertion not strictly needed; we mainly want to show that a notice is not thrown.
unset( $empty_array[$page]['bar']['baz'] );
unset( $empty_array[ $page ]['bar']['baz'] );
$this->assertFalse( isset( $empty_array[ $page ]['bar']['baz'] ) );
}
@@ -166,11 +171,11 @@ EOF;
function _switch_order_helper( $var ) {
$return = 'no match';
switch ( $var ) {
default:
break;
case 1:
$return = 'match';
break;
default:
break;
case 1:
$return = 'match';
break;
}
return $return;