Changeset 55192 for trunk/tests/phpunit/tests/theme/wpThemeJson.php
- Timestamp:
- 02/02/2023 06:50:54 PM (22 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/theme/wpThemeJson.php
r55176 r55192 14 14 */ 15 15 class Tests_Theme_wpThemeJson extends WP_UnitTestCase { 16 17 /** 18 * Administrator ID. 19 * 20 * @var int 21 */ 22 private static $administrator_id; 23 24 /** 25 * User ID. 26 * 27 * @var int 28 */ 29 private static $user_id; 30 31 public static function set_up_before_class() { 32 parent::set_up_before_class(); 33 34 static::$administrator_id = self::factory()->user->create( 35 array( 36 'role' => 'administrator', 37 ) 38 ); 39 40 if ( is_multisite() ) { 41 grant_super_admin( self::$administrator_id ); 42 } 43 44 static::$user_id = self::factory()->user->create(); 45 } 16 46 17 47 /** … … 4506 4536 $this->assertSame( $expected_styles, $theme_json->get_stylesheet() ); 4507 4537 } 4538 4539 /** 4540 * @ticket 57536 4541 */ 4542 public function test_get_custom_css_handles_global_custom_css() { 4543 $theme_json = new WP_Theme_JSON( 4544 array( 4545 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4546 'styles' => array( 4547 'css' => 'body { color:purple; }', 4548 ), 4549 ) 4550 ); 4551 $custom_css = 'body { color:purple; }'; 4552 $this->assertSame( $custom_css, $theme_json->get_custom_css() ); 4553 } 4554 4555 /** 4556 * Tests that custom CSS is kept for users with correct capabilities and removed for others. 4557 * 4558 * @ticket 57536 4559 * 4560 * @dataProvider data_custom_css_for_user_caps 4561 * 4562 * @param string $user_property The property name for current user. 4563 * @param array $expected Expected results. 4564 */ 4565 public function test_custom_css_for_user_caps( $user_property, array $expected ) { 4566 wp_set_current_user( static::${$user_property} ); 4567 4568 $actual = WP_Theme_JSON::remove_insecure_properties( 4569 array( 4570 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4571 'styles' => array( 4572 'css' => 'body { color:purple; }', 4573 'blocks' => array( 4574 'core/separator' => array( 4575 'color' => array( 4576 'background' => 'blue', 4577 ), 4578 ), 4579 ), 4580 ), 4581 ) 4582 ); 4583 4584 $this->assertSameSetsWithIndex( $expected, $actual ); 4585 } 4586 4587 /** 4588 * Data provider. 4589 * 4590 * @return array[] 4591 */ 4592 public function data_custom_css_for_user_caps() { 4593 return array( 4594 'allows custom css for users with caps' => array( 4595 'user_property' => 'administrator_id', 4596 'expected' => array( 4597 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4598 'styles' => array( 4599 'css' => 'body { color:purple; }', 4600 'blocks' => array( 4601 'core/separator' => array( 4602 'color' => array( 4603 'background' => 'blue', 4604 ), 4605 ), 4606 ), 4607 ), 4608 ), 4609 ), 4610 'removes custom css for users without caps' => array( 4611 'user_property' => 'user_id', 4612 'expected' => array( 4613 'version' => WP_Theme_JSON::LATEST_SCHEMA, 4614 'styles' => array( 4615 'blocks' => array( 4616 'core/separator' => array( 4617 'color' => array( 4618 'background' => 'blue', 4619 ), 4620 ), 4621 ), 4622 ), 4623 ), 4624 ), 4625 ); 4626 } 4508 4627 }
Note: See TracChangeset
for help on using the changeset viewer.