Make WordPress Core


Ignore:
Timestamp:
01/06/2018 07:28:44 PM (7 years ago)
Author:
rachelbaker
Message:

EST API: Adjust unit testes to expect a 401 status code in error responses from permission callbacks when user is not authenticated.

Missed in [42421].

Merges [42423] to the 4.9 branch.
Fixes #42828.

Location:
branches/4.9
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.9

  • branches/4.9/tests/phpunit/tests/rest-api/rest-taxonomies-controller.php

    r41176 r42427  
    1111 */
    1212class WP_Test_REST_Taxonomies_Controller extends WP_Test_REST_Controller_Testcase {
     13
     14    protected static $contributor_id;
     15
     16    public static function wpSetUpBeforeClass( $factory ) {
     17        self::$contributor_id = $factory->user->create(
     18            array(
     19                'role' => 'contributor',
     20            )
     21        );
     22    }
     23
     24    public static function wpTearDownAfterClass() {
     25        self::delete_user( self::$contributor_id );
     26    }
    1327
    1428    public function test_register_routes() {
     
    102116    }
    103117
    104     public function test_get_non_public_taxonomy() {
     118    public function test_get_non_public_taxonomy_not_authenticated() {
    105119        register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
    106120
    107121        $request = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' );
     122        $response = $this->server->dispatch( $request );
     123        $this->assertErrorResponse( 'rest_forbidden', $response, 401 );
     124    }
     125
     126        public function test_get_non_public_taxonomy_no_permission() {
     127        wp_set_current_user( self::$contributor_id );
     128        register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
     129
     130        $request  = new WP_REST_Request( 'GET', '/wp/v2/taxonomies/api-private' );
    108131        $response = $this->server->dispatch( $request );
    109132        $this->assertErrorResponse( 'rest_forbidden', $response, 403 );
Note: See TracChangeset for help on using the changeset viewer.