<!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>[57686] trunk: Editor: Ensure font collection metadata can be properly localized.</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/57686">57686</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/57686","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>swissspidy</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2024-02-21 19:24:14 +0000 (Wed, 21 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'>Editor: Ensure font collection metadata can be properly localized.
Updates `wp_register_font_collection()` and `WP_Font_Collection` so that only font families can be loaded from a file or URL.
All metadata, such as name, description, and list of font categories, needs to be passed directly in PHP so that it can be properly localized.
Props swissspidy, mmaattiiaass, grantmkin, youknowriad.
Fixes <a href="https://core.trac.wordpress.org/ticket/60509">#60509</a>.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunksrcwpincludesfontsclasswpfontcollectionphp">trunk/src/wp-includes/fonts/class-wp-font-collection.php</a></li>
<li><a href="#trunksrcwpincludesfontsclasswpfontlibraryphp">trunk/src/wp-includes/fonts/class-wp-font-library.php</a></li>
<li><a href="#trunksrcwpincludesfontsphp">trunk/src/wp-includes/fonts.php</a></li>
<li><a href="#trunksrcwpincludesrestapiendpointsclasswprestfontcollectionscontrollerphp">trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php</a></li>
<li><a href="#trunktestsphpunittestsfontsfontlibrarywpFontCollectiongetDataphp">trunk/tests/phpunit/tests/fonts/font-library/wpFontCollection/getData.php</a></li>
<li><a href="#trunktestsphpunittestsfontsfontlibrarywpRestFontCollectionsControllerphp">trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunksrcwpincludesfontsclasswpfontcollectionphp"></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-collection.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-collection.php 2024-02-21 19:24:12 UTC (rev 57685)
+++ trunk/src/wp-includes/fonts/class-wp-font-collection.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -46,12 +46,11 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><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 $slug Font collection slug.
- * @param array|string $data_or_file Font collection data array or a path/URL to a JSON file
- * containing the font collection.
- * See {@see wp_register_font_collection()} for the supported fields.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
+ * and underscores. See sanitize_title().
+ * @param array $args Font collection data. See wp_register_font_collection() for information on accepted arguments.
</ins><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 __construct( $slug, $data_or_file ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function __construct( string $slug, array $args ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->slug = sanitize_title( $slug );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->slug !== $slug ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -62,12 +61,17 @@
</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">- if ( is_array( $data_or_file ) ) {
- $this->data = $this->sanitize_and_validate_data( $data_or_file );
- } else {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $required_properties = array( 'name', 'font_families' );
+
+ if ( isset( $args['font_families'] ) && is_string( $args['font_families'] ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> // JSON data is lazy loaded by ::get_data().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->src = $data_or_file;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->src = $args['font_families'];
+ unset( $args['font_families'] );
+
+ $required_properties = array( 'name' );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+
+ $this->data = $this->sanitize_and_validate_data( $args, $required_properties );
</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">@@ -78,8 +82,12 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @return array|WP_Error An array containing the font collection data, or a WP_Error on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function get_data() {
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( is_wp_error( $this->data ) ) {
+ return $this->data;
+ }
+
</ins><span class="cx" style="display: block; padding: 0 10px"> // If the collection uses JSON data, load it and cache the data/error.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- if ( $this->src && empty( $this->data ) ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ if ( isset( $this->src ) ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $this->data = $this->load_from_json( $this->src );
</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">@@ -116,7 +124,26 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'font_collection_json_missing', $message );
</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">- return $url ? $this->load_from_url( $url ) : $this->load_from_file( $file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = $url ? $this->load_from_url( $url ) : $this->load_from_file( $file );
+
+ if ( is_wp_error( $data ) ) {
+ return $data;
+ }
+
+ $data = array(
+ 'name' => $this->data['name'],
+ 'font_families' => $data['font_families'],
+ );
+
+ if ( isset( $this->data['description'] ) ) {
+ $data['description'] = $this->data['description'];
+ }
+
+ if ( isset( $this->data['categories'] ) ) {
+ $data['categories'] = $this->data['categories'];
+ }
+
+ return $data;
</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">@@ -134,7 +161,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> return new WP_Error( 'font_collection_decode_error', __( 'Error decoding the font collection JSON file contents.' ) );
</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">- return $this->sanitize_and_validate_data( $data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return $this->sanitize_and_validate_data( $data, array( 'font_families' ) );
</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">@@ -154,8 +181,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> if ( false === $data ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $response = wp_safe_remote_get( $url );
</span><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- // translators: %s: Font collection URL.
- return new WP_Error( 'font_collection_request_error', sprintf( __( 'Error fetching the font collection data from "%s".' ), $url ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ return new WP_Error(
+ 'font_collection_request_error',
+ sprintf(
+ // translators: %s: Font collection URL.
+ __( 'Error fetching the font collection data from "%s".' ),
+ $url
+ )
+ );
</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"> $data = json_decode( wp_remote_retrieve_body( $response ), true );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -164,7 +197,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"> // Make sure the data is valid before storing it in a transient.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $data = $this->sanitize_and_validate_data( $data );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $data = $this->sanitize_and_validate_data( $data, array( 'font_families' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( is_wp_error( $data ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $data;
</span><span class="cx" style="display: block; padding: 0 10px"> }
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -180,14 +213,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array $data Font collection data to sanitize and validate.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $data Font collection data to sanitize and validate.
+ * @param array $required_properties Required properties that must exist in the passed data.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return array|WP_Error Sanitized data if valid, otherwise a WP_Error instance.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function sanitize_and_validate_data( $data ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function sanitize_and_validate_data( $data, $required_properties = array() ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> $schema = self::get_sanitization_schema();
</span><span class="cx" style="display: block; padding: 0 10px"> $data = WP_Font_Utils::sanitize_from_schema( $data, $schema );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $required_properties = array( 'name', 'font_families' );
</del><span class="cx" style="display: block; padding: 0 10px"> foreach ( $required_properties as $property ) {
</span><span class="cx" style="display: block; padding: 0 10px"> if ( empty( $data[ $property ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $message = sprintf(
</span></span></pre></div>
<a id="trunksrcwpincludesfontsclasswpfontlibraryphp"></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-library.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-library.php 2024-02-21 19:24:12 UTC (rev 57685)
+++ trunk/src/wp-includes/fonts/class-wp-font-library.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -37,15 +37,14 @@
</span><span class="cx" style="display: block; padding: 0 10px"> *
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><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 $slug Font collection slug.
- * @param array $data_or_file Font collection data array or a path/URL to a JSON file
- * containing the font collection.
- * See {@see wp_register_font_collection()} for the supported fields.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
+ * and underscores. See sanitize_title().
+ * @param array $args Font collection data. See wp_register_font_collection() for information on accepted arguments.
</ins><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Font_Collection|WP_Error A font collection if it was registered successfully,
</span><span class="cx" style="display: block; padding: 0 10px"> * or WP_Error object on failure.
</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 register_font_collection( $slug, $data_or_file ) {
- $new_collection = new WP_Font_Collection( $slug, $data_or_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function register_font_collection( string $slug, array $args ) {
+ $new_collection = new WP_Font_Collection( $slug, $args );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> if ( $this->is_collection_registered( $new_collection->slug ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> $error_message = sprintf(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -72,7 +71,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug Font collection slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if the font collection was unregistered successfully and false otherwise.
</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 unregister_font_collection( $slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function unregister_font_collection( string $slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( ! $this->is_collection_registered( $slug ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> _doing_it_wrong(
</span><span class="cx" style="display: block; padding: 0 10px"> __METHOD__,
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -94,7 +93,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug Font collection slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if the font collection is registered and false otherwise.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- private function is_collection_registered( $slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ private function is_collection_registered( string $slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return array_key_exists( $slug, $this->collections );
</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">@@ -117,7 +116,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug Font collection slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
</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 get_font_collection( $slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function get_font_collection( string $slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> if ( $this->is_collection_registered( $slug ) ) {
</span><span class="cx" style="display: block; padding: 0 10px"> return $this->collections[ $slug ];
</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-21 19:24:12 UTC (rev 57685)
+++ trunk/src/wp-includes/fonts.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -53,28 +53,30 @@
</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">- * Registers a new Font Collection in the Font Library.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * Registers a new font collection in the font library.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * See {@link https://schemas.wp.org/trunk/font-collection.json} for the schema
+ * the font collection data must adhere to.
+ *
</ins><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><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 $slug Font collection slug. May only contain alphanumeric characters, dashes,
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
</ins><span class="cx" style="display: block; padding: 0 10px"> * and underscores. See sanitize_title().
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @param array|string $data_or_file {
- * Font collection data array or a path/URL to a JSON file containing the font collection.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @param array $args {
+ * Font collection data.
</ins><span class="cx" style="display: block; padding: 0 10px"> *
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- * @link https://schemas.wp.org/trunk/font-collection.json
- *
- * @type string $name Required. Name of the font collection shown in the Font Library.
- * @type string $description Optional. A short descriptive summary of the font collection. Default empty.
- * @type array $font_families Required. Array of font family definitions that are in the collection.
- * @type array $categories Optional. Array of categories, each with a name and slug, that are used by the
- * fonts in the collection. Default empty.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ * @type string $name Required. Name of the font collection shown in the Font Library.
+ * @type string $description Optional. A short descriptive summary of the font collection. Default empty.
+ * @type array|string $font_families Required. Array of font family definitions that are in the collection,
+ * or a string containing the path or URL to a JSON file containing the font collection.
+ * @type array $categories Optional. Array of categories, each with a name and slug, that are used by the
+ * fonts in the collection. Default empty.
</ins><span class="cx" style="display: block; padding: 0 10px"> * }
</span><span class="cx" style="display: block; padding: 0 10px"> * @return WP_Font_Collection|WP_Error A font collection if it was registered
</span><span class="cx" style="display: block; padding: 0 10px"> * successfully, or WP_Error object on failure.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_register_font_collection( $slug, $data_or_file ) {
- return WP_Font_Library::get_instance()->register_font_collection( $slug, $data_or_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_register_font_collection( string $slug, array $args ) {
+ return WP_Font_Library::get_instance()->register_font_collection( $slug, $args );
</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">@@ -85,7 +87,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @param string $slug Font collection slug.
</span><span class="cx" style="display: block; padding: 0 10px"> * @return bool True if the font collection was unregistered successfully, else false.
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-function wp_unregister_font_collection( $slug ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+function wp_unregister_font_collection( string $slug ) {
</ins><span class="cx" style="display: block; padding: 0 10px"> return WP_Font_Library::get_instance()->unregister_font_collection( $slug );
</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">@@ -196,5 +198,34 @@
</span><span class="cx" style="display: block; padding: 0 10px"> * @since 6.5.0
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> function _wp_register_default_font_collections() {
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_register_font_collection( 'google-fonts', 'https://s.w.org/images/fonts/17.7/collections/google-fonts-with-preview.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_register_font_collection(
+ 'google-fonts',
+ array(
+ 'name' => _x( 'Google Fonts', 'font collection name' ),
+ 'description' => __( 'Install from Google Fonts. Fonts are copied to and served from your site.' ),
+ 'font_families' => 'https://s.w.org/images/fonts/17.7/collections/google-fonts-with-preview.json',
+ 'categories' => array(
+ array(
+ 'name' => _x( 'Sans Serif', 'font category' ),
+ 'slug' => 'sans-serif',
+ ),
+ array(
+ 'name' => _x( 'Display', 'font category' ),
+ 'slug' => 'display',
+ ),
+ array(
+ 'name' => _x( 'Serif', 'font category' ),
+ 'slug' => 'serif',
+ ),
+ array(
+ 'name' => _x( 'Handwriting', 'font category' ),
+ 'slug' => 'handwriting',
+ ),
+ array(
+ 'name' => _x( 'Monospace', 'font category' ),
+ 'slug' => 'monospace',
+ ),
+ ),
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> }
</span></span></pre></div>
<a id="trunksrcwpincludesrestapiendpointsclasswprestfontcollectionscontrollerphp"></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/rest-api/endpoints/class-wp-rest-font-collections-controller.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php 2024-02-21 19:24:12 UTC (rev 57685)
+++ trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-font-collections-controller.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -104,7 +104,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_ensure_response( $items );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $response->header( 'X-WP-Total', (int) $total_items );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $response->header( 'X-WP-TotalPages', (int) $max_pages );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $response->header( 'X-WP-TotalPages', $max_pages );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request_params = $request->get_query_params();
</span><span class="cx" style="display: block; padding: 0 10px"> $collection_url = rest_url( $this->namespace . '/' . $this->rest_base );
</span></span></pre></div>
<a id="trunktestsphpunittestsfontsfontlibrarywpFontCollectiongetDataphp"></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-library/wpFontCollection/getData.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-library/wpFontCollection/getData.php 2024-02-21 19:24:12 UTC (rev 57685)
+++ trunk/tests/phpunit/tests/fonts/font-library/wpFontCollection/getData.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -40,11 +40,17 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $mock_file = wp_tempnam( 'my-collection-data-' );
</span><span class="cx" style="display: block; padding: 0 10px"> file_put_contents( $mock_file, wp_json_encode( $config ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $collection = new WP_Font_Collection( $slug, $mock_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ $slug,
+ array_merge(
+ $config,
+ array( 'font_families' => $mock_file )
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $slug, $collection->slug, 'The slug should match.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $expected_data, $data, 'The collection data should match.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEqualSetsWithIndex( $expected_data, $data, 'The collection data should match.' );
</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">@@ -58,13 +64,21 @@
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_http_request', array( $this, 'mock_request' ), 10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> self::$mock_collection_data = $config;
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $collection = new WP_Font_Collection( $slug, 'https://example.com/fonts/mock-font-collection.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ $slug,
+ array_merge(
+ $config,
+ array(
+ 'font_families' => 'https://example.com/fonts/mock-font-collection.json',
+ )
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'pre_http_request', array( $this, 'mock_request' ) );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame( $slug, $collection->slug, 'The slug should match.' );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertSame( $expected_data, $data, 'The collection data should match.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertEqualSetsWithIndex( $expected_data, $data, 'The collection data should match.' );
</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">@@ -74,7 +88,6 @@
</span><span class="cx" style="display: block; padding: 0 10px"> */
</span><span class="cx" style="display: block; padding: 0 10px"> public function data_create_font_collection() {
</span><span class="cx" style="display: block; padding: 0 10px"> return array(
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-
</del><span class="cx" style="display: block; padding: 0 10px"> 'font collection with required data' => array(
</span><span class="cx" style="display: block; padding: 0 10px"> 'slug' => 'my-collection',
</span><span class="cx" style="display: block; padding: 0 10px"> 'config' => array(
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -185,7 +198,6 @@
</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">-
</del><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">@@ -202,8 +214,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned when property is missing or invalid.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_missing_property',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_missing_property',
</del><span class="cx" style="display: block; padding: 0 10px"> 'Incorrect error code when property is missing or invalid.'
</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">@@ -243,13 +255,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_should_error_with_invalid_json_file_path() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_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">- $collection = new WP_Font_Collection( 'my-collection', 'non-existing.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ 'my-collection',
+ array(
+ 'name' => 'My collection',
+ 'font_families' => 'non-existing.json',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned when invalid file path is provided.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_json_missing',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_json_missing',
</del><span class="cx" style="display: block; padding: 0 10px"> 'Incorrect error code when invalid file path is provided.'
</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">@@ -258,7 +276,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $mock_file = wp_tempnam( 'my-collection-data-' );
</span><span class="cx" style="display: block; padding: 0 10px"> file_put_contents( $mock_file, 'invalid-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">- $collection = new WP_Font_Collection( 'my-collection', $mock_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ 'my-collection',
+ array(
+ 'name' => 'Invalid collection',
+ 'font_families' => $mock_file,
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Testing error response returned by `load_from_json`, not the underlying error from `wp_json_file_decode`.
</span><span class="cx" style="display: block; padding: 0 10px"> $data = @$collection->get_data();
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -265,8 +289,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned with invalid json file contents.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_decode_error',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_decode_error',
</del><span class="cx" style="display: block; padding: 0 10px"> 'Incorrect error code with invalid json file contents.'
</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">@@ -274,13 +298,19 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_should_error_with_invalid_url() {
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_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">- $collection = new WP_Font_Collection( 'my-collection', 'not-a-url' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ 'my-collection',
+ array(
+ 'name' => 'Invalid collection',
+ 'font_families' => 'not-a-url',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned when invalid url is provided.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_json_missing',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_json_missing',
</del><span class="cx" style="display: block; padding: 0 10px"> 'Incorrect error code when invalid url is provided.'
</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">@@ -288,7 +318,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_should_error_with_unsuccessful_response_status() {
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_http_request', array( $this, 'mock_request_unsuccessful_response' ), 10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $collection = new WP_Font_Collection( 'my-collection', 'https://example.com/fonts/missing-collection.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ 'my-collection',
+ array(
+ 'name' => 'Missing collection',
+ 'font_families' => 'https://example.com/fonts/missing-collection.json',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'pre_http_request', array( $this, 'mock_request_unsuccessful_response' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -295,9 +331,9 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned when response is unsuccessful.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_request_error',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_request_error',
- 'Incorrect error code when response is unsuccussful.'
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'Incorrect error code when response is unsuccessful.'
</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">@@ -304,7 +340,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> public function test_should_error_with_invalid_json_from_url() {
</span><span class="cx" style="display: block; padding: 0 10px"> add_filter( 'pre_http_request', array( $this, 'mock_request_invalid_json' ), 10, 3 );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $collection = new WP_Font_Collection( 'my-collection', 'https://example.com/fonts/invalid-collection.json' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $collection = new WP_Font_Collection(
+ 'my-collection',
+ array(
+ 'name' => 'Invalid collection',
+ 'font_families' => 'https://example.com/fonts/invalid-collection.json',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px"> $data = $collection->get_data();
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> remove_filter( 'pre_http_request', array( $this, 'mock_request_invalid_json' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -311,8 +353,8 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertWPError( $data, 'Error is not returned when response is invalid json.' );
</span><span class="cx" style="display: block; padding: 0 10px"> $this->assertSame(
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ 'font_collection_decode_error',
</ins><span class="cx" style="display: block; padding: 0 10px"> $data->get_error_code(),
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- 'font_collection_decode_error',
</del><span class="cx" style="display: block; padding: 0 10px"> 'Incorrect error code when response is invalid json.'
</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="trunktestsphpunittestsfontsfontlibrarywpRestFontCollectionsControllerphp"></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-library/wpRestFontCollectionsController.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php 2024-02-21 19:24:12 UTC (rev 57685)
+++ trunk/tests/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php 2024-02-21 19:24:14 UTC (rev 57686)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -38,7 +38,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $mock_file = wp_tempnam( 'my-collection-data-' );
</span><span class="cx" style="display: block; padding: 0 10px"> file_put_contents( $mock_file, '{"name": "Mock Collection", "font_families": [ "mock" ], "categories": [ "mock" ] }' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_register_font_collection( 'mock-col-slug', $mock_file );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_register_font_collection(
+ 'mock-col-slug',
+ array(
+ 'name' => 'My collection',
+ 'font_families' => $mock_file,
+ )
+ );
</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"> public static function wpTearDownAfterClass() {
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -78,7 +84,13 @@
</span><span class="cx" style="display: block; padding: 0 10px"> $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_json' );
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( self::$admin_id );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_register_font_collection( 'invalid-collection', 'invalid-collection-file' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_register_font_collection(
+ 'invalid-collection',
+ array(
+ 'name' => 'My collection',
+ 'font_families' => 'invalid-collection-file',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request = new WP_REST_Request( 'GET', '/wp/v2/font-collections' );
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_get_server()->dispatch( $request );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -132,7 +144,13 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( self::$admin_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $slug = 'invalid-collection';
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- wp_register_font_collection( $slug, 'invalid-collection-file' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ wp_register_font_collection(
+ $slug,
+ array(
+ 'name' => 'My collection',
+ 'font_families' => 'invalid-collection-file',
+ )
+ );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> $request = new WP_REST_Request( 'GET', '/wp/v2/font-collections/' . $slug );
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_get_server()->dispatch( $request );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -139,7 +157,7 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_unregister_font_collection( $slug );
</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->assertErrorResponse( 'font_collection_json_missing', $response, 500, 'When the collection json file is invalid, the response should return an error for "font_collection_json_missing" with 500 status.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertErrorResponse( 'font_collection_json_missing', $response, 500 );
</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">@@ -150,11 +168,11 @@
</span><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( 0 );
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_get_server()->dispatch( $request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertErrorResponse( 'rest_cannot_read', $response, 401, 'The response status should be 401 for non-authenticated users.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertErrorResponse( 'rest_cannot_read', $response, 401 );
</ins><span class="cx" style="display: block; padding: 0 10px">
</span><span class="cx" style="display: block; padding: 0 10px"> wp_set_current_user( self::$editor_id );
</span><span class="cx" style="display: block; padding: 0 10px"> $response = rest_get_server()->dispatch( $request );
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">- $this->assertErrorResponse( 'rest_cannot_read', $response, 403, 'The response status should be 403 for users without the right permissions.' );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ $this->assertErrorResponse( 'rest_cannot_read', $response, 403 );
</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>