<!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>[57720] trunk: Font face resolver: print font faces from font families defined in all theme.json origins.</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/57720">57720</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/57720","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>youknowriad</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-02-27 12:04:55 +0000 (Tue, 27 Feb 2024)</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'>Font face resolver: print font faces from font families defined in all theme.json origins.

This commit updates the theme.json style generation to allow a font family name to be repeated across theme.json origins (default, theme, custom).

Props mmaattiiaass, hellofromtonya, arthur791004, ironprogrammer.
Fixes <a href="https://core.trac.wordpress.org/ticket/60605">#60605</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesfontsclasswpfontfaceresolverphp">trunk/src/wp-includes/fonts/class-wp-font-face-resolver.php</a></li>
<li><a href="#trunksrcwpincludesfontsphp">trunk/src/wp-includes/fonts.php</a></li>
<li><a href="#trunktestsphpunittestsfontsfontfacewpfontfacetestsdatasetphp">trunk/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php</a></li>
<li><a href="#trunktestsphpunittestsfontsfontfacewpFontFaceResolvergetFontsFromThemeJsonphp">trunk/tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesfontsclasswpfontfaceresolverphp"></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/fonts/class-wp-font-face-resolver.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/fonts/class-wp-font-face-resolver.php       2024-02-27 10:27:08 UTC (rev 57719)
+++ trunk/src/wp-includes/fonts/class-wp-font-face-resolver.php 2024-02-27 12:04:55 UTC (rev 57720)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -67,12 +67,7 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                // Prepare the fonts array structure for this font-family.
-                               if ( ! array_key_exists( $font_family_name, $fonts ) ) {
-                                       $fonts[ $font_family_name ] = array();
-                               }
-
-                               $fonts[ $font_family_name ] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         $fonts[] = static::convert_font_face_properties( $definition['fontFace'], $font_family_name );
</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></pre></div>
<a id="trunksrcwpincludesfontsphp"></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/fonts.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/fonts.php   2024-02-27 10:27:08 UTC (rev 57719)
+++ trunk/src/wp-includes/fonts.php     2024-02-27 12:04:55 UTC (rev 57720)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -13,13 +13,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">  * @since 6.4.0
</span><span class="cx" style="display: block; padding: 0 10px">  *
</span><span class="cx" style="display: block; padding: 0 10px">  * @param array[][] $fonts {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *     Optional. The font-families and their font variations. Default empty array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *     Optional. The font-families and their font faces. Default empty array.
</ins><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 $font-family => array[] $variations {
- *         Optional. An associated array of font variations for this font-family.
- *         Each variation has the following structure.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *     @type array {
+ *         An indexed or associative (keyed by font-family) array of font variations for this font-family.
+ *         Each font face has the following structure.
</ins><span class="cx" style="display: block; padding: 0 10px">  *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- *         @type array $font_variation {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ *         @type array {
</ins><span class="cx" style="display: block; padding: 0 10px">  *             @type string          $font-family             The font-family property.
</span><span class="cx" style="display: block; padding: 0 10px">  *             @type string|string[] $src                     The URL(s) to each resource containing the font data.
</span><span class="cx" style="display: block; padding: 0 10px">  *             @type string          $font-style              Optional. The font-style property. Default 'normal'.
</span></span></pre></div>
<a id="trunktestsphpunittestsfontsfontfacewpfontfacetestsdatasetphp"></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/fonts/font-face/wp-font-face-tests-dataset.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php  2024-02-27 10:27:08 UTC (rev 57719)
+++ trunk/tests/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php    2024-02-27 12:04:55 UTC (rev 57720)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -92,7 +92,7 @@
</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">                        'multiple woff2 format fonts'    => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'fonts'    => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'fonts'                  => array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                         'DM Sans'       =>
</span><span class="cx" style="display: block; padding: 0 10px">                                                array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -184,7 +184,7 @@
</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><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'expected' => <<<CSS
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'expected'               => <<<CSS
</ins><span class="cx" style="display: block; padding: 0 10px"> @font-face{font-family:"DM Sans";font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2') format('woff2');font-stretch:normal;}
</span><span class="cx" style="display: block; padding: 0 10px"> @font-face{font-family:"DM Sans";font-style:italic;font-weight:400;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2') format('woff2');font-stretch:normal;}
</span><span class="cx" style="display: block; padding: 0 10px"> @font-face{font-family:"DM Sans";font-style:normal;font-weight:700;font-display:fallback;src:url('https://example.org/assets/fonts/dm-sans/DMSans-Bold.woff2') format('woff2');font-stretch:normal;}
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -195,6 +195,49 @@
</span><span class="cx" style="display: block; padding: 0 10px"> @font-face{font-family:"IBM Plex Mono";font-style:normal;font-weight:700;font-display:block;src:url('https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2') format('woff2');font-stretch:normal;}
</span><span class="cx" style="display: block; padding: 0 10px"> CSS
</span><span class="cx" style="display: block; padding: 0 10px">                        ,
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                'indexed array as input' => array(
+                                       'fonts'    => array(
+                                               array(
+                                                       array(
+                                                               'font-family'  => 'Piazzolla',
+                                                               'src'          => array( 'https://example.org/fonts/piazzolla400.ttf' ),
+                                                               'font-style'   => 'normal',
+                                                               'font-weight'  => '400',
+                                                               'font-stretch' => 'normal',
+                                                       ),
+                                                       array(
+                                                               'font-family'  => 'Piazzolla',
+                                                               'src'          => array( 'https://example.org/fonts/piazzolla500.ttf' ),
+                                                               'font-style'   => 'normal',
+                                                               'font-weight'  => '400',
+                                                               'font-stretch' => 'normal',
+                                                       ),
+                                               ),
+                                               array(
+                                                       array(
+                                                               'font-family'  => 'Lobster',
+                                                               'src'          => array( 'https://example.org/fonts/lobster400.ttf' ),
+                                                               'font-style'   => 'normal',
+                                                               'font-weight'  => '400',
+                                                               'font-stretch' => 'normal',
+                                                       ),
+                                                       array(
+                                                               'font-family'  => 'Lobster',
+                                                               'src'          => array( 'https://example.org/fonts/lobster500.ttf' ),
+                                                               'font-style'   => 'normal',
+                                                               'font-weight'  => '500',
+                                                               'font-stretch' => 'normal',
+                                                       ),
+                                               ),
+                                       ),
+                                       'expected' => <<<CSS
+@font-face{font-family:Piazzolla;font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/fonts/piazzolla400.ttf') format('truetype');font-stretch:normal;}
+@font-face{font-family:Piazzolla;font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/fonts/piazzolla500.ttf') format('truetype');font-stretch:normal;}
+@font-face{font-family:Lobster;font-style:normal;font-weight:400;font-display:fallback;src:url('https://example.org/fonts/lobster400.ttf') format('truetype');font-stretch:normal;}
+@font-face{font-family:Lobster;font-style:normal;font-weight:500;font-display:fallback;src:url('https://example.org/fonts/lobster500.ttf') format('truetype');font-stretch:normal;}
+CSS
+                                       ,
+                               ),
</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">@@ -206,7 +249,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        $uri  = get_stylesheet_directory_uri() . '/assets/fonts/';
</span><span class="cx" style="display: block; padding: 0 10px">                        $data = array(
</span><span class="cx" style="display: block; padding: 0 10px">                                'fonts'            => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'DM Sans'          => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'src'          => array( $uri . 'dm-sans/DMSans-Regular.woff2' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'font-family'  => 'DM Sans',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -236,7 +279,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'font-weight'  => '700',
</span><span class="cx" style="display: block; padding: 0 10px">                                                ),
</span><span class="cx" style="display: block; padding: 0 10px">                                        ),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                        'Source Serif Pro' => array(
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                                 array(
</ins><span class="cx" style="display: block; padding: 0 10px">                                                 array(
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'src'          => array( $uri . 'source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ),
</span><span class="cx" style="display: block; padding: 0 10px">                                                        'font-family'  => 'Source Serif Pro',
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -271,4 +314,93 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                return $data;
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+       public static function get_custom_font_families( $key = '' ) {
+               static $data = null;
+
+               $custom_theme_json_fonts = array(
+                       array(
+                               'fontFamily' => 'Piazzolla, serif',
+                               'name'       => 'Piazzolla',
+                               'slug'       => 'piazzolla',
+                               'fontFace'   => array(
+                                       array(
+                                               'fontFamily' => 'Piazzolla',
+                                               'src'        => array( 'https://example.org/fonts/piazzolla400.ttf' ),
+                                               'fontStyle'  => 'normal',
+                                               'fontWeight' => '400',
+                                       ),
+                                       array(
+                                               'fontFamily' => 'Piazzolla',
+                                               'src'        => array( 'https://example.org/fonts/piazzolla500.ttf' ),
+                                               'fontStyle'  => 'normal',
+                                               'fontWeight' => '400',
+                                       ),
+                               ),
+                       ),
+                       array(
+                               'fontFamily' => 'Lobster, sans-serif',
+                               'name'       => 'Lobster',
+                               'slug'       => 'lobster',
+                               'fontFace'   => array(
+                                       array(
+                                               'fontFamily' => 'Lobster',
+                                               'src'        => array( 'https://example.org/fonts/lobster400.ttf' ),
+                                               'fontStyle'  => 'normal',
+                                               'fontWeight' => '400',
+                                       ),
+                                       array(
+                                               'fontFamily' => 'Lobster',
+                                               'src'        => array( 'https://example.org/fonts/lobster500.ttf' ),
+                                               'fontStyle'  => 'normal',
+                                               'fontWeight' => '500',
+                                       ),
+                               ),
+                       ),
+               );
+
+               $expected_font_faces = array(
+                       array(
+                               array(
+                                       'src'         => array( 'https://example.org/fonts/piazzolla400.ttf' ),
+                                       'font-family' => 'Piazzolla',
+                                       'font-style'  => 'normal',
+                                       'font-weight' => '400',
+                               ),
+                               array(
+                                       'src'         => array( 'https://example.org/fonts/piazzolla500.ttf' ),
+                                       'font-family' => 'Piazzolla',
+                                       'font-style'  => 'normal',
+                                       'font-weight' => '400',
+                               ),
+                       ),
+                       array(
+                               array(
+                                       'src'         => array( 'https://example.org/fonts/lobster400.ttf' ),
+                                       'font-family' => 'Lobster',
+                                       'font-style'  => 'normal',
+                                       'font-weight' => '400',
+                               ),
+                               array(
+                                       'src'         => array( 'https://example.org/fonts/lobster500.ttf' ),
+                                       'font-family' => 'Lobster',
+                                       'font-style'  => 'normal',
+                                       'font-weight' => '500',
+                               ),
+                       ),
+               );
+
+               if ( null === $data ) {
+                       $data = array(
+                               'input'    => $custom_theme_json_fonts,
+                               'expected' => $expected_font_faces,
+                       );
+               }
+
+               if ( isset( $data[ $key ] ) ) {
+                       return $data[ $key ];
+               }
+
+               return $data;
+       }
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunktestsphpunittestsfontsfontfacewpFontFaceResolvergetFontsFromThemeJsonphp"></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/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php    2024-02-27 10:27:08 UTC (rev 57719)
+++ trunk/tests/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php      2024-02-27 12:04:55 UTC (rev 57720)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,19 +38,57 @@
</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">+         * @ticket 60605
+        */
+       public function test_should_return_all_fonts_from_all_theme_origins() {
+               switch_theme( static::FONTS_THEME );
+
+               $add_custom_fonts = static function ( $theme_json_data ) {
+                       $data = $theme_json_data->get_data();
+                       // Add font families to the custom origin of theme json.
+                       $data['settings']['typography']['fontFamilies']['custom'] = self::get_custom_font_families( 'input' );
+                       return new WP_Theme_JSON_Data( $data );
+               };
+
+               add_filter( 'wp_theme_json_data_theme', $add_custom_fonts );
+               $actual = WP_Font_Face_Resolver::get_fonts_from_theme_json();
+               remove_filter( 'wp_theme_json_data_theme', $add_custom_fonts );
+
+               $expected = array_merge(
+                       $this->get_expected_fonts_for_fonts_block_theme( 'fonts' ),
+                       $this->get_custom_font_families( 'expected' )
+               );
+
+               $this->assertSame( $expected, $actual, 'Both the fonts from the theme and the custom origin should be returned.' );
+       }
+
+       /**
</ins><span class="cx" style="display: block; padding: 0 10px">          * @dataProvider data_should_replace_src_file_placeholder
</span><span class="cx" style="display: block; padding: 0 10px">         *
</span><span class="cx" style="display: block; padding: 0 10px">         * @param string $font_name  Font's name.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * @param string $font_index Font's index in the $fonts array.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * @param string $font_weight Font's weight.
+        * @param string $font_style  Font's style.
</ins><span class="cx" style="display: block; padding: 0 10px">          * @param string $expected   Expected src.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function test_should_replace_src_file_placeholder( $font_name, $font_index, $expected ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function test_should_replace_src_file_placeholder( $font_name, $font_weight, $font_style, $expected ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                 switch_theme( static::FONTS_THEME );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $fonts = array_merge( array(), ...array_map( 'array_values', $fonts ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $actual   = $fonts[ $font_name ][ $font_index ]['src'][0];
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $font = array_filter(
+                       $fonts,
+                       static function ( $font ) use ( $font_name, $font_weight, $font_style ) {
+                               return $font['font-family'] === $font_name
+                               && $font['font-weight'] === $font_weight
+                               && $font['font-style'] === $font_style;
+                       }
+               );
+
+               $font = reset( $font );
+
</ins><span class="cx" style="display: block; padding: 0 10px">                 $expected = get_stylesheet_directory_uri() . $expected;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                $actual   = $font['src'][0];
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertStringNotContainsString( 'file:./', $actual, 'Font src should not contain the "file:./" placeholder' );
</span><span class="cx" style="display: block; padding: 0 10px">                $this->assertSame( $expected, $actual, 'Font src should be an URL to its file' );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -65,34 +103,40 @@
</span><span class="cx" style="display: block; padding: 0 10px">                return array(
</span><span class="cx" style="display: block; padding: 0 10px">                        // Theme's theme.json.
</span><span class="cx" style="display: block; padding: 0 10px">                        'DM Sans: 400 normal'              => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'DM Sans',
-                               'font_index' => 0,
-                               'expected'   => '/assets/fonts/dm-sans/DMSans-Regular.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'DM Sans',
+                               'font_weight' => '400',
+                               'font_style'  => 'normal',
+                               'expected'    => '/assets/fonts/dm-sans/DMSans-Regular.woff2',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'DM Sans: 400 italic'              => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'DM Sans',
-                               'font_index' => 1,
-                               'expected'   => '/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'DM Sans',
+                               'font_weight' => '400',
+                               'font_style'  => 'italic',
+                               'expected'    => '/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'DM Sans: 700 normal'              => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'DM Sans',
-                               'font_index' => 2,
-                               'expected'   => '/assets/fonts/dm-sans/DMSans-Bold.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'DM Sans',
+                               'font_weight' => '700',
+                               'font_style'  => 'normal',
+                               'expected'    => '/assets/fonts/dm-sans/DMSans-Bold.woff2',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'DM Sans: 700 italic'              => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'DM Sans',
-                               'font_index' => 3,
-                               'expected'   => '/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'DM Sans',
+                               'font_weight' => '700',
+                               'font_style'  => 'italic',
+                               'expected'    => '/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'Source Serif Pro: 200-900 normal' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'Source Serif Pro',
-                               'font_index' => 0,
-                               'expected'   => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'Source Serif Pro',
+                               'font_weight' => '200 900',
+                               'font_style'  => 'normal',
+                               'expected'    => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2',
</ins><span class="cx" style="display: block; padding: 0 10px">                         ),
</span><span class="cx" style="display: block; padding: 0 10px">                        'Source Serif Pro: 200-900 italic' => array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                'font_name'  => 'Source Serif Pro',
-                               'font_index' => 1,
-                               'expected'   => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2',
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         'font_name'   => 'Source Serif Pro',
+                               'font_weight' => '200 900',
+                               'font_style'  => 'italic',
+                               'expected'    => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2',
</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">@@ -118,7 +162,17 @@
</span><span class="cx" style="display: block; padding: 0 10px">                $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json();
</span><span class="cx" style="display: block; padding: 0 10px">                remove_filter( 'wp_theme_json_data_theme', $replace_fonts );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $this->assertArrayHasKey( $expected_name, $fonts );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // flatten the array to make it easier to test.
+               $fonts = array_merge( array(), ...array_map( 'array_values', $fonts ) );
+
+               $fonts_found = array_filter(
+                       $fonts,
+                       function ( $font ) use ( $expected_name ) {
+                               return $font['font-family'] === $expected_name;
+                       }
+               );
+
+               $this->assertNotEmpty( $fonts_found, 'Expected font-family name not found in the array' );
</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></pre>
</div>
</div>

</body>
</html>