Skip to content

Commit

Permalink
Tests: Increase test coverage for WP_Theme_JSON_Resolver.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
SergeyBiryukov authored and = committed Nov 4, 2022
1 parent 896ba18 commit 999f3a3
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/phpunit/tests/theme/wpThemeJsonResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -693,4 +693,27 @@ function test_get_user_data_from_wp_global_styles_filter_state() {
$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.' );
}
}

0 comments on commit 999f3a3

Please sign in to comment.