Make WordPress Core


Ignore:
Timestamp:
10/18/2022 01:19:38 PM (2 years ago)
Author:
SergeyBiryukov
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/theme/wpThemeJsonResolver.php

    r54501 r54630  
    694694        $this->assertSameSets( array(), $post2 );
    695695    }
     696
     697    /**
     698     * @ticket 56835
     699     * @covers WP_Theme_JSON_Resolver::get_theme_data
     700     */
     701    function test_get_theme_data_theme_supports_overrides_theme_json() {
     702        // Test that get_theme_data() returns a WP_Theme_JSON object.
     703        $theme_json_resolver = new WP_Theme_JSON_Resolver();
     704        $theme_data          = $theme_json_resolver->get_theme_data();
     705        $this->assertInstanceOf( 'WP_Theme_JSON', $theme_data, 'Theme data should be an instance of WP_Theme_JSON.' );
     706
     707        // Test that wp_theme_json_data_theme filter has been called.
     708        $this->assertGreaterThan( 0, did_filter( 'wp_theme_json_data_default' ), 'The filter "theme_json_default" should fire.' );
     709
     710        // Test that data from theme.json is backfilled from existing theme supports.
     711        $previous_settings    = $theme_data->get_settings();
     712        $previous_line_height = $previous_settings['typography']['lineHeight'];
     713        $this->assertFalse( $previous_line_height, 'lineHeight setting from theme.json should be false.' );
     714        add_theme_support( 'custom-line-height' );
     715        $current_settings = $theme_json_resolver->get_theme_data()->get_settings();
     716        $line_height      = $current_settings['typography']['lineHeight'];
     717        $this->assertTrue( $line_height, 'lineHeight setting after add_theme_support() should be true.' );
     718    }
    696719}
Note: See TracChangeset for help on using the changeset viewer.