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 105978 additions and 78184 deletions
@@ -12,16 +12,18 @@
class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
public function test_validate_within_min_max_range_inclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (inclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertTrue( $ret );
@@ -32,17 +34,19 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
}
public function test_validate_within_min_max_range_min_exclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMinimum' => true,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMinimum' => true,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (inclusive)', $ret->get_error_message() );
@@ -57,17 +61,19 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
}
public function test_validate_within_min_max_range_max_exclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMaximum' => true,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMaximum' => true,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (inclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertTrue( $ret );
@@ -82,18 +88,20 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
}
public function test_validate_within_min_max_range_both_exclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMinimum' => true,
'exclusiveMaximum' => true,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'minmaxrange' => array(
'type' => 'integer',
'minimum' => 2,
'maximum' => 10,
'exclusiveMinimum' => true,
'exclusiveMaximum' => true,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'minmaxrange' );
$this->assertEquals( 'minmaxrange must be between 2 (exclusive) and 10 (exclusive)', $ret->get_error_message() );
@@ -108,31 +116,35 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
}
public function test_validate_greater_than_min_inclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'greaterthanmin' => array(
'type' => 'integer',
'minimum' => 2,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'greaterthanmin' => array(
'type' => 'integer',
'minimum' => 2,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than or equal to 2', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
$this->assertTrue( $ret );
}
public function test_validate_greater_than_min_exclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'greaterthanmin' => array(
'type' => 'integer',
'minimum' => 2,
'exclusiveMinimum' => true,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'greaterthanmin' => array(
'type' => 'integer',
'minimum' => 2,
'exclusiveMinimum' => true,
),
),
),
) );
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
)
);
$ret = rest_validate_request_arg( 1, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
$ret = rest_validate_request_arg( 2, $request, 'greaterthanmin' );
$this->assertEquals( 'greaterthanmin must be greater than 2', $ret->get_error_message() );
@@ -141,31 +153,35 @@ class WP_Test_REST_Request_Validation extends WP_Test_REST_TestCase {
}
public function test_validate_less_than_max_inclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'lessthanmax' => array(
'type' => 'integer',
'maximum' => 10,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'lessthanmax' => array(
'type' => 'integer',
'maximum' => 10,
),
),
),
) );
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
)
);
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than or equal to 10', $ret->get_error_message() );
$ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
$this->assertTrue( $ret );
}
public function test_validate_less_than_max_exclusive() {
$request = new WP_REST_Request( 'GET', '/wp/v2/foo', array(
'args' => array(
'lessthanmax' => array(
'type' => 'integer',
'maximum' => 10,
'exclusiveMaximum' => true,
$request = new WP_REST_Request(
'GET', '/wp/v2/foo', array(
'args' => array(
'lessthanmax' => array(
'type' => 'integer',
'maximum' => 10,
'exclusiveMaximum' => true,
),
),
),
) );
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
)
);
$ret = rest_validate_request_arg( 11, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );
$ret = rest_validate_request_arg( 10, $request, 'lessthanmax' );
$this->assertEquals( 'lessthanmax must be less than 10', $ret->get_error_message() );