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-settings-controller.php

    r42000 r42427  
    1111 */
    1212class WP_Test_REST_Settings_Controller extends WP_Test_REST_Controller_Testcase {
     13   
    1314    protected static $administrator;
     15    protected static $author;
    1416
    1517    public static function wpSetUpBeforeClass( $factory ) {
     
    1719            'role' => 'administrator',
    1820        ) );
     21
     22        self::$author        = $factory->user->create(
     23            array(
     24                'role' => 'author',
     25            )
     26        );
    1927    }
    2028
    2129    public static function wpTearDownAfterClass() {
    2230        self::delete_user( self::$administrator );
     31        self::delete_user( self::$author );
    2332    }
    2433
     
    4453    }
    4554
    46     public function test_get_item_is_not_public() {
    47         $request = new WP_REST_Request( 'GET', '/wp/v2/settings' );
     55    public function test_get_item_is_not_public_not_authenticated() {
     56        $request = new WP_REST_Request( 'GET', '/wp/v2/settings' );
     57        $response = $this->server->dispatch( $request );
     58        $this->assertEquals( 401, $response->get_status() );
     59    }
     60
     61    public function test_get_item_is_not_public_no_permission() {
     62        wp_set_current_user( self::$author );
     63        $request  = new WP_REST_Request( 'GET', '/wp/v2/settings' );
    4864        $response = $this->server->dispatch( $request );
    4965        $this->assertEquals( 403, $response->get_status() );
Note: See TracChangeset for help on using the changeset viewer.