<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[54497] trunk: Editor: Merge latest fluid typography bugfixes for 6.1 Release Candidate 1.</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="https://core.trac.wordpress.org/changeset/54497">54497</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"https://core.trac.wordpress.org/changeset/54497","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>davidbaumwald</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2022-10-11 18:42:20 +0000 (Tue, 11 Oct 2022)</dd>
</dl>
<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>Editor: Merge latest fluid typography bugfixes for 6.1 Release Candidate 1.
Merges the following:
* [https://github.com/WordPress/gutenberg/pull/44761 Gutenberg PR 44761] - Fluid Typography: Fix bug in global styles where fluid `clamp()` rules were not calculated for custom values
* [https://github.com/WordPress/gutenberg/pull/44762 Gutenberg PR 44762] - Fluid Typography: Convert server-side block support values
* [https://github.com/WordPress/gutenberg/pull/44764 Gutenberg PR 44764] - Fluid Typography: Convert font size inline style attributes to fluid values
* [https://github.com/WordPress/gutenberg/pull/44807 Gutenberg PR 44807] - Fluid Typography: Covert font size number values to pixels
* [https://github.com/WordPress/gutenberg/pull/44847 Gutenberg PR 44847] - Fluid Typography: ensure font sizes are strings or integers
Follow-up to <a href="https://core.trac.wordpress.org/changeset/54280">[54280]</a>.
Props andrewserong, isabel_brison, ramonopoly.
See <a href="https://core.trac.wordpress.org/ticket/56467">#56467</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesblocksupportstypographyphp">trunk/src/wp-includes/block-supports/typography.php</a></li>
<li><a href="#trunksrcwpincludesclasswpthemejsonphp">trunk/src/wp-includes/class-wp-theme-json.php</a></li>
<li><a href="#trunksrcwpincludesdefaultfiltersphp">trunk/src/wp-includes/default-filters.php</a></li>
<li><a href="#trunktestsphpunittestsblocksupportstypographyphp">trunk/tests/phpunit/tests/block-supports/typography.php</a></li>
<li><a href="#trunktestsphpunitteststhemethemeDirphp">trunk/tests/phpunit/tests/theme/themeDir.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesblocksupportstypographyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/block-supports/typography.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/block-supports/typography.php 2022-10-11 18:13:34 UTC (rev 54496)
+++ trunk/src/wp-includes/block-supports/typography.php 2022-10-11 18:42:20 UTC (rev 54497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -119,7 +119,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $custom_font_size = isset( $block_attributes['style']['typography']['fontSize'] )
</span><span class="cx" style="display: block; padding: 0 10px"> ? $block_attributes['style']['typography']['fontSize']
</span><span class="cx" style="display: block; padding: 0 10px"> : null;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : $custom_font_size;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $typography_block_styles['fontSize'] = $preset_font_size ? $preset_font_size : wp_get_typography_font_size_value(
+ array(
+ 'size' => $custom_font_size,
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $has_font_family_support && ! $should_skip_font_family ) {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -245,28 +249,70 @@
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Renders typography styles/content to the block wrapper.
+ *
+ * @since 6.1.0
+ *
+ * @param string $block_content Rendered block content.
+ * @param array $block Block object.
+ * @return string Filtered block content.
+ */
+function wp_render_typography_support( $block_content, $block ) {
+ if ( ! isset( $block['attrs']['style']['typography']['fontSize'] ) ) {
+ return $block_content;
+ }
+
+ $custom_font_size = $block['attrs']['style']['typography']['fontSize'];
+ $fluid_font_size = wp_get_typography_font_size_value( array( 'size' => $custom_font_size ) );
+
+ /*
+ * Checks that $fluid_font_size does not match $custom_font_size,
+ * which means it's been mutated by the fluid font size functions.
+ */
+ if ( ! empty( $fluid_font_size ) && $fluid_font_size !== $custom_font_size ) {
+ // Replaces the first instance of `font-size:$custom_font_size` with `font-size:$fluid_font_size`.
+ return preg_replace( '/font-size\s*:\s*' . preg_quote( $custom_font_size, '/' ) . '\s*;?/', 'font-size:' . esc_attr( $fluid_font_size ) . ';', $block_content, 1 );
+ }
+
+ return $block_content;
+}
+
+/**
</ins><span class="cx" style="display: block; padding: 0 10px"> * Checks a string for a unit and value and returns an array
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * consisting of `'value'` and `'unit'`, e.g., [ '42', 'rem' ].
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * consisting of `'value'` and `'unit'`, e.g. array( '42', 'rem' ).
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.1.0
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @access private
</del><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param string $raw_value Raw size value from theme.json.
- * @param array $options {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string|int|float $raw_value Raw size value from theme.json.
+ * @param array $options {
</ins><span class="cx" style="display: block; padding: 0 10px"> * Optional. An associative array of options. Default is empty array.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $coerce_to Coerce the value to rem or px. Default `'rem'`.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $root_size_value Value of root font size for rem|em <-> px conversion. Default `16`.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string[] $acceptable_units An array of font size units. Default `[ 'rem', 'px', 'em' ]`;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string[] $acceptable_units An array of font size units. Default `array( 'rem', 'px', 'em' )`;
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array|null An array consisting of `'value'` and `'unit'` properties on success.
</span><span class="cx" style="display: block; padding: 0 10px"> * `null` on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_typography_value_and_unit( $raw_value, $options = array() ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! is_string( $raw_value ) && ! is_int( $raw_value ) && ! is_float( $raw_value ) ) {
+ _doing_it_wrong(
+ __FUNCTION__,
+ __( 'Raw size value must be a string, integer, or float.' ),
+ '6.1.0'
+ );
+ return null;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $raw_value ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return null;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Converts numbers to pixel values by default.
+ if ( is_numeric( $raw_value ) ) {
+ $raw_value = $raw_value . 'px';
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $defaults = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'coerce_to' => '',
</span><span class="cx" style="display: block; padding: 0 10px"> 'root_size_value' => 16,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -288,8 +334,10 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $value = $matches[1];
</span><span class="cx" style="display: block; padding: 0 10px"> $unit = $matches[2];
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // Default browser font size. Later, possibly could inject some JS to
- // compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /*
+ * Default browser font size. Later, possibly could inject some JS to
+ * compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
+ */
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( 'px' === $options['coerce_to'] && ( 'em' === $unit || 'rem' === $unit ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $value = $value * $options['root_size_value'];
</span><span class="cx" style="display: block; padding: 0 10px"> $unit = $options['coerce_to'];
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -323,7 +371,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @type string $minimum_font_size Minimum font size for any clamp() calculation.
</span><span class="cx" style="display: block; padding: 0 10px"> * @type int $scale_factor A scale factor to determine how fast a font scales within boundaries.
</span><span class="cx" style="display: block; padding: 0 10px"> * }
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @return string|null A font-size value using clamp() on success. Else, null.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @return string|null A font-size value using clamp() on success, otherwise null.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_computed_fluid_typography_value( $args = array() ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $maximum_viewport_width_raw = isset( $args['maximum_viewport_width'] ) ? $args['maximum_viewport_width'] : null;
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -395,15 +443,27 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param array $preset {
</span><span class="cx" style="display: block; padding: 0 10px"> * Required. fontSizes preset value as seen in theme.json.
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @type string $name Name of the font size preset.
- * @type string $slug Kebab-case unique identifier for the font size preset.
- * @type string $size CSS font-size value, including units where applicable.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $name Name of the font size preset.
+ * @type string $slug Kebab-case, unique identifier for the font size preset.
+ * @type string|int|float $size CSS font-size value, including units if applicable.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * Default is `false`.
- * @return string Font-size value.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Default is false.
+ * @return string|null Font-size value or null if a size is not passed in $preset.
</ins><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function wp_get_typography_font_size_value( $preset, $should_use_fluid_typography = false ) {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( ! isset( $preset['size'] ) ) {
+ return null;
+ }
+
+ /*
+ * Catches empty values and 0/'0'.
+ * Fluid calculations cannot be performed on 0.
+ */
+ if ( empty( $preset['size'] ) ) {
+ return $preset['size'];
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // Checks if fluid font sizes are activated.
</span><span class="cx" style="display: block; padding: 0 10px"> $typography_settings = wp_get_global_settings( array( 'typography' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> $should_use_fluid_typography = isset( $typography_settings['fluid'] ) && true === $typography_settings['fluid'] ? true : $should_use_fluid_typography;
</span></span></pre></div>
<a id="trunksrcwpincludesclasswpthemejsonphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/class-wp-theme-json.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/class-wp-theme-json.php 2022-10-11 18:13:34 UTC (rev 54496)
+++ trunk/src/wp-includes/class-wp-theme-json.php 2022-10-11 18:42:20 UTC (rev 54497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -1675,6 +1675,18 @@
</span><span class="cx" style="display: block; padding: 0 10px"> continue;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Calculates fluid typography rules where available.
+ if ( 'font-size' === $css_property ) {
+ /*
+ * wp_get_typography_font_size_value() will check
+ * if fluid typography has been activated and also
+ * whether the incoming value can be converted to a fluid value.
+ * Values that already have a clamp() function will not pass the test,
+ * and therefore the original $value will be returned.
+ */
+ $value = wp_get_typography_font_size_value( array( 'size' => $value ) );
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> $declarations[] = array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'name' => $css_property,
</span><span class="cx" style="display: block; padding: 0 10px"> 'value' => $value,
</span></span></pre></div>
<a id="trunksrcwpincludesdefaultfiltersphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/src/wp-includes/default-filters.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/default-filters.php 2022-10-11 18:13:34 UTC (rev 54496)
+++ trunk/src/wp-includes/default-filters.php 2022-10-11 18:42:20 UTC (rev 54497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -687,6 +687,9 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'setup_theme', 'wp_enable_block_templates' );
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'wp_loaded', '_add_template_loader_filters' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+// Fluid typography.
+add_filter( 'render_block', 'wp_render_typography_support', 10, 2 );
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // User preferences.
</span><span class="cx" style="display: block; padding: 0 10px"> add_action( 'init', 'wp_register_persisted_preferences_meta' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span></span></pre></div>
<a id="trunktestsphpunittestsblocksupportstypographyphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/block-supports/typography.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/block-supports/typography.php 2022-10-11 18:13:34 UTC (rev 54496)
+++ trunk/tests/phpunit/tests/block-supports/typography.php 2022-10-11 18:42:20 UTC (rev 54497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8,9 +8,41 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> private $test_block_name;
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+ * Stores the current test theme root.
+ *
+ * @var string|null
+ */
+ private $theme_root;
+
+ /**
+ * Caches the original theme directory global value in order
+ * to restore it in tear_down().
+ *
+ * @var string|null
+ */
+ private $orig_theme_dir;
+
</ins><span class="cx" style="display: block; padding: 0 10px"> function set_up() {
</span><span class="cx" style="display: block; padding: 0 10px"> parent::set_up();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->test_block_name = null;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ // Sets up the `wp-content/themes/` directory to ensure consistency when running tests.
+ $this->theme_root = realpath( DIR_TESTDATA . '/themedir1' );
+ $this->orig_theme_dir = $GLOBALS['wp_theme_directories'];
+ $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', $this->theme_root );
+
+ $theme_root_callback = function () {
+ return $this->theme_root;
+ };
+ add_filter( 'theme_root', $theme_root_callback );
+ add_filter( 'stylesheet_root', $theme_root_callback );
+ add_filter( 'template_root', $theme_root_callback );
+
+ // Clear caches.
+ wp_clean_themes_cache();
+ unset( $GLOBALS['wp_themes'] );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> /**
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -17,8 +49,15 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * Unregisters block type after each test.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function tear_down() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ // Restores the original theme directory setup.
+ $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir;
+ wp_clean_themes_cache();
+ unset( $GLOBALS['wp_themes'] );
+
+ // Resets test block name.
</ins><span class="cx" style="display: block; padding: 0 10px"> unregister_block_type( $this->test_block_name );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->test_block_name = null;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
</ins><span class="cx" style="display: block; padding: 0 10px"> parent::tear_down();
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -289,6 +328,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'expected_output' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'size: int 0' => array(
+ 'font_size_preset' => array(
+ 'size' => 0,
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 0,
+ ),
+
+ 'size: string 0' => array(
+ 'font_size_preset' => array(
+ 'size' => '0',
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '0',
+ ),
+
+ 'default_return_value_when_size_is_undefined' => array(
+ 'font_size_preset' => array(
+ 'size' => null,
+ ),
+ 'should_use_fluid_typography' => false,
+ 'expected_output' => null,
+ ),
+
</ins><span class="cx" style="display: block; padding: 0 10px"> 'default_return_value_when_fluid_is_false' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'font_size_preset' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -298,6 +361,24 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'expected_output' => '28px',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'default_return_value_when_value_is_already_clamped' => array(
+ 'font_size_preset' => array(
+ 'size' => 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
+ 'fluid' => false,
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
+ ),
+
+ 'default_return_value_with_unsupported_unit' => array(
+ 'font_size_preset' => array(
+ 'size' => '1000%',
+ 'fluid' => false,
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '1000%',
+ ),
+
</ins><span class="cx" style="display: block; padding: 0 10px"> 'return_fluid_value' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'font_size_preset' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'size' => '1.75rem',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -306,6 +387,30 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'expected_output' => 'clamp(1.3125rem, 1.3125rem + ((1vw - 0.48rem) * 2.524), 2.625rem)',
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px">
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'return_fluid_value_with_floats_with_units' => array(
+ 'font_size_preset' => array(
+ 'size' => '100.175px',
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 'clamp(75.13125px, 4.695703125rem + ((1vw - 7.68px) * 9.03), 150.2625px)',
+ ),
+
+ 'return_fluid_value_with_integer_coerced_to_px' => array(
+ 'font_size_preset' => array(
+ 'size' => 33,
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 'clamp(24.75px, 1.546875rem + ((1vw - 7.68px) * 2.975), 49.5px)',
+ ),
+
+ 'return_fluid_value_with_float_coerced_to_px' => array(
+ 'font_size_preset' => array(
+ 'size' => 100.23,
+ ),
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 'clamp(75.1725px, 4.69828125rem + ((1vw - 7.68px) * 9.035), 150.345px)',
+ ),
+
</ins><span class="cx" style="display: block; padding: 0 10px"> 'return_default_fluid_values_with_empty_fluid_array' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'font_size_preset' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'size' => '28px',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -371,4 +476,278 @@
</span><span class="cx" style="display: block; padding: 0 10px"> ),
</span><span class="cx" style="display: block; padding: 0 10px"> );
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ /**
+ * Tests that custom font sizes are converted to fluid values
+ * in inline block supports styles
+ * when "settings.typography.fluid" is set to true.
+ *
+ * @ticket 56467
+ *
+ * @covers ::wp_register_typography_support
+ *
+ * @dataProvider data_generate_block_supports_font_size_fixtures
+ *
+ * @param string $font_size_value The block supports custom font size value.
+ * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
+ * @param string $expected_output Expected value of style property from wp_apply_typography_support().
+ */
+ public function test_should_covert_font_sizes_to_fluid_values( $font_size_value, $should_use_fluid_typography, $expected_output ) {
+ if ( $should_use_fluid_typography ) {
+ switch_theme( 'block-theme-child-with-fluid-typography' );
+ } else {
+ switch_theme( 'default' );
+ }
+
+ $this->test_block_name = 'test/font-size-fluid-value';
+ register_block_type(
+ $this->test_block_name,
+ array(
+ 'api_version' => 2,
+ 'attributes' => array(
+ 'style' => array(
+ 'type' => 'object',
+ ),
+ ),
+ 'supports' => array(
+ 'typography' => array(
+ 'fontSize' => true,
+ ),
+ ),
+ )
+ );
+ $registry = WP_Block_Type_Registry::get_instance();
+ $block_type = $registry->get_registered( $this->test_block_name );
+ $block_attributes = array(
+ 'style' => array(
+ 'typography' => array(
+ 'fontSize' => $font_size_value,
+ ),
+ ),
+ );
+
+ $actual = wp_apply_typography_support( $block_type, $block_attributes );
+ $expected = array( 'style' => $expected_output );
+
+ $this->assertSame( $expected, $actual );
+ }
+
+ /**
+ * Data provider for test_should_covert_font_sizes_to_fluid_values().
+ *
+ * @return array
+ */
+ public function data_generate_block_supports_font_size_fixtures() {
+ return array(
+ 'default_return_value' => array(
+ 'font_size_value' => '50px',
+ 'should_use_fluid_typography' => false,
+ 'expected_output' => 'font-size:50px;',
+ ),
+ 'return_value_with_fluid_typography' => array(
+ 'font_size_value' => '50px',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => 'font-size:clamp(37.5px, 2.34375rem + ((1vw - 7.68px) * 4.507), 75px);',
+ ),
+ );
+ }
+
+ /**
+ * Tests that a block element's custom font size in the inline style attribute
+ * is replaced with a fluid value when "settings.typography.fluid" is set to true,
+ * and the correct block content is generated.
+ *
+ * @ticket 56467
+ *
+ * @dataProvider data_generate_replace_inline_font_styles_with_fluid_values_fixtures
+ *
+ * @param string $block_content HTML block content.
+ * @param string $font_size_value The block supports custom font size value.
+ * @param bool $should_use_fluid_typography An override to switch fluid typography "on". Can be used for unit testing.
+ * @param string $expected_output Expected value of style property from wp_apply_typography_support().
+ */
+ public function test_should_replace_inline_font_styles_with_fluid_values( $block_content, $font_size_value, $should_use_fluid_typography, $expected_output ) {
+ if ( $should_use_fluid_typography ) {
+ switch_theme( 'block-theme-child-with-fluid-typography' );
+ } else {
+ switch_theme( 'default' );
+ }
+
+ $block = array(
+ 'blockName' => 'core/image',
+ 'attrs' => array(
+ 'style' => array(
+ 'typography' => array(
+ 'fontSize' => $font_size_value,
+ ),
+ ),
+ ),
+ );
+ $actual = wp_render_typography_support( $block_content, $block );
+
+ $this->assertSame( $expected_output, $actual );
+ }
+
+ /**
+ * Data provider for test_should_replace_inline_font_styles_with_fluid_values().
+ *
+ * @return array
+ */
+ public function data_generate_replace_inline_font_styles_with_fluid_values_fixtures() {
+ return array(
+ 'default_return_content' => array(
+ 'block_content' => '<h2 class="has-vivid-red-background-color has-background has-link-color" style="margin-top:var(--wp--preset--spacing--60);font-size:4rem;font-style:normal;font-weight:600;letter-spacing:29px;text-decoration:underline;text-transform:capitalize">This is a heading</h2>',
+ 'font_size_value' => '4rem',
+ 'should_use_fluid_typography' => false,
+ 'expected_output' => '<h2 class="has-vivid-red-background-color has-background has-link-color" style="margin-top:var(--wp--preset--spacing--60);font-size:4rem;font-style:normal;font-weight:600;letter-spacing:29px;text-decoration:underline;text-transform:capitalize">This is a heading</h2>',
+ ),
+ 'return_content_with_replaced_fluid_font_size_inline_style' => array(
+ 'block_content' => '<h2 class="has-vivid-red-background-color has-background has-link-color" style="margin-top:var(--wp--preset--spacing--60);font-size:4rem;font-style:normal;font-weight:600;letter-spacing:29px;text-decoration:underline;text-transform:capitalize">This is a heading</h2>',
+ 'font_size_value' => '4rem',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '<h2 class="has-vivid-red-background-color has-background has-link-color" style="margin-top:var(--wp--preset--spacing--60);font-size:clamp(3rem, 3rem + ((1vw - 0.48rem) * 5.769), 6rem);font-style:normal;font-weight:600;letter-spacing:29px;text-decoration:underline;text-transform:capitalize">This is a heading</h2>',
+ ),
+ 'return_content_if_no_inline_font_size_found' => array(
+ 'block_content' => '<p class="has-medium-font-size" style="font-style:normal;font-weight:600;letter-spacing:29px;">A paragraph inside a group</p>',
+ 'font_size_value' => '20px',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '<p class="has-medium-font-size" style="font-style:normal;font-weight:600;letter-spacing:29px;">A paragraph inside a group</p>',
+ ),
+ 'return_content_css_var' => array(
+ 'block_content' => '<p class="has-medium-font-size" style="font-size:var(--wp--preset--font-size--x-large);">A paragraph inside a group</p>',
+ 'font_size_value' => 'var:preset|font-size|x-large',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '<p class="has-medium-font-size" style="font-size:var(--wp--preset--font-size--x-large);">A paragraph inside a group</p>',
+ ),
+ 'return_content_with_spaces' => array(
+ 'block_content' => '<p class="has-medium-font-size" style=" font-size: 20px ; ">A paragraph inside a group</p>',
+ 'font_size_value' => '20px',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => '<p class="has-medium-font-size" style=" font-size:clamp(15px, 0.9375rem + ((1vw - 7.68px) * 1.803), 30px); ">A paragraph inside a group</p>',
+ ),
+ 'return_content_with_first_match_replace_only' => array(
+ 'block_content' => "<div class=\"wp-block-group\" style=\"font-size:1em\"> \n \n<p style=\"font-size:1em\">A paragraph inside a group</p></div>",
+ 'font_size_value' => '1em',
+ 'should_use_fluid_typography' => true,
+ 'expected_output' => "<div class=\"wp-block-group\" style=\"font-size:clamp(0.75em, 0.75em + ((1vw - 0.48em) * 1.442), 1.5em);\"> \n \n<p style=\"font-size:1em\">A paragraph inside a group</p></div>",
+ ),
+ );
+ }
+
+ /**
+ * Tests that valid font size values are parsed.
+ *
+ * @ticket 56467
+ *
+ * @covers ::wp_get_typography_value_and_unit
+ *
+ * @dataProvider data_valid_size_wp_get_typography_value_and_unit
+ *
+ * @param mixed $raw_value Raw size value to test.
+ * @param mixed $expected An expected return value.
+ */
+ public function test_valid_size_wp_get_typography_value_and_unit( $raw_value, $expected ) {
+ $this->assertEquals( $expected, wp_get_typography_value_and_unit( $raw_value ) );
+ }
+
+ /**
+ * Data provider for test_valid_size_wp_get_typography_value_and_unit().
+ *
+ * @return array
+ */
+ public function data_valid_size_wp_get_typography_value_and_unit() {
+ return array(
+ 'size: 10vh with default units do not match' => array(
+ 'raw_value' => '10vh',
+ 'expected' => null,
+ ),
+ 'size: calc() values do not match' => array(
+ 'raw_value' => 'calc(2 * 10px)',
+ 'expected' => null,
+ ),
+ 'size: clamp() values do not match' => array(
+ 'raw_value' => 'clamp(15px, 0.9375rem + ((1vw - 7.68px) * 5.409), 60px)',
+ 'expected' => null,
+ ),
+ 'size: `"10"`' => array(
+ 'raw_value' => '10',
+ 'expected' => array(
+ 'value' => 10,
+ 'unit' => 'px',
+ ),
+ ),
+ 'size: `11`' => array(
+ 'raw_value' => 11,
+ 'expected' => array(
+ 'value' => 11,
+ 'unit' => 'px',
+ ),
+ ),
+ 'size: `11.234`' => array(
+ 'raw_value' => '11.234',
+ 'expected' => array(
+ 'value' => 11.234,
+ 'unit' => 'px',
+ ),
+ ),
+ 'size: `"12rem"`' => array(
+ 'raw_value' => '12rem',
+ 'expected' => array(
+ 'value' => 12,
+ 'unit' => 'rem',
+ ),
+ ),
+ 'size: `"12px"`' => array(
+ 'raw_value' => '12px',
+ 'expected' => array(
+ 'value' => 12,
+ 'unit' => 'px',
+ ),
+ ),
+ 'size: `"12em"`' => array(
+ 'raw_value' => '12em',
+ 'expected' => array(
+ 'value' => 12,
+ 'unit' => 'em',
+ ),
+ ),
+ 'size: `"12.74em"`' => array(
+ 'raw_value' => '12.74em',
+ 'expected' => array(
+ 'value' => 12.74,
+ 'unit' => 'em',
+ ),
+ ),
+ );
+ }
+
+ /**
+ * Tests that invalid font size values are not parsed and trigger incorrect usage.
+ *
+ * @ticket 56467
+ *
+ * @covers ::wp_get_typography_value_and_unit
+ *
+ * @dataProvider data_invalid_size_wp_get_typography_value_and_unit
+ * @expectedIncorrectUsage wp_get_typography_value_and_unit
+ *
+ * @param mixed $raw_value Raw size value to test.
+ */
+ public function test_invalid_size_wp_get_typography_value_and_unit( $raw_value ) {
+ $this->assertNull( wp_get_typography_value_and_unit( $raw_value ) );
+ }
+
+ /**
+ * Data provider for test_invalid_size_wp_get_typography_value_and_unit().
+ *
+ * @return array
+ */
+ public function data_invalid_size_wp_get_typography_value_and_unit() {
+ return array(
+ 'size: null' => array( null ),
+ 'size: false' => array( false ),
+ 'size: true' => array( true ),
+ 'size: array' => array( array( '10' ) ),
+ );
+ }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunitteststhemethemeDirphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: trunk/tests/phpunit/tests/theme/themeDir.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/theme/themeDir.php 2022-10-11 18:13:34 UTC (rev 54496)
+++ trunk/tests/phpunit/tests/theme/themeDir.php 2022-10-11 18:42:20 UTC (rev 54497)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -177,6 +177,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 'REST Theme',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme Child Theme',
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Block Theme Child Theme With Fluid Typography',
</ins><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme [0.4.0]',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme [1.0.0] in subdirectory',
</span><span class="cx" style="display: block; padding: 0 10px"> 'Block Theme Deprecated Path',
</span></span></pre>
</div>
</div>
</body>
</html>