Skip to content

Commit

Permalink
Added permissions test for editor role
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Sep 9, 2024
1 parent 993f59f commit ce2509d
Showing 1 changed file with 29 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ class WP_REST_Global_Styles_Controller_Gutenberg_Test extends WP_Test_REST_Contr
*/
protected static $admin_id;

/**
* @var int
*/
protected static $editor_id;

/**
* @var int
*/
Expand Down Expand Up @@ -44,6 +49,12 @@ public static function wpSetupBeforeClass( $factory ) {
)
);

self::$editor_id = $factory->user->create(
array(
'role' => 'editor',
)
);

self::$subscriber_id = $factory->user->create(
array(
'role' => 'subscriber',
Expand Down Expand Up @@ -197,13 +208,30 @@ public function test_get_theme_item_no_user() {
/**
* @covers WP_REST_Global_Styles_Controller_Gutenberg::get_theme_item
*/
public function test_get_theme_item_permission_check() {
public function test_get_theme_item_subscriber_permission_check() {
wp_set_current_user( self::$subscriber_id );
switch_theme( 'emptytheme' );
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/emptytheme' );
$response = rest_get_server()->dispatch( $request );
$this->assertErrorResponse( 'rest_cannot_manage_global_styles', $response, 403 );
}

/**
* @covers WP_REST_Global_Styles_Controller_Gutenberg::get_theme_item
*/
public function test_get_theme_item_editor_permission_check() {
wp_set_current_user( self::$editor_id );
switch_theme( 'emptytheme' );
$request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/emptytheme' );
$response = rest_get_server()->dispatch( $request );
// Checks that the response has the expected keys.
$data = $response->get_data();
$links = $response->get_links();
$this->assertArrayHasKey( 'settings', $data, 'Data does not have "settings" key' );
$this->assertArrayHasKey( 'styles', $data, 'Data does not have "styles" key' );
$this->assertArrayHasKey( 'self', $links, 'Links do not have a "self" key' );
}

/**
* @covers WP_REST_Global_Styles_Controller_Gutenberg::get_theme_item
*/
Expand Down

0 comments on commit ce2509d

Please sign in to comment.