From 012ac0d4d8211246a90c2ccfbb350f31b14153e6 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Fri, 14 Oct 2022 20:39:09 +0200 Subject: [PATCH 1/2] Initial tests creation --- tests/phpunit/tests/theme/wpThemeJsonResolver.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 5174b04a9f8b2..1ec5bd1479e4e 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -693,4 +693,14 @@ function test_get_user_data_from_wp_global_styles_filter_state() { $this->assertIsArray( $post2 ); $this->assertSameSets( array(), $post2 ); } + + function test_get_core_data() { + $theme_json = WP_Theme_JSON_Resolver::get_core_data(); + $this->assertIsObject( $theme_json ); + $core_data = $theme_json->get_raw_data(); + $this->assertIsArray( $core_data ); + $this->assertArrayHasKey( 'version', $core_data ); + $this->assertArrayHasKey( 'settings', $core_data ); + $this->assertArrayHasKey( 'styles', $core_data ); + } } From 3a24d087797a2c5f03bc846235ff0be0c928d647 Mon Sep 17 00:00:00 2001 From: Carlos Bravo Date: Sun, 16 Oct 2022 16:50:49 +0200 Subject: [PATCH 2/2] Add tests for get_theme_data() --- .../tests/theme/wpThemeJsonResolver.php | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 1ec5bd1479e4e..d648ba867de86 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -694,13 +694,27 @@ function test_get_user_data_from_wp_global_styles_filter_state() { $this->assertSameSets( array(), $post2 ); } - function test_get_core_data() { - $theme_json = WP_Theme_JSON_Resolver::get_core_data(); - $this->assertIsObject( $theme_json ); - $core_data = $theme_json->get_raw_data(); - $this->assertIsArray( $core_data ); - $this->assertArrayHasKey( 'version', $core_data ); - $this->assertArrayHasKey( 'settings', $core_data ); - $this->assertArrayHasKey( 'styles', $core_data ); + + /** + * @ticket 56835 + * @covers WP_Theme_JSON_Resolver::get_theme_data + */ + function test_get_theme_data_theme_supports_overrides_theme_json() { + // Test that get_theme_data() returns a WP_Theme_JSON object. + $theme_json_resolver = new WP_Theme_JSON_Resolver(); + $theme_data = $theme_json_resolver->get_theme_data(); + $this->assertInstanceOf( 'WP_Theme_JSON', $theme_data ); + + // Test that wp_theme_json_data_theme filter has been called. + $this->assertGreaterThan( 0, did_filter( 'wp_theme_json_data_default' ) ); + + // Test that data from theme.json must be backfilled from existing theme supports. + $previous_settings = $theme_data->get_settings(); + $previous_line_height = $previous_settings['typography']['lineHeight']; + $this->assertFalse( $previous_line_height ); + add_theme_support( 'custom-line-height' ); + $current_settings = $theme_json_resolver->get_theme_data()->get_settings(); + $line_height = $current_settings['typography']['lineHeight']; + $this->assertTrue( $line_height ); } }