Make WordPress Core


Ignore:
Timestamp:
11/03/2016 02:17:39 AM (8 years ago)
Author:
rachelbaker
Message:

REST API: Clean-up our validation callbacks and add missing array items properties in our endpoint schemas.

Props joehoyle, jnylen0.
Fixes #38617.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/rest-api/rest-users-controller.php

    r39096 r39105  
    364364    }
    365365
     366    public function test_get_items_invalid_order() {
     367        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     368        $request->set_param( 'order', 'asc,id' );
     369        $response = $this->server->dispatch( $request );
     370        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     371    }
     372
     373    public function test_get_items_invalid_orderby() {
     374        $request = new WP_REST_Request( 'GET', '/wp/v2/users' );
     375        $request->set_param( 'orderby', 'invalid' );
     376        $response = $this->server->dispatch( $request );
     377        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
     378    }
     379
    366380    public function test_get_items_offset() {
    367381        wp_set_current_user( self::$user );
     
    380394        $response = $this->server->dispatch( $request );
    381395        $this->assertCount( 2, $response->get_data() );
     396        // 'offset' invalid value should error
     397        $request->set_param( 'offset', 'moreplease' );
     398        $response = $this->server->dispatch( $request );
     399        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    382400    }
    383401
     
    400418        $this->assertEquals( 2, count( $data ) );
    401419        $this->assertEquals( $id3, $data[0]['id'] );
     420        // Invalid include should fail
     421        $request->set_param( 'include', 'invalid' );
     422        $response = $this->server->dispatch( $request );
     423        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    402424        // No privileges
     425        $request->set_param( 'include', array( $id3, $id1 ) );
    403426        wp_set_current_user( 0 );
    404427        $response = $this->server->dispatch( $request );
     
    422445        $this->assertTrue( in_array( $id1, wp_list_pluck( $data, 'id' ), true ) );
    423446        $this->assertFalse( in_array( $id2, wp_list_pluck( $data, 'id' ), true ) );
     447        // Invalid exlude value should error.
     448        $request->set_param( 'exclude', 'none-of-those-please' );
     449        $response = $this->server->dispatch( $request );
     450        $this->assertErrorResponse( 'rest_invalid_param', $response, 400 );
    424451    }
    425452
Note: See TracChangeset for help on using the changeset viewer.