| | 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 | |
| | 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 | |
| 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 | | } |