- Timestamp:
- 09/18/2024 05:17:05 AM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/rest-api/rest-global-styles-controller.php
r58466 r59048 20 20 * @var int 21 21 */ 22 protected static $editor_id; 23 24 /** 25 * @var int 26 */ 22 27 protected static $subscriber_id; 28 29 /** 30 * @var int 31 */ 32 protected static $theme_manager_id; 23 33 24 34 /** … … 55 65 ); 56 66 67 self::$editor_id = $factory->user->create( 68 array( 69 'role' => 'editor', 70 ) 71 ); 72 57 73 self::$subscriber_id = $factory->user->create( 58 74 array( … … 60 76 ) 61 77 ); 78 79 self::$theme_manager_id = $factory->user->create( 80 array( 81 'role' => 'subscriber', 82 ) 83 ); 84 85 // Add the 'edit_theme_options' capability to the theme manager (subscriber). 86 $theme_manager_id = get_user_by( 'id', self::$theme_manager_id ); 87 if ( $theme_manager_id instanceof WP_User ) { 88 $theme_manager_id->add_cap( 'edit_theme_options' ); 89 } 62 90 63 91 // This creates the global styles for the current theme. … … 79 107 80 108 /** 81 * 109 * Clean up after our tests run. 82 110 */ 83 111 public static function wpTearDownAfterClass() { 84 112 self::delete_user( self::$admin_id ); 113 self::delete_user( self::$editor_id ); 85 114 self::delete_user( self::$subscriber_id ); 115 self::delete_user( self::$theme_manager_id ); 86 116 } 87 117 … … 265 295 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/tt1-blocks' ); 266 296 $response = rest_get_server()->dispatch( $request ); 267 $this->assertErrorResponse( 'rest_cannot_ manage_global_styles', $response, 401 );297 $this->assertErrorResponse( 'rest_cannot_read_global_styles', $response, 401 ); 268 298 } 269 299 … … 271 301 * @covers WP_REST_Global_Styles_Controller::get_theme_item 272 302 * @ticket 54516 273 */ 274 public function test_get_theme_item_permission_check() { 303 * @ticket 62042 304 */ 305 public function test_get_theme_item_subscriber_permission_check() { 275 306 wp_set_current_user( self::$subscriber_id ); 276 307 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/tt1-blocks' ); 277 308 $response = rest_get_server()->dispatch( $request ); 278 $this->assertErrorResponse( 'rest_cannot_manage_global_styles', $response, 403 ); 309 $this->assertErrorResponse( 'rest_cannot_read_global_styles', $response, 403 ); 310 } 311 312 /** 313 * @covers WP_REST_Global_Styles_Controller::get_theme_item 314 * @ticket 62042 315 */ 316 public function test_get_theme_item_editor_permission_check() { 317 wp_set_current_user( self::$editor_id ); 318 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/tt1-blocks' ); 319 $response = rest_get_server()->dispatch( $request ); 320 // Checks that the response has the expected keys. 321 $data = $response->get_data(); 322 $links = $response->get_links(); 323 $this->assertArrayHasKey( 'settings', $data, 'Data does not have "settings" key' ); 324 $this->assertArrayHasKey( 'styles', $data, 'Data does not have "styles" key' ); 325 $this->assertArrayHasKey( 'self', $links, 'Links do not have a "self" key' ); 326 } 327 328 /** 329 * @covers WP_REST_Global_Styles_Controller_Gutenberg::get_theme_item 330 * @ticket 62042 331 */ 332 public function test_get_theme_item_theme_options_manager_permission_check() { 333 wp_set_current_user( self::$theme_manager_id ); 334 switch_theme( 'emptytheme' ); 335 $request = new WP_REST_Request( 'GET', '/wp/v2/global-styles/themes/emptytheme' ); 336 $response = rest_get_server()->dispatch( $request ); 337 // Checks that the response has the expected keys. 338 $data = $response->get_data(); 339 $links = $response->get_links(); 340 $this->assertArrayHasKey( 'settings', $data, 'Data does not have "settings" key' ); 341 $this->assertArrayHasKey( 'styles', $data, 'Data does not have "styles" key' ); 342 $this->assertArrayHasKey( 'self', $links, 'Links do not have a "self" key' ); 279 343 } 280 344 … … 608 672 * of saving via the API. 609 673 * 610 * @covers WP_REST_Global_Styles_Controller _Gutenberg::update_item674 * @covers WP_REST_Global_Styles_Controller::update_item 611 675 * @ticket 61312 612 676 * @ticket 61451
Note: See TracChangeset
for help on using the changeset viewer.