diff --git a/phpunit/tests/fonts/font-library/fontLibraryHooks.php b/phpunit/tests/fonts/font-library/fontLibraryHooks.php
deleted file mode 100644
index 85d631ecaa45f2..00000000000000
--- a/phpunit/tests/fonts/font-library/fontLibraryHooks.php
+++ /dev/null
@@ -1,88 +0,0 @@
-post->create(
- array(
- 'post_type' => 'wp_font_family',
- )
- );
- $font_face_id = self::factory()->post->create(
- array(
- 'post_type' => 'wp_font_face',
- 'post_parent' => $font_family_id,
- )
- );
- $other_font_family_id = self::factory()->post->create(
- array(
- 'post_type' => 'wp_font_family',
- )
- );
- $other_font_face_id = self::factory()->post->create(
- array(
- 'post_type' => 'wp_font_face',
- 'post_parent' => $other_font_family_id,
- )
- );
-
- wp_delete_post( $font_family_id, true );
-
- $this->assertNull( get_post( $font_face_id ), 'Font face post should also have been deleted.' );
- $this->assertNotNull( get_post( $other_font_face_id ), 'The other post should exist.' );
- }
-
- public function test_deleting_font_faces_deletes_associated_font_files() {
- list( $font_face_id, $font_path ) = $this->create_font_face_with_file( 'OpenSans-Regular.woff2' );
- list( , $other_font_path ) = $this->create_font_face_with_file( 'OpenSans-Regular.ttf' );
-
- wp_delete_post( $font_face_id, true );
-
- $this->assertFalse( file_exists( $font_path ), 'The font file should have been deleted when the post was deleted.' );
- $this->assertTrue( file_exists( $other_font_path ), 'The other font file should exist.' );
- }
-
- protected function create_font_face_with_file( $filename ) {
- $font_face_id = self::factory()->post->create(
- array(
- 'post_type' => 'wp_font_face',
- )
- );
-
- $font_file = $this->upload_font_file( $filename );
-
- // Make sure the font file uploaded successfully.
- $this->assertFalse( $font_file['error'] );
-
- $font_path = $font_file['file'];
- $font_filename = basename( $font_path );
- add_post_meta( $font_face_id, '_wp_font_face_file', $font_filename );
-
- return array( $font_face_id, $font_path );
- }
-
- protected function upload_font_file( $font_filename ) {
- // @core-merge Use `DIR_TESTDATA` instead of `GUTENBERG_DIR_TESTDATA`.
- $font_file_path = GUTENBERG_DIR_TESTDATA . 'fonts/' . $font_filename;
-
- add_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );
- add_filter( 'upload_dir', 'wp_get_font_dir' );
- $font_file = wp_upload_bits(
- $font_filename,
- null,
- file_get_contents( $font_file_path )
- );
- remove_filter( 'upload_dir', 'wp_get_font_dir' );
- remove_filter( 'upload_mimes', array( 'WP_Font_Utils', 'get_allowed_font_mime_types' ) );
-
- return $font_file;
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php b/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php
deleted file mode 100644
index a0693ce3414565..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontCollection/__construct.php
+++ /dev/null
@@ -1,26 +0,0 @@
-setExpectedIncorrectUsage( 'WP_Font_Collection::__construct' );
- $mock_collection_data = array(
- 'name' => 'Test Collection',
- 'font_families' => array( 'mock ' ),
- );
-
- $collection = new WP_Font_Collection( 'slug with spaces', $mock_collection_data );
-
- $this->assertSame( 'slug-with-spaces', $collection->slug, 'Slug is not sanitized.' );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php b/phpunit/tests/fonts/font-library/wpFontCollection/getData.php
deleted file mode 100644
index 1cb16e271db61a..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontCollection/getData.php
+++ /dev/null
@@ -1,358 +0,0 @@
-get_data();
-
- $this->assertSame( $slug, $collection->slug, 'The slug should match.' );
- $this->assertSame( $expected_data, $data, 'The collection data should match.' );
- }
-
- /**
- * @dataProvider data_create_font_collection
- *
- * @param string $slug Font collection slug.
- * @param array $config Font collection config.
- * @param array $expected_data Expected collection data.
- */
- public function test_should_get_data_from_json_file( $slug, $config, $expected_data ) {
- $mock_file = wp_tempnam( 'my-collection-data-' );
- file_put_contents( $mock_file, wp_json_encode( $config ) );
-
- $collection = new WP_Font_Collection( $slug, $mock_file );
- $data = $collection->get_data();
-
- $this->assertSame( $slug, $collection->slug, 'The slug should match.' );
- $this->assertSame( $expected_data, $data, 'The collection data should match.' );
- }
-
- /**
- * @dataProvider data_create_font_collection
- *
- * @param string $slug Font collection slug.
- * @param array $config Font collection config.
- * @param array $expected_data Expected collection data.
- */
- public function test_should_get_data_from_json_url( $slug, $config, $expected_data ) {
- add_filter( 'pre_http_request', array( $this, 'mock_request' ), 10, 3 );
-
- self::$mock_collection_data = $config;
- $collection = new WP_Font_Collection( $slug, 'https://localhost/fonts/mock-font-collection.json' );
- $data = $collection->get_data();
-
- remove_filter( 'pre_http_request', array( $this, 'mock_request' ) );
-
- $this->assertSame( $slug, $collection->slug, 'The slug should match.' );
- $this->assertSame( $expected_data, $data, 'The collection data should match.' );
- }
-
- /**
- * Data provider.
- *
- * @return array
- */
- public function data_create_font_collection() {
- return array(
-
- 'font collection with required data' => array(
- 'slug' => 'my-collection',
- 'config' => array(
- 'name' => 'My Collection',
- 'font_families' => array( array() ),
- ),
- 'expected_data' => array(
- 'description' => '',
- 'categories' => array(),
- 'name' => 'My Collection',
- 'font_families' => array( array() ),
- ),
- ),
-
- 'font collection with all data' => array(
- 'slug' => 'my-collection',
- 'config' => array(
- 'name' => 'My Collection',
- 'description' => 'My collection description',
- 'font_families' => array( array() ),
- 'categories' => array(),
- ),
- 'expected_data' => array(
- 'description' => 'My collection description',
- 'categories' => array(),
- 'name' => 'My Collection',
- 'font_families' => array( array() ),
- ),
- ),
-
- 'font collection with risky data' => array(
- 'slug' => 'my-collection',
- 'config' => array(
- 'name' => 'My Collection',
- 'description' => 'My collection description',
- 'font_families' => array(
- array(
- 'font_family_settings' => array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'slug' => 'open-sans',
- 'name' => 'Open Sans',
- 'fontFace' => array(
- array(
- 'fontFamily' => 'Open Sans',
- 'fontStyle' => 'normal',
- 'fontWeight' => '400',
- 'src' => 'https://example.com/src-as-string.ttf?a=',
- ),
- array(
- 'fontFamily' => 'Open Sans',
- 'fontStyle' => 'normal',
- 'fontWeight' => '400',
- 'src' => array(
- 'https://example.com/src-as-array.woff2?a=',
- 'https://example.com/src-as-array.ttf',
- ),
- ),
- ),
- 'unwanted_property' => 'potentially evil value',
- ),
- 'categories' => array( 'sans-serif' ),
- ),
- ),
- 'categories' => array(
- array(
- 'name' => 'Mock col',
- 'slug' => 'mock-col',
- 'unwanted_property' => 'potentially evil value',
- ),
- ),
- 'unwanted_property' => 'potentially evil value',
- ),
- 'expected_data' => array(
- 'description' => 'My collection description',
- 'categories' => array(
- array(
- 'name' => 'Mock col',
- 'slug' => 'mock-colalertxss',
- ),
- ),
- 'name' => 'My Collection',
- 'font_families' => array(
- array(
- 'font_family_settings' => array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'slug' => 'open-sans',
- 'name' => 'Open Sans',
- 'fontFace' => array(
- array(
- 'fontFamily' => 'Open Sans',
- 'fontStyle' => 'normal',
- 'fontWeight' => '400',
- 'src' => 'https://example.com/src-as-string.ttf?a=',
- ),
- array(
- 'fontFamily' => 'Open Sans',
- 'fontStyle' => 'normal',
- 'fontWeight' => '400',
- 'src' => array(
- 'https://example.com/src-as-array.woff2?a=',
- 'https://example.com/src-as-array.ttf',
- ),
- ),
- ),
- ),
- 'categories' => array( 'sans-serifalertxss' ),
- ),
- ),
- ),
- ),
-
- );
- }
-
- /**
- * @dataProvider data_should_error_when_missing_properties
- *
- * @param array $config Font collection config.
- */
- public function test_should_error_when_missing_properties( $config ) {
- $this->setExpectedIncorrectUsage( 'WP_Font_Collection::sanitize_and_validate_data' );
-
- $collection = new WP_Font_Collection( 'my-collection', $config );
- $data = $collection->get_data();
-
- $this->assertWPError( $data, 'Error is not returned when property is missing or invalid.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_missing_property',
- 'Incorrect error code when property is missing or invalid.'
- );
- }
-
- /**
- * Data provider.
- *
- * @return array
- */
- public function data_should_error_when_missing_properties() {
- return array(
- 'missing name' => array(
- 'config' => array(
- 'font_families' => array( 'mock' ),
- ),
- ),
- 'empty name' => array(
- 'config' => array(
- 'name' => '',
- 'font_families' => array( 'mock' ),
- ),
- ),
- 'missing font_families' => array(
- 'config' => array(
- 'name' => 'My Collection',
- ),
- ),
- 'empty font_families' => array(
- 'config' => array(
- 'name' => 'My Collection',
- 'font_families' => array(),
- ),
- ),
- );
- }
-
- public function test_should_error_with_invalid_json_file_path() {
- $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_json' );
-
- $collection = new WP_Font_Collection( 'my-collection', 'non-existing.json' );
- $data = $collection->get_data();
-
- $this->assertWPError( $data, 'Error is not returned when invalid file path is provided.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_json_missing',
- 'Incorrect error code when invalid file path is provided.'
- );
- }
-
- public function test_should_error_with_invalid_json_from_file() {
- $mock_file = wp_tempnam( 'my-collection-data-' );
- file_put_contents( $mock_file, 'invalid-json' );
-
- $collection = new WP_Font_Collection( 'my-collection', $mock_file );
-
- // phpcs:ignore WordPress.PHP.NoSilencedErrors.Discouraged -- Testing error response returned by `load_from_json`, not the underlying error from `wp_json_file_decode`.
- $data = @$collection->get_data();
-
- $this->assertWPError( $data, 'Error is not returned with invalid json file contents.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_decode_error',
- 'Incorrect error code with invalid json file contents.'
- );
- }
-
- public function test_should_error_with_invalid_url() {
- $this->setExpectedIncorrectUsage( 'WP_Font_Collection::load_from_json' );
-
- $collection = new WP_Font_Collection( 'my-collection', 'not-a-url' );
- $data = $collection->get_data();
-
- $this->assertWPError( $data, 'Error is not returned when invalid url is provided.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_json_missing',
- 'Incorrect error code when invalid url is provided.'
- );
- }
-
- public function test_should_error_with_unsuccessful_response_status() {
- add_filter( 'pre_http_request', array( $this, 'mock_request_unsuccessful_response' ), 10, 3 );
-
- $collection = new WP_Font_Collection( 'my-collection', 'https://localhost/fonts/missing-collection.json' );
- $data = $collection->get_data();
-
- remove_filter( 'pre_http_request', array( $this, 'mock_request_unsuccessful_response' ) );
-
- $this->assertWPError( $data, 'Error is not returned when response is unsuccessful.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_request_error',
- 'Incorrect error code when response is unsuccussful.'
- );
- }
-
- public function test_should_error_with_invalid_json_from_url() {
- add_filter( 'pre_http_request', array( $this, 'mock_request_invalid_json' ), 10, 3 );
-
- $collection = new WP_Font_Collection( 'my-collection', 'https://localhost/fonts/invalid-collection.json' );
- $data = $collection->get_data();
-
- remove_filter( 'pre_http_request', array( $this, 'mock_request_invalid_json' ) );
-
- $this->assertWPError( $data, 'Error is not returned when response is invalid json.' );
- $this->assertSame(
- $data->get_error_code(),
- 'font_collection_decode_error',
- 'Incorrect error code when response is invalid json.'
- );
- }
-
- public function mock_request( $preempt, $args, $url ) {
- if ( 'https://localhost/fonts/mock-font-collection.json' !== $url ) {
- return false;
- }
-
- return array(
- 'body' => wp_json_encode( self::$mock_collection_data ),
- 'response' => array(
- 'code' => 200,
- ),
- );
- }
-
- public function mock_request_unsuccessful_response( $preempt, $args, $url ) {
- if ( 'https://localhost/fonts/missing-collection.json' !== $url ) {
- return false;
- }
-
- return array(
- 'body' => '',
- 'response' => array(
- 'code' => 404,
- ),
- );
- }
-
- public function mock_request_invalid_json( $preempt, $args, $url ) {
- if ( 'https://localhost/fonts/invalid-collection.json' !== $url ) {
- return false;
- }
-
- return array(
- 'body' => 'invalid',
- 'response' => array(
- 'code' => 200,
- ),
- );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/base.php b/phpunit/tests/fonts/font-library/wpFontLibrary/base.php
deleted file mode 100644
index 135329e5add73a..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontLibrary/base.php
+++ /dev/null
@@ -1,25 +0,0 @@
-get_font_collections();
- foreach ( $collections as $slug => $collection ) {
- WP_Font_Library::get_instance()->unregister_font_collection( $slug );
- }
- }
-
- public function set_up() {
- parent::set_up();
- $this->reset_font_collections();
- }
-
- public function tear_down() {
- parent::tear_down();
- $this->reset_font_collections();
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php
deleted file mode 100644
index 675efe81aec59b..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollection.php
+++ /dev/null
@@ -1,30 +0,0 @@
- 'Test Collection',
- 'font_families' => array( 'mock' ),
- );
-
- wp_register_font_collection( 'my-font-collection', $mock_collection_data );
- $font_collection = WP_Font_Library::get_instance()->get_font_collection( 'my-font-collection' );
- $this->assertInstanceOf( 'WP_Font_Collection', $font_collection );
- }
-
- public function test_should_get_no_font_collection_if_the_slug_is_not_registered() {
- $font_collection = WP_Font_Library::get_instance()->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
deleted file mode 100644
index f5ca6389b8ff51..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontLibrary/getFontCollections.php
+++ /dev/null
@@ -1,34 +0,0 @@
-get_font_collections();
- $this->assertEmpty( $font_collections, 'Should return an empty array.' );
- }
-
- public function test_should_get_mock_font_collection() {
- $my_font_collection_config = array(
- 'name' => 'My Font Collection',
- 'description' => 'Demo about how to a font collection to your WordPress Font Library.',
- 'font_families' => array( 'mock' ),
- );
-
- WP_Font_Library::get_instance()->register_font_collection( 'my-font-collection', $my_font_collection_config );
-
- $font_collections = WP_Font_Library::get_instance()->get_font_collections();
- $this->assertNotEmpty( $font_collections, 'Should return an array of font collections.' );
- $this->assertCount( 1, $font_collections, 'Should return an array with one font collection.' );
- $this->assertArrayHasKey( 'my-font-collection', $font_collections, 'The array should have the key of the registered font collection id.' );
- $this->assertInstanceOf( 'WP_Font_Collection', $font_collections['my-font-collection'], 'The value of the array $font_collections[id] should be an instance of WP_Font_Collection class.' );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php
deleted file mode 100644
index d3b0f126e2e7e1..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontLibrary/registerFontCollection.php
+++ /dev/null
@@ -1,40 +0,0 @@
- 'My Collection',
- 'font_families' => array( 'mock' ),
- );
-
- $collection = WP_Font_Library::get_instance()->register_font_collection( 'my-collection', $config );
- $this->assertInstanceOf( 'WP_Font_Collection', $collection );
- }
-
- public function test_should_return_error_if_slug_is_repeated() {
- $mock_collection_data = array(
- 'name' => 'Test Collection',
- 'font_families' => array( 'mock' ),
- );
-
- // Register first collection.
- $collection1 = WP_Font_Library::get_instance()->register_font_collection( 'my-collection-1', $mock_collection_data );
- $this->assertInstanceOf( 'WP_Font_Collection', $collection1, 'A collection should be registered.' );
-
- // Expects a _doing_it_wrong notice.
- $this->setExpectedIncorrectUsage( 'WP_Font_Library::register_font_collection' );
-
- // Try to register a second collection with same slug.
- WP_Font_Library::get_instance()->register_font_collection( 'my-collection-1', $mock_collection_data );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php b/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php
deleted file mode 100644
index ddb0fa91c1d609..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontLibrary/unregisterFontCollection.php
+++ /dev/null
@@ -1,46 +0,0 @@
- 'Test Collection',
- 'font_families' => array( 'mock' ),
- );
-
- // Registers two mock font collections.
- WP_Font_Library::get_instance()->register_font_collection( 'mock-font-collection-1', $mock_collection_data );
- WP_Font_Library::get_instance()->register_font_collection( 'mock-font-collection-2', $mock_collection_data );
-
- // Unregister mock font collection.
- WP_Font_Library::get_instance()->unregister_font_collection( 'mock-font-collection-1' );
- $collections = WP_Font_Library::get_instance()->get_font_collections();
- $this->assertArrayNotHasKey( 'mock-font-collection-1', $collections, 'Font collection was not unregistered.' );
- $this->assertArrayHasKey( 'mock-font-collection-2', $collections, 'Font collection was unregistered by mistake.' );
-
- // Unregisters remaining mock font collection.
- WP_Font_Library::get_instance()->unregister_font_collection( 'mock-font-collection-2' );
- $collections = WP_Font_Library::get_instance()->get_font_collections();
- $this->assertArrayNotHasKey( 'mock-font-collection-2', $collections, 'Mock font collection was not unregistered.' );
-
- // Checks that all font collections were unregistered.
- $this->assertEmpty( $collections, 'Font collections were not unregistered.' );
- }
-
- public function unregister_non_existing_collection() {
- // Unregisters non-existing font collection.
- WP_Font_Library::get_instance()->unregister_font_collection( 'non-existing-collection' );
- $collections = WP_Font_Library::get_instance()->get_font_collections();
- $this->assertEmpty( $collections, 'No collections should be registered.' );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontUtils/getFontFaceSlug.php b/phpunit/tests/fonts/font-library/wpFontUtils/getFontFaceSlug.php
deleted file mode 100644
index de0b02e63185ed..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontUtils/getFontFaceSlug.php
+++ /dev/null
@@ -1,92 +0,0 @@
-assertSame( $expected_slug, $slug );
- }
-
- /**
- * Data provider.
- *
- * @return array
- */
- public function data_get_font_face_slug_normalizes_values() {
- return array(
- 'Sets defaults' => array(
- 'settings' => array(
- 'fontFamily' => 'Open Sans',
- ),
- 'expected_slug' => 'open sans;normal;400;100%;U+0-10FFFF',
- ),
- 'Converts normal weight to 400' => array(
- 'settings' => array(
- 'fontFamily' => 'Open Sans',
- 'fontWeight' => 'normal',
- ),
- 'expected_slug' => 'open sans;normal;400;100%;U+0-10FFFF',
- ),
- 'Converts bold weight to 700' => array(
- 'settings' => array(
- 'fontFamily' => 'Open Sans',
- 'fontWeight' => 'bold',
- ),
- 'expected_slug' => 'open sans;normal;700;100%;U+0-10FFFF',
- ),
- 'Converts normal font-stretch to 100%' => array(
- 'settings' => array(
- 'fontFamily' => 'Open Sans',
- 'fontStretch' => 'normal',
- ),
- 'expected_slug' => 'open sans;normal;400;100%;U+0-10FFFF',
- ),
- 'Removes double quotes from fontFamilies' => array(
- 'settings' => array(
- 'fontFamily' => '"Open Sans"',
- ),
- 'expected_slug' => 'open sans;normal;400;100%;U+0-10FFFF',
- ),
- 'Removes single quotes from fontFamilies' => array(
- 'settings' => array(
- 'fontFamily' => "'Open Sans'",
- ),
- 'expected_slug' => 'open sans;normal;400;100%;U+0-10FFFF',
- ),
- 'Removes spaces between comma separated font families' => array(
- 'settings' => array(
- 'fontFamily' => 'Open Sans, serif',
- ),
- 'expected_slug' => 'open sans,serif;normal;400;100%;U+0-10FFFF',
- ),
- 'Removes tabs between comma separated font families' => array(
- 'settings' => array(
- 'fontFamily' => "Open Sans,\tserif",
- ),
- 'expected_slug' => 'open sans,serif;normal;400;100%;U+0-10FFFF',
- ),
- 'Removes new lines between comma separated font families' => array(
- 'settings' => array(
- 'fontFamily' => "Open Sans,\nserif",
- ),
- 'expected_slug' => 'open sans,serif;normal;400;100%;U+0-10FFFF',
- ),
- );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFontFamily.php b/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFontFamily.php
deleted file mode 100644
index 71511331c65dcb..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFontFamily.php
+++ /dev/null
@@ -1,63 +0,0 @@
-assertSame(
- $expected,
- WP_Font_Utils::sanitize_font_family(
- $font_family
- )
- );
- }
-
- /**
- * Data provider.
- *
- * @return array
- */
- public function data_should_sanitize_font_family() {
- return array(
- 'data_families_with_spaces_and_numbers' => array(
- 'font_family' => 'Rock 3D , Open Sans,serif',
- 'expected' => '"Rock 3D", "Open Sans", serif',
- ),
- 'data_single_font_family' => array(
- 'font_family' => 'Rock 3D',
- 'expected' => '"Rock 3D"',
- ),
- 'data_no_spaces' => array(
- 'font_family' => 'Rock3D',
- 'expected' => 'Rock3D',
- ),
- 'data_many_spaces_and_existing_quotes' => array(
- 'font_family' => 'Rock 3D serif, serif,sans-serif, "Open Sans"',
- 'expected' => '"Rock 3D serif", serif, sans-serif, "Open Sans"',
- ),
- 'data_empty_family' => array(
- 'font_family' => ' ',
- 'expected' => '',
- ),
- 'data_font_family_with_whitespace_tags_new_lines' => array(
- 'font_family' => " Rock 3D\n ",
- 'expected' => '"Rock 3D"',
- ),
- );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFromSchema.php b/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFromSchema.php
deleted file mode 100644
index 88983fe15a14ec..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontUtils/sanitizeFromSchema.php
+++ /dev/null
@@ -1,310 +0,0 @@
-assertSame( $result, $expected );
- }
-
- public function data_sanitize_from_schema() {
- return array(
- 'One level associative array' => array(
- 'data' => array(
- 'slug' => 'open - sans',
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json',
- ),
- 'schema' => array(
- 'slug' => 'sanitize_title',
- 'fontFamily' => 'sanitize_text_field',
- 'src' => 'sanitize_url',
- ),
- 'expected' => array(
- 'slug' => 'open-sansalertxss',
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- ),
- ),
-
- 'Nested associative arrays' => array(
- 'data' => array(
- 'slug' => 'open - sans',
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json',
- 'nested' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'nested2' => array(
- 'key3' => 'value3',
- 'key4' => 'value4',
- ),
- ),
- ),
- 'schema' => array(
- 'slug' => 'sanitize_title',
- 'fontFamily' => 'sanitize_text_field',
- 'src' => 'sanitize_url',
- 'nested' => array(
- 'key1' => 'sanitize_text_field',
- 'key2' => 'sanitize_text_field',
- 'nested2' => array(
- 'key3' => 'sanitize_text_field',
- 'key4' => 'sanitize_text_field',
- ),
- ),
- ),
- 'expected' => array(
- 'slug' => 'open-sansalertxss',
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- 'nested' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'nested2' => array(
- 'key3' => 'value3',
- 'key4' => 'value4',
- ),
- ),
- ),
- ),
-
- 'Indexed arrays' => array(
- 'data' => array(
- 'slug' => 'oPeN SaNs',
- 'enum' => array(
- 'value1',
- 'value2',
- 'value3',
- ),
- ),
- 'schema' => array(
- 'slug' => 'sanitize_title',
- 'enum' => array( 'sanitize_text_field' ),
- ),
- 'expected' => array(
- 'slug' => 'open-sans',
- 'enum' => array( 'value1', 'value2', 'value3' ),
- ),
- ),
-
- 'Nested indexed arrays' => array(
- 'data' => array(
- 'slug' => 'OPEN-SANS',
- 'name' => 'Open Sans',
- 'fontFace' => array(
- array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- ),
- array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- ),
- ),
- ),
- 'schema' => array(
- 'slug' => 'sanitize_title',
- 'name' => 'sanitize_text_field',
- 'fontFace' => array(
- array(
- 'fontFamily' => 'sanitize_text_field',
- 'src' => 'sanitize_url',
- ),
- ),
- ),
- 'expected' => array(
- 'slug' => 'open-sans',
- 'name' => 'Open Sans',
- 'fontFace' => array(
- array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- ),
- array(
- 'fontFamily' => 'Open Sans, sans-serif',
- 'src' => 'https://wordpress.org/example.json/stylescriptalert(xss)/script',
- ),
- ),
- ),
- ),
-
- 'Custom sanitization function' => array(
- 'data' => array(
- 'key1' => 'abc123edf456ghi789',
- 'key2' => 'value2',
- ),
- 'schema' => array(
- 'key1' => function ( $value ) {
- // Remove the six first character.
- return substr( $value, 6 );
- },
- 'key2' => function ( $value ) {
- // Capitalize the value.
- return strtoupper( $value );
- },
- ),
- 'expected' => array(
- 'key1' => 'edf456ghi789',
- 'key2' => 'VALUE2',
- ),
- ),
-
- 'Null as schema value' => array(
- 'data' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'nested' => array(
- 'key3' => 'value3',
- 'key4' => 'value4',
- ),
- ),
- 'schema' => array(
- 'key1' => null,
- 'key2' => 'sanitize_text_field',
- 'nested' => null,
- ),
- 'expected' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'nested' => array(
- 'key3' => 'value3',
- 'key4' => 'value4',
- ),
- ),
- ),
-
- 'Keys to remove' => array(
- 'data' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'unwanted1' => 'value',
- 'unwanted2' => 'value',
- 'nestedAssociative' => array(
- 'key5' => 'value5',
- 'unwanted3' => 'value',
- ),
- 'nestedIndexed' => array(
- array(
- 'key6' => 'value7',
- 'unwanted4' => 'value',
- ),
- array(
- 'key6' => 'value7',
- 'unwanted5' => 'value',
- ),
- ),
-
- ),
- 'schema' => array(
- 'key1' => 'sanitize_text_field',
- 'key2' => 'sanitize_text_field',
- 'nestedAssociative' => array(
- 'key5' => 'sanitize_text_field',
- ),
- 'nestedIndexed' => array(
- array(
- 'key6' => 'sanitize_text_field',
- ),
- ),
- ),
- 'expected' => array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- 'nestedAssociative' => array(
- 'key5' => 'value5',
- ),
- 'nestedIndexed' => array(
- array(
- 'key6' => 'value7',
- ),
- array(
- 'key6' => 'value7',
- ),
- ),
- ),
- ),
-
- 'With empty structure' => array(
- 'data' => array(
- 'slug' => 'open-sans',
- 'nested' => array(
- 'key1' => 'value',
- 'nested2' => array(
- 'key2' => 'value',
- 'nested3' => array(
- 'nested4' => array(),
- ),
- ),
- ),
- ),
- 'schema' => array(
- 'slug' => 'sanitize_title',
- 'nested' => array(
- 'key1' => 'sanitize_text_field',
- 'nested2' => array(
- 'key2' => 'sanitize_text_field',
- 'nested3' => array(
- 'key3' => 'sanitize_text_field',
- 'nested4' => array(
- 'key4' => 'sanitize_text_field',
- ),
- ),
- ),
- ),
- ),
- 'expected' => array(
- 'slug' => 'open-sans',
- 'nested' => array(
- 'key1' => 'value',
- 'nested2' => array(
- 'key2' => 'value',
- ),
- ),
- ),
- ),
- );
- }
-
- public function test_sanitize_from_schema_with_invalid_data() {
- $data = 'invalid data';
- $schema = array(
- 'key1' => 'sanitize_text_field',
- 'key2' => 'sanitize_text_field',
- );
-
- $result = WP_Font_Utils::sanitize_from_schema( $data, $schema );
-
- $this->assertSame( $result, array() );
- }
-
-
- public function test_sanitize_from_schema_with_invalid_schema() {
- $data = array(
- 'key1' => 'value1',
- 'key2' => 'value2',
- );
- $schema = 'invalid schema';
-
- $result = WP_Font_Utils::sanitize_from_schema( $data, $schema );
-
- $this->assertSame( $result, array() );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpFontsDir.php b/phpunit/tests/fonts/font-library/wpFontsDir.php
deleted file mode 100644
index a8f79888315bdf..00000000000000
--- a/phpunit/tests/fonts/font-library/wpFontsDir.php
+++ /dev/null
@@ -1,72 +0,0 @@
- path_join( WP_CONTENT_DIR, 'fonts' ),
- 'url' => content_url( 'fonts' ),
- 'subdir' => '',
- 'basedir' => path_join( WP_CONTENT_DIR, 'fonts' ),
- 'baseurl' => content_url( 'fonts' ),
- 'error' => false,
- );
- }
-
- public function test_fonts_dir() {
- $font_dir = wp_get_font_dir();
-
- $this->assertSame( $font_dir, static::$dir_defaults );
- }
-
- public function test_fonts_dir_with_filter() {
- // Define a callback function to pass to the filter.
- function set_new_values( $defaults ) {
- $defaults['path'] = '/custom-path/fonts/my-custom-subdir';
- $defaults['url'] = 'http://example.com/custom-path/fonts/my-custom-subdir';
- $defaults['subdir'] = 'my-custom-subdir';
- $defaults['basedir'] = '/custom-path/fonts';
- $defaults['baseurl'] = 'http://example.com/custom-path/fonts';
- $defaults['error'] = false;
- return $defaults;
- }
-
- // Add the filter.
- add_filter( 'font_dir', 'set_new_values' );
-
- // Gets the fonts dir.
- $font_dir = wp_get_font_dir();
-
- $expected = array(
- 'path' => '/custom-path/fonts/my-custom-subdir',
- 'url' => 'http://example.com/custom-path/fonts/my-custom-subdir',
- 'subdir' => 'my-custom-subdir',
- 'basedir' => '/custom-path/fonts',
- 'baseurl' => 'http://example.com/custom-path/fonts',
- 'error' => false,
- );
-
- // Remove the filter.
- remove_filter( 'font_dir', 'set_new_values' );
-
- $this->assertSame( $expected, $font_dir, 'The wp_get_font_dir() method should return the expected values.' );
-
- // Gets the fonts dir.
- $font_dir = wp_get_font_dir();
-
- $this->assertSame( static::$dir_defaults, $font_dir, 'The wp_get_font_dir() method should return the default values.' );
- }
-}
diff --git a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php
index 60f50e503fdbe4..df2daccb5d24f0 100644
--- a/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php
+++ b/phpunit/tests/fonts/font-library/wpRestFontCollectionsController.php
@@ -19,6 +19,12 @@ class Tests_REST_WpRestFontCollectionsController extends WP_Test_REST_Controller
public static function wpSetUpBeforeClass( WP_UnitTest_Factory $factory ) {
+ // Clear the font collections.
+ $collections = WP_Font_Library::get_instance()->get_font_collections();
+ foreach ( $collections as $slug => $collection ) {
+ WP_Font_Library::get_instance()->unregister_font_collection( $slug );
+ }
+
self::$admin_id = $factory->user->create(
array(
'role' => 'administrator',