From 313ebd3162258104c44a8710a07f02846eb1f220 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 18 Oct 2022 13:19:38 +0000 Subject: [PATCH] Tests: Increase test coverage for `WP_Theme_JSON_Resolver`. This commit adds a unit test to check that `WP_Theme_JSON_Resolver::get_theme_data()` returns a `WP_Theme_JSON` object, and that an `add_theme_support()` call overrides the settings from `theme.json`. Follow-up to [54443], [54493]. Props cbravobernal. Fixes #56835. git-svn-id: https://develop.svn.wordpress.org/trunk@54630 602fd350-edb4-49c9-b593-d223f7449a82 --- .../tests/theme/wpThemeJsonResolver.php | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/phpunit/tests/theme/wpThemeJsonResolver.php b/tests/phpunit/tests/theme/wpThemeJsonResolver.php index 5174b04a9f..9e8068c11f 100644 --- a/tests/phpunit/tests/theme/wpThemeJsonResolver.php +++ b/tests/phpunit/tests/theme/wpThemeJsonResolver.php @@ -693,4 +693,27 @@ class Tests_Theme_wpThemeJsonResolver extends WP_UnitTestCase { $this->assertIsArray( $post2 ); $this->assertSameSets( array(), $post2 ); } + + /** + * @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, 'Theme data should be an instance of WP_Theme_JSON.' ); + + // Test that wp_theme_json_data_theme filter has been called. + $this->assertGreaterThan( 0, did_filter( 'wp_theme_json_data_default' ), 'The filter "theme_json_default" should fire.' ); + + // Test that data from theme.json is backfilled from existing theme supports. + $previous_settings = $theme_data->get_settings(); + $previous_line_height = $previous_settings['typography']['lineHeight']; + $this->assertFalse( $previous_line_height, 'lineHeight setting from theme.json should be false.' ); + 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, 'lineHeight setting after add_theme_support() should be true.' ); + } }