From 176dd50628824f547fbf61626047bfafab6e3c29 Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Wed, 10 Jan 2024 13:00:43 -0500 Subject: [PATCH 1/5] Add ability to use data rather than a file to define font collection --- .../font-library/class-wp-font-collection.php | 9 +++++++-- .../font-library/wpFontCollection/__construct.php | 2 +- .../font-library/wpFontCollection/getData.php | 14 ++++++++++++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-collection.php b/lib/experimental/fonts/font-library/class-wp-font-collection.php index e8cc7c98fe730..336718ce54d92 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-collection.php +++ b/lib/experimental/fonts/font-library/class-wp-font-collection.php @@ -51,8 +51,8 @@ public function __construct( $config ) { throw new Exception( 'Font Collection config name is required as a non-empty string.' ); } - if ( empty( $config['src'] ) || ! is_string( $config['src'] ) ) { - throw new Exception( 'Font Collection config "src" option is required as a non-empty string.' ); + if ( ( empty( $config['src'] ) || ! is_string( $config['src'] ) ) && ( empty( $config['data'] ) ) ) { + throw new Exception( 'Font Collection config "src" option OR "data" option is required.' ); } $this->config = $config; @@ -78,6 +78,11 @@ public function get_config() { * else an instance of WP_Error on failure. */ public function get_data() { + + if ( ! empty( $this->config[ 'data' ] ) ) { + return $this->get_config(); + } + // If the src is a URL, fetch the data from the URL. if ( str_contains( $this->config['src'], 'http' ) && str_contains( $this->config['src'], '://' ) ) { if ( ! wp_http_validate_url( $this->config['src'] ) ) { diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php index 5c2b7b5c02793..21f529d71a297 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php @@ -84,7 +84,7 @@ public function data_should_throw_exception() { 'name' => 'My Collection', 'description' => 'My collection description', ), - 'Font Collection config "src" option is required as a non-empty string.', + 'Font Collection config "src" option OR "data" option is required.', ), ); diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php index 4d0b2eb92b595..08712a2dc03c5 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php @@ -98,6 +98,20 @@ public function data_should_get_data() { ), ), ), + 'with data' => array( + 'config' => array( + 'id' => 'my-collection', + 'name' => 'My Collection', + 'description' => 'My collection description', + 'data' => array( 'this is mock data' => true ), + ), + 'expected_data' => array( + 'id' => 'my-collection', + 'name' => 'My Collection', + 'description' => 'My collection description', + 'data' => array( 'this is mock data' => true ), + ), + ), ); } } From 0094034fa6caee3e951da4e49447c49df2f93638 Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Wed, 10 Jan 2024 16:30:08 -0500 Subject: [PATCH 2/5] Use slug instead of id for Font Collections --- .../font-library/class-wp-font-collection.php | 4 +-- .../font-library/class-wp-font-library.php | 36 +++++++++---------- ...ss-wp-rest-font-collections-controller.php | 6 ++-- .../fonts/font-library/font-library.php | 2 +- .../wpFontCollection/__construct.php | 6 ++-- .../font-library/wpFontCollection/getData.php | 12 +++---- .../wpFontLibrary/getFontCollection.php | 4 +-- .../wpFontLibrary/getFontCollections.php | 2 +- .../wpFontLibrary/registerFontCollection.php | 16 ++++----- .../unregisterFontCollection.php | 4 +-- .../getFontCollection.php | 8 ++--- .../getFontCollections.php | 4 +-- .../registerRoutes.php | 4 +-- 13 files changed, 54 insertions(+), 54 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-collection.php b/lib/experimental/fonts/font-library/class-wp-font-collection.php index 336718ce54d92..3ac7f33e2732d 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-collection.php +++ b/lib/experimental/fonts/font-library/class-wp-font-collection.php @@ -43,8 +43,8 @@ public function __construct( $config ) { throw new Exception( 'Font Collection config options is required as a non-empty array.' ); } - if ( empty( $config['id'] ) || ! is_string( $config['id'] ) ) { - throw new Exception( 'Font Collection config ID is required as a non-empty string.' ); + if ( empty( $config['slug'] ) || ! is_string( $config['slug'] ) ) { + throw new Exception( 'Font Collection config slug is required as a non-empty string.' ); } if ( empty( $config['name'] ) || ! is_string( $config['name'] ) ) { diff --git a/lib/experimental/fonts/font-library/class-wp-font-library.php b/lib/experimental/fonts/font-library/class-wp-font-library.php index 99de81e0bd74a..4d029fe039fec 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-library.php +++ b/lib/experimental/fonts/font-library/class-wp-font-library.php @@ -63,11 +63,11 @@ public static function get_expected_font_mime_types_per_php_version( $php_versio */ public static function register_font_collection( $config ) { $new_collection = new WP_Font_Collection( $config ); - if ( self::is_collection_registered( $config['id'] ) ) { + if ( self::is_collection_registered( $config['slug'] ) ) { $error_message = sprintf( - /* translators: %s: Font collection id. */ - __( 'Font collection with id: "%s" is already registered.', 'default' ), - $config['id'] + /* translators: %s: Font collection slug. */ + __( 'Font collection with slug: "%s" is already registered.', 'default' ), + $config['slug'] ); _doing_it_wrong( __METHOD__, @@ -76,7 +76,7 @@ public static function register_font_collection( $config ) { ); return new WP_Error( 'font_collection_registration_error', $error_message ); } - self::$collections[ $config['id'] ] = $new_collection; + self::$collections[ $config['slug'] ] = $new_collection; return $new_collection; } @@ -85,20 +85,20 @@ public static function register_font_collection( $config ) { * * @since 6.5.0 * - * @param string $collection_id Font collection ID. + * @param string $collection_slug Font collection slug. * @return bool True if the font collection was unregistered successfully and false otherwise. */ - public static function unregister_font_collection( $collection_id ) { - if ( ! self::is_collection_registered( $collection_id ) ) { + public static function unregister_font_collection( $slug ) { + if ( ! self::is_collection_registered( $slug ) ) { _doing_it_wrong( __METHOD__, - /* translators: %s: Font collection id. */ - sprintf( __( 'Font collection "%s" not found.', 'default' ), $collection_id ), + /* translators: %s: Font collection slug. */ + sprintf( __( 'Font collection "%s" not found.', 'default' ), $slug ), '6.5.0' ); return false; } - unset( self::$collections[ $collection_id ] ); + unset( self::$collections[ $slug ] ); return true; } @@ -107,11 +107,11 @@ public static function unregister_font_collection( $collection_id ) { * * @since 6.5.0 * - * @param string $collection_id Font collection ID. + * @param string $slug Font collection slug. * @return bool True if the font collection is registered and false otherwise. */ - private static function is_collection_registered( $collection_id ) { - return array_key_exists( $collection_id, self::$collections ); + private static function is_collection_registered( $slug ) { + return array_key_exists( $slug, self::$collections ); } /** @@ -130,12 +130,12 @@ public static function get_font_collections() { * * @since 6.5.0 * - * @param string $id Font collection id. + * @param string $slug Font collection slug. * @return array List of font collections. */ - public static function get_font_collection( $id ) { - if ( array_key_exists( $id, self::$collections ) ) { - return self::$collections[ $id ]; + public static function get_font_collection( $slug ) { + if ( array_key_exists( $slug, self::$collections ) ) { + return self::$collections[ $slug ]; } return new WP_Error( 'font_collection_not_found', 'Font collection not found.' ); } diff --git a/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php b/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php index 2367cba0b870a..7857dae7cdb0b 100644 --- a/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php +++ b/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php @@ -50,7 +50,7 @@ public function register_routes() { register_rest_route( $this->namespace, - '/' . $this->rest_base . '/(?P[\/\w-]+)', + '/' . $this->rest_base . '/(?P[\/\w-]+)', array( array( 'methods' => WP_REST_Server::READABLE, @@ -70,8 +70,8 @@ public function register_routes() { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_font_collection( $request ) { - $id = $request->get_param( 'id' ); - $collection = WP_Font_Library::get_font_collection( $id ); + $slug = $request->get_param( 'slug' ); + $collection = WP_Font_Library::get_font_collection( $slug ); // If the collection doesn't exist returns a 404. if ( is_wp_error( $collection ) ) { $collection->add_data( array( 'status' => 404 ) ); diff --git a/lib/experimental/fonts/font-library/font-library.php b/lib/experimental/fonts/font-library/font-library.php index 711a6bb40c282..ca920c232fae7 100644 --- a/lib/experimental/fonts/font-library/font-library.php +++ b/lib/experimental/fonts/font-library/font-library.php @@ -75,7 +75,7 @@ function wp_unregister_font_collection( $collection_id ) { } $default_font_collection = array( - 'id' => 'default-font-collection', + 'slug' => 'default-font-collection', 'name' => 'Google Fonts', 'description' => __( 'Add from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ), 'src' => 'https://s.w.org/images/fonts/16.7/collections/google-fonts-with-preview.json', diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php index 21f529d71a297..34e17d30fb859 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php @@ -17,7 +17,7 @@ public function test_should_initialize_data() { $property->setAccessible( true ); $config = array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'src' => 'my-collection-data.json', @@ -55,7 +55,7 @@ public function data_should_throw_exception() { 'description' => 'My collection description', 'src' => 'my-collection-data.json', ), - 'Font Collection config ID is required as a non-empty string.', + 'Font Collection config slug is required as a non-empty string.', ), 'no config' => array( @@ -80,7 +80,7 @@ public function data_should_throw_exception() { 'missing src' => array( array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', ), diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php index 08712a2dc03c5..62c1063697b98 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php @@ -69,13 +69,13 @@ public function data_should_get_data() { return array( 'with a file' => array( 'config' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'src' => $mock_file, ), 'expected_data' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), @@ -83,13 +83,13 @@ public function data_should_get_data() { ), 'with a url' => array( 'config' => array( - 'id' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', 'src' => 'https://localhost/fonts/mock-font-collection.json', ), 'expected_data' => array( - 'id' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', 'data' => array( @@ -100,13 +100,13 @@ public function data_should_get_data() { ), 'with data' => array( 'config' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), ), 'expected_data' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php index 00d5ca2dcb2e7..082ca89211465 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php @@ -14,7 +14,7 @@ class Tests_Fonts_WpFontLibrary_GetFontCollection extends WP_Font_Library_UnitTe public function test_should_get_font_collection() { $my_font_collection_config = array( - 'id' => 'my-font-collection', + 'slug' => 'my-font-collection', 'name' => 'My Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => path_join( __DIR__, 'my-font-collection-data.json' ), @@ -24,7 +24,7 @@ public function test_should_get_font_collection() { $this->assertInstanceOf( 'WP_Font_Collection', $font_collection ); } - public function test_should_get_no_font_collection_if_the_id_is_not_registered() { + public function test_should_get_no_font_collection_if_the_slug_is_not_registered() { $font_collection = WP_Font_Library::get_font_collection( 'not-registered-font-collection' ); $this->assertWPError( $font_collection ); } diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php index 40eacba8e18c5..a405584efccc2 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php @@ -18,7 +18,7 @@ public function test_should_get_an_empty_list() { public function test_should_get_mock_font_collection() { $my_font_collection_config = array( - 'id' => 'my-font-collection', + 'slug' => 'my-font-collection', 'name' => 'My Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => path_join( __DIR__, 'my-font-collection-data.json' ), diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php index 2569830f6bf2a..2cbaef6ff4774 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php @@ -14,7 +14,7 @@ class Tests_Fonts_WpFontLibrary_RegisterFontCollection extends WP_Font_Library_U public function test_should_register_font_collection() { $config = array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My Collection Description', 'src' => 'my-collection-data.json', @@ -23,20 +23,20 @@ public function test_should_register_font_collection() { $this->assertInstanceOf( 'WP_Font_Collection', $collection ); } - public function test_should_return_error_if_id_is_missing() { + public function test_should_return_error_if_slug_is_missing() { $config = array( 'name' => 'My Collection', 'description' => 'My Collection Description', 'src' => 'my-collection-data.json', ); $this->expectException( 'Exception' ); - $this->expectExceptionMessage( 'Font Collection config ID is required as a non-empty string.' ); + $this->expectExceptionMessage( 'Font Collection config slug is required as a non-empty string.' ); WP_Font_Library::register_font_collection( $config ); } public function test_should_return_error_if_name_is_missing() { $config = array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'description' => 'My Collection Description', 'src' => 'my-collection-data.json', ); @@ -52,15 +52,15 @@ public function test_should_return_error_if_config_is_empty() { WP_Font_Library::register_font_collection( $config ); } - public function test_should_return_error_if_id_is_repeated() { + public function test_should_return_error_if_slug_is_repeated() { $config1 = array( - 'id' => 'my-collection-1', + 'slug' => 'my-collection-1', 'name' => 'My Collection 1', 'description' => 'My Collection 1 Description', 'src' => 'my-collection-1-data.json', ); $config2 = array( - 'id' => 'my-collection-1', + 'slug' => 'my-collection-1', 'name' => 'My Collection 2', 'description' => 'My Collection 2 Description', 'src' => 'my-collection-2-data.json', @@ -72,7 +72,7 @@ public function test_should_return_error_if_id_is_repeated() { // Expects a _doing_it_wrong notice. $this->setExpectedIncorrectUsage( 'WP_Font_Library::register_font_collection' ); - // Try to register a second collection with same id. + // Try to register a second collection with same slug. $collection2 = WP_Font_Library::register_font_collection( $config2 ); $this->assertWPError( $collection2, 'A WP_Error should be returned.' ); } diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php index e6e16956814fb..62aa336abff13 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php @@ -15,7 +15,7 @@ class Tests_Fonts_WpFontLibrary_UnregisterFontCollection extends WP_Font_Library public function test_should_unregister_font_collection() { // Registers two mock font collections. $config = array( - 'id' => 'mock-font-collection-1', + 'slug' => 'mock-font-collection-1', 'name' => 'Mock Collection to be unregistered', 'description' => 'A mock font collection to be unregistered.', 'src' => 'my-collection-data.json', @@ -23,7 +23,7 @@ public function test_should_unregister_font_collection() { WP_Font_Library::register_font_collection( $config ); $config = array( - 'id' => 'mock-font-collection-2', + 'slug' => 'mock-font-collection-2', 'name' => 'Mock Collection', 'description' => 'A mock font collection.', 'src' => 'my-mock-data.json', diff --git a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollection.php b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollection.php index 94e7daaa16634..c9d003389997b 100644 --- a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollection.php @@ -25,7 +25,7 @@ public function set_up() { add_filter( 'pre_http_request', array( $this, 'mock_request' ), 10, 3 ); $config_with_file = array( - 'id' => 'one-collection', + 'slug' => 'one-collection', 'name' => 'One Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => $mock_file, @@ -33,7 +33,7 @@ public function set_up() { wp_register_font_collection( $config_with_file ); $config_with_url = array( - 'id' => 'collection-with-url', + 'slug' => 'collection-with-url', 'name' => 'Another Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => 'https://wordpress.org/fonts/mock-font-collection.json', @@ -42,7 +42,7 @@ public function set_up() { wp_register_font_collection( $config_with_url ); $config_with_non_existing_file = array( - 'id' => 'collection-with-non-existing-file', + 'slug' => 'collection-with-non-existing-file', 'name' => 'Another Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => '/home/non-existing-file.json', @@ -51,7 +51,7 @@ public function set_up() { wp_register_font_collection( $config_with_non_existing_file ); $config_with_non_existing_url = array( - 'id' => 'collection-with-non-existing-url', + 'slug' => 'collection-with-non-existing-url', 'name' => 'Another Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => 'https://non-existing-url-1234x.com.ar/fake-path/missing-file.json', diff --git a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php index 224dab07cf0b7..a1f462229e76a 100644 --- a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php +++ b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php @@ -27,7 +27,7 @@ public function test_get_font_collections() { // Add a font collection. $config = array( - 'id' => 'my-font-collection', + 'slug' => 'my-font-collection', 'name' => 'My Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => $mock_file, @@ -39,7 +39,7 @@ public function test_get_font_collections() { $data = $response->get_data(); $this->assertSame( 200, $response->get_status(), 'The response status is not 200.' ); $this->assertCount( 1, $data, 'The response data is not an array with one element.' ); - $this->assertArrayHasKey( 'id', $data[0], 'The response data does not have the key with the collection ID.' ); + $this->assertArrayHasKey( 'slug', $data[0], 'The response data does not have the key with the collection slug.' ); $this->assertArrayHasKey( 'name', $data[0], 'The response data does not have the key with the collection name.' ); } } diff --git a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/registerRoutes.php b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/registerRoutes.php index c2c019fa70a02..fb100a400fb4c 100644 --- a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/registerRoutes.php +++ b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/registerRoutes.php @@ -16,9 +16,9 @@ class Tests_Fonts_WPRESTFontCollectionsController_RegisterRoutes extends WP_Unit public function test_register_routes() { $routes = rest_get_server()->get_routes(); $this->assertCount( 1, $routes['/wp/v2/font-collections'], 'Rest server has not the collections path initialized.' ); - $this->assertCount( 1, $routes['/wp/v2/font-collections/(?P[\/\w-]+)'], 'Rest server has not the collection path initialized.' ); + $this->assertCount( 1, $routes['/wp/v2/font-collections/(?P[\/\w-]+)'], 'Rest server has not the collection path initialized.' ); $this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections'][0]['methods'], 'Rest server has not the GET method for collections intialized.' ); - $this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections/(?P[\/\w-]+)'][0]['methods'], 'Rest server has not the GET method for collection intialized.' ); + $this->assertArrayHasKey( 'GET', $routes['/wp/v2/font-collections/(?P[\/\w-]+)'][0]['methods'], 'Rest server has not the GET method for collection intialized.' ); } } From e02fc8dc9ced4685a50177a865c774d78548945d Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 09:20:31 -0300 Subject: [PATCH 3/5] format php --- .../fonts/font-library/class-wp-font-collection.php | 4 ++-- .../class-wp-rest-font-collections-controller.php | 2 +- .../font-library/wpFontCollection/__construct.php | 4 ++-- .../fonts/font-library/wpFontCollection/getData.php | 12 ++++++------ .../wpFontLibrary/registerFontCollection.php | 8 ++++---- .../wpFontLibrary/unregisterFontCollection.php | 4 ++-- .../getFontCollections.php | 2 +- 7 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/experimental/fonts/font-library/class-wp-font-collection.php b/lib/experimental/fonts/font-library/class-wp-font-collection.php index 3ac7f33e2732d..db6f4551d199f 100644 --- a/lib/experimental/fonts/font-library/class-wp-font-collection.php +++ b/lib/experimental/fonts/font-library/class-wp-font-collection.php @@ -51,7 +51,7 @@ public function __construct( $config ) { throw new Exception( 'Font Collection config name is required as a non-empty string.' ); } - if ( ( empty( $config['src'] ) || ! is_string( $config['src'] ) ) && ( empty( $config['data'] ) ) ) { + if ( ( empty( $config['src'] ) || ! is_string( $config['src'] ) ) && ( empty( $config['data'] ) ) ) { throw new Exception( 'Font Collection config "src" option OR "data" option is required.' ); } @@ -79,7 +79,7 @@ public function get_config() { */ public function get_data() { - if ( ! empty( $this->config[ 'data' ] ) ) { + if ( ! empty( $this->config['data'] ) ) { return $this->get_config(); } diff --git a/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php b/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php index 7857dae7cdb0b..3771fffae1672 100644 --- a/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php +++ b/lib/experimental/fonts/font-library/class-wp-rest-font-collections-controller.php @@ -70,7 +70,7 @@ public function register_routes() { * @return WP_REST_Response|WP_Error Response object on success, or WP_Error object on failure. */ public function get_font_collection( $request ) { - $slug = $request->get_param( 'slug' ); + $slug = $request->get_param( 'slug' ); $collection = WP_Font_Library::get_font_collection( $slug ); // If the collection doesn't exist returns a 404. if ( is_wp_error( $collection ) ) { diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php index 34e17d30fb859..380226ee8af8a 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php @@ -17,7 +17,7 @@ public function test_should_initialize_data() { $property->setAccessible( true ); $config = array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'src' => 'my-collection-data.json', @@ -80,7 +80,7 @@ public function data_should_throw_exception() { 'missing src' => array( array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', ), diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php index 62c1063697b98..11b2951efaee5 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php @@ -75,7 +75,7 @@ public function data_should_get_data() { 'src' => $mock_file, ), 'expected_data' => array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), @@ -83,13 +83,13 @@ public function data_should_get_data() { ), 'with a url' => array( 'config' => array( - 'slug' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', 'src' => 'https://localhost/fonts/mock-font-collection.json', ), 'expected_data' => array( - 'slug' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', 'data' => array( @@ -98,15 +98,15 @@ public function data_should_get_data() { ), ), ), - 'with data' => array( + 'with data' => array( 'config' => array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), ), 'expected_data' => array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php index 2cbaef6ff4774..a7ea2870957e9 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php @@ -14,7 +14,7 @@ class Tests_Fonts_WpFontLibrary_RegisterFontCollection extends WP_Font_Library_U public function test_should_register_font_collection() { $config = array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My Collection Description', 'src' => 'my-collection-data.json', @@ -36,7 +36,7 @@ public function test_should_return_error_if_slug_is_missing() { public function test_should_return_error_if_name_is_missing() { $config = array( - 'slug' => 'my-collection', + 'slug' => 'my-collection', 'description' => 'My Collection Description', 'src' => 'my-collection-data.json', ); @@ -54,13 +54,13 @@ public function test_should_return_error_if_config_is_empty() { public function test_should_return_error_if_slug_is_repeated() { $config1 = array( - 'slug' => 'my-collection-1', + 'slug' => 'my-collection-1', 'name' => 'My Collection 1', 'description' => 'My Collection 1 Description', 'src' => 'my-collection-1-data.json', ); $config2 = array( - 'slug' => 'my-collection-1', + 'slug' => 'my-collection-1', 'name' => 'My Collection 2', 'description' => 'My Collection 2 Description', 'src' => 'my-collection-2-data.json', diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php index 62aa336abff13..3c19a1d2089e7 100644 --- a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php +++ b/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php @@ -15,7 +15,7 @@ class Tests_Fonts_WpFontLibrary_UnregisterFontCollection extends WP_Font_Library public function test_should_unregister_font_collection() { // Registers two mock font collections. $config = array( - 'slug' => 'mock-font-collection-1', + 'slug' => 'mock-font-collection-1', 'name' => 'Mock Collection to be unregistered', 'description' => 'A mock font collection to be unregistered.', 'src' => 'my-collection-data.json', @@ -23,7 +23,7 @@ public function test_should_unregister_font_collection() { WP_Font_Library::register_font_collection( $config ); $config = array( - 'slug' => 'mock-font-collection-2', + 'slug' => 'mock-font-collection-2', 'name' => 'Mock Collection', 'description' => 'A mock font collection.', 'src' => 'my-mock-data.json', diff --git a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php index a1f462229e76a..0a8d24e8f392b 100644 --- a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php +++ b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController/getFontCollections.php @@ -27,7 +27,7 @@ public function test_get_font_collections() { // Add a font collection. $config = array( - 'slug' => 'my-font-collection', + 'slug' => 'my-font-collection', 'name' => 'My Font Collection', 'description' => 'Demo about how to a font collection to your WordPress Font Library.', 'src' => $mock_file, From 473cdf32a31d1360381e37a3f33766266ee6e072 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 09:28:32 -0300 Subject: [PATCH 4/5] merge file changes --- .../font-library/wpFontCollection/getConfig.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php b/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php index 03f59b6a1a6eb..513f9dcbb9529 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php @@ -34,39 +34,39 @@ public function data_should_get_config() { return array( 'with a file' => array( 'config' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'src' => $mock_file, ), 'expected_data' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', ), ), 'with a url' => array( 'config' => array( - 'id' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', 'src' => 'https://localhost/fonts/mock-font-collection.json', ), 'expected_data' => array( - 'id' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', ), ), 'with data' => array( 'config' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', 'data' => array( 'this is mock data' => true ), ), 'expected_data' => array( - 'id' => 'my-collection', + 'slug' => 'my-collection', 'name' => 'My Collection', 'description' => 'My collection description', ), From ee307104c4efc311d158c1330b7aec33ead12c3c Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Thu, 11 Jan 2024 09:29:27 -0300 Subject: [PATCH 5/5] format php --- phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php b/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php index 513f9dcbb9529..5f1f082297d41 100644 --- a/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php +++ b/phpunit/tests/fonts/font-library/wpFontCollection/getConfig.php @@ -53,7 +53,7 @@ public function data_should_get_config() { 'src' => 'https://localhost/fonts/mock-font-collection.json', ), 'expected_data' => array( - 'slug' => 'my-collection-with-url', + 'slug' => 'my-collection-with-url', 'name' => 'My Collection with URL', 'description' => 'My collection description', ),