Make WordPress Core


Ignore:
Timestamp:
05/18/2024 11:16:09 PM (18 months ago)
Author:
isabel_brison
Message:

Editor: pass fluid typography theme.json settings to wp_get_typography_font_size_value.

Updates wp_get_typography_font_size_value to accept an array of theme.json settings instead of a boolean derived from global state.

Props ramonopoly, audrasjb.
Fixes #61118.

File:
1 edited

Legend:

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

    r58123 r58171  
    14181418    }
    14191419
     1420    /*
     1421     *  Tests that settings passed to WP_Theme_JSON override merged theme data.
     1422     *
     1423     * @ticket 61118
     1424     */
     1425    public function test_get_stylesheet_generates_fluid_typography_values() {
     1426        register_block_type(
     1427            'test/clamp-me',
     1428            array(
     1429                'api_version' => 3,
     1430            )
     1431        );
     1432        $theme_json = new WP_Theme_JSON(
     1433            array(
     1434                'version'  => WP_Theme_JSON::LATEST_SCHEMA,
     1435                'settings' => array(
     1436                    'typography' => array(
     1437                        'fluid'     => true,
     1438                        'fontSizes' => array(
     1439                            array(
     1440                                'size' => '16px',
     1441                                'slug' => 'pickles',
     1442                                'name' => 'Pickles',
     1443                            ),
     1444                            array(
     1445                                'size' => '22px',
     1446                                'slug' => 'toast',
     1447                                'name' => 'Toast',
     1448                            ),
     1449                        ),
     1450                    ),
     1451                ),
     1452                'styles'   => array(
     1453                    'typography' => array(
     1454                        'fontSize' => '1em',
     1455                    ),
     1456                    'elements'   => array(
     1457                        'h1' => array(
     1458                            'typography' => array(
     1459                                'fontSize' => '100px',
     1460                            ),
     1461                        ),
     1462                    ),
     1463                    'blocks'     => array(
     1464                        'test/clamp-me' => array(
     1465                            'typography' => array(
     1466                                'fontSize' => '48px',
     1467                            ),
     1468                        ),
     1469                    ),
     1470                ),
     1471            ),
     1472            'default'
     1473        );
     1474
     1475        unregister_block_type( 'test/clamp-me' );
     1476
     1477        // Results also include root site blocks styles.
     1478        $this->assertSame(
     1479            'body{--wp--preset--font-size--pickles: clamp(14px, 0.875rem + ((1vw - 3.2px) * 0.156), 16px);--wp--preset--font-size--toast: clamp(14.642px, 0.915rem + ((1vw - 3.2px) * 0.575), 22px);}body { margin: 0; }.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }:where(.is-layout-flex){gap: 0.5em;}:where(.is-layout-grid){gap: 0.5em;}body .is-layout-flow > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-flow > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-flow > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > .alignleft{float: left;margin-inline-start: 0;margin-inline-end: 2em;}body .is-layout-constrained > .alignright{float: right;margin-inline-start: 2em;margin-inline-end: 0;}body .is-layout-constrained > .aligncenter{margin-left: auto !important;margin-right: auto !important;}body .is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)){margin-left: auto !important;margin-right: auto !important;}body .is-layout-flex{display: flex;}body .is-layout-flex{flex-wrap: wrap;align-items: center;}body .is-layout-flex > *{margin: 0;}body .is-layout-grid{display: grid;}body .is-layout-grid > *{margin: 0;}body{font-size: clamp(0.875em, 0.875rem + ((1vw - 0.2em) * 0.156), 1em);}h1{font-size: clamp(50.171px, 3.136rem + ((1vw - 3.2px) * 3.893), 100px);}.wp-block-test-clamp-me{font-size: clamp(27.894px, 1.743rem + ((1vw - 3.2px) * 1.571), 48px);}.has-pickles-font-size{font-size: var(--wp--preset--font-size--pickles) !important;}.has-toast-font-size{font-size: var(--wp--preset--font-size--toast) !important;}',
     1480            $theme_json->get_stylesheet()
     1481        );
     1482    }
     1483
    14201484    public function test_allow_indirect_properties() {
    14211485        $actual = WP_Theme_JSON::remove_insecure_properties(
Note: See TracChangeset for help on using the changeset viewer.