Skip to content

Commit 54593bc

Browse files
Tests: Move data providers and helpers in Tests_REST_Server for consistency.
This ensures that data providers or helper functions used by a single test are located next to the test, for consistency with the rest of the test suite. Follow-up to [37905], [37943], [45809], [47239], [47260], [47351], [48947], [49252], [49257], [51960], [53110], [56096], [59032]. See #64225. git-svn-id: https://develop.svn.wordpress.org/trunk@62205 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8510818 commit 54593bc

File tree

1 file changed

+74
-74
lines changed

1 file changed

+74
-74
lines changed

tests/phpunit/tests/rest-api/rest-server.php

Lines changed: 74 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,21 @@ public function test_envelope_param( $_embed ) {
151151
$this->assertSame( $headers, $enveloped['headers'] );
152152
}
153153

154+
/**
155+
* Data provider.
156+
*
157+
* @return array
158+
*/
159+
public function data_envelope_params() {
160+
return array(
161+
array( '1' ),
162+
array( 'true' ),
163+
array( false ),
164+
array( 'alternate' ),
165+
array( array( 'alternate' ) ),
166+
);
167+
}
168+
154169
public function test_default_param() {
155170

156171
register_rest_route(
@@ -1721,6 +1736,32 @@ public function test_rest_send_refreshed_nonce_invalid_nonce() {
17211736
$this->assertArrayNotHasKey( 'X-WP-Nonce', $headers );
17221737
}
17231738

1739+
/**
1740+
* Helper to setup a users and auth cookie global for the
1741+
* rest_send_refreshed_nonce related tests.
1742+
*/
1743+
protected function helper_setup_user_for_rest_send_refreshed_nonce_tests() {
1744+
$author = self::factory()->user->create( array( 'role' => 'author' ) );
1745+
wp_set_current_user( $author );
1746+
1747+
global $wp_rest_auth_cookie;
1748+
1749+
$wp_rest_auth_cookie = true;
1750+
}
1751+
1752+
/**
1753+
* Helper to make the request and get the headers for the
1754+
* rest_send_refreshed_nonce related tests.
1755+
*
1756+
* @return array
1757+
*/
1758+
protected function helper_make_request_and_return_headers_for_rest_send_refreshed_nonce_tests() {
1759+
$request = new WP_REST_Request( 'GET', '/', array() );
1760+
$result = rest_get_server()->serve_request( '/' );
1761+
1762+
return rest_get_server()->sent_headers;
1763+
}
1764+
17241765
/**
17251766
* Refreshed nonce should be present in header when a valid nonce is
17261767
* passed for logged in/anonymous user and not present when nonce is not
@@ -1751,6 +1792,23 @@ public function test_rest_send_refreshed_nonce( $has_logged_in_user, $has_nonce
17511792
}
17521793
}
17531794

1795+
/**
1796+
* @return array {
1797+
* @type array {
1798+
* @type bool $has_logged_in_user Are we registering a user for the test.
1799+
* @type bool $has_nonce Is the nonce passed.
1800+
* }
1801+
* }
1802+
*/
1803+
public function data_rest_send_refreshed_nonce() {
1804+
return array(
1805+
array( true, true ),
1806+
array( true, false ),
1807+
array( false, true ),
1808+
array( false, false ),
1809+
);
1810+
}
1811+
17541812
/**
17551813
* Make sure that a sanitization that transforms the argument type will not
17561814
* cause the validation to fail.
@@ -1790,6 +1848,22 @@ public function test_rest_validate_before_sanitization() {
17901848
$this->assertSame( 200, $response->get_status() );
17911849
}
17921850

1851+
public function _validate_as_integer_123( $value, $request, $key ) {
1852+
if ( ! is_int( $value ) ) {
1853+
return new WP_Error( 'some-error', 'This is not valid!' );
1854+
}
1855+
1856+
return true;
1857+
}
1858+
1859+
public function _validate_as_string_foo( $value, $request, $key ) {
1860+
if ( ! is_string( $value ) ) {
1861+
return new WP_Error( 'some-error', 'This is not valid!' );
1862+
}
1863+
1864+
return true;
1865+
}
1866+
17931867
/**
17941868
* @ticket 43691
17951869
*/
@@ -2637,78 +2711,4 @@ public function test_prefers_developer_defined_target_hints() {
26372711
$this->assertArrayHasKey( 'allow', $link['targetHints'] );
26382712
$this->assertSame( array( 'GET', 'PUT' ), $link['targetHints']['allow'] );
26392713
}
2640-
2641-
public function _validate_as_integer_123( $value, $request, $key ) {
2642-
if ( ! is_int( $value ) ) {
2643-
return new WP_Error( 'some-error', 'This is not valid!' );
2644-
}
2645-
2646-
return true;
2647-
}
2648-
2649-
public function _validate_as_string_foo( $value, $request, $key ) {
2650-
if ( ! is_string( $value ) ) {
2651-
return new WP_Error( 'some-error', 'This is not valid!' );
2652-
}
2653-
2654-
return true;
2655-
}
2656-
2657-
/**
2658-
* @return array {
2659-
* @type array {
2660-
* @type bool $has_logged_in_user Are we registering a user for the test.
2661-
* @type bool $has_nonce Is the nonce passed.
2662-
* }
2663-
* }
2664-
*/
2665-
public function data_rest_send_refreshed_nonce() {
2666-
return array(
2667-
array( true, true ),
2668-
array( true, false ),
2669-
array( false, true ),
2670-
array( false, false ),
2671-
);
2672-
}
2673-
2674-
/**
2675-
* Helper to setup a users and auth cookie global for the
2676-
* rest_send_refreshed_nonce related tests.
2677-
*/
2678-
protected function helper_setup_user_for_rest_send_refreshed_nonce_tests() {
2679-
$author = self::factory()->user->create( array( 'role' => 'author' ) );
2680-
wp_set_current_user( $author );
2681-
2682-
global $wp_rest_auth_cookie;
2683-
2684-
$wp_rest_auth_cookie = true;
2685-
}
2686-
2687-
/**
2688-
* Helper to make the request and get the headers for the
2689-
* rest_send_refreshed_nonce related tests.
2690-
*
2691-
* @return array
2692-
*/
2693-
protected function helper_make_request_and_return_headers_for_rest_send_refreshed_nonce_tests() {
2694-
$request = new WP_REST_Request( 'GET', '/', array() );
2695-
$result = rest_get_server()->serve_request( '/' );
2696-
2697-
return rest_get_server()->sent_headers;
2698-
}
2699-
2700-
/**
2701-
* Data provider.
2702-
*
2703-
* @return array
2704-
*/
2705-
public function data_envelope_params() {
2706-
return array(
2707-
array( '1' ),
2708-
array( 'true' ),
2709-
array( false ),
2710-
array( 'alternate' ),
2711-
array( array( 'alternate' ) ),
2712-
);
2713-
}
27142714
}

0 commit comments

Comments
 (0)