Make WordPress Core


Ignore:
Timestamp:
01/01/2018 02:30:39 AM (7 years ago)
Author:
rachelbaker
Message:

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

Missed in [42421].

Fixes #42828.

File:
1 edited

Legend:

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

    r42343 r42423  
    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() {
     119        register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
     120
     121        $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 );
    105128        register_taxonomy( 'api-private', 'post', array( 'public' => false ) );
    106129
Note: See TracChangeset for help on using the changeset viewer.