From de472fd5ca740e1ab9fd269755c24580896ddbc9 Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Tue, 27 Feb 2024 10:28:54 -0300 Subject: [PATCH] Remove the tests that no longer test the code in Gutenberg but the code from core because the classes being tested are not loaded from gutenberg but from core (#59402) Co-authored-by: matiasbenedetto Co-authored-by: getdave --- phpunit/tests/fonts/font-face/base.php | 136 --------- .../font-face/wp-font-face-tests-dataset.php | 274 ------------------ .../font-face/wpFontFace/generateAndPrint.php | 45 --- .../getFontsFromThemeJson.php | 104 ------- .../fonts/font-face/wpPrintFontFaces.php | 87 ------ 5 files changed, 646 deletions(-) delete mode 100644 phpunit/tests/fonts/font-face/base.php delete mode 100644 phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php delete mode 100644 phpunit/tests/fonts/font-face/wpFontFace/generateAndPrint.php delete mode 100644 phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php delete mode 100644 phpunit/tests/fonts/font-face/wpPrintFontFaces.php diff --git a/phpunit/tests/fonts/font-face/base.php b/phpunit/tests/fonts/font-face/base.php deleted file mode 100644 index 65d7cdd02d727..0000000000000 --- a/phpunit/tests/fonts/font-face/base.php +++ /dev/null @@ -1,136 +0,0 @@ -orig_theme_dir = $GLOBALS['wp_theme_directories']; - - // /themes is necessary as theme.php functions assume /themes is the root if there is only one root. - $GLOBALS['wp_theme_directories'] = array( WP_CONTENT_DIR . '/themes', self::$theme_root ); - - // Set up the new root. - add_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); - add_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); - add_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); - - // Clear caches. - wp_clean_themes_cache(); - unset( $GLOBALS['wp_themes'] ); - } - } - - public function tear_down() { - $this->property = array(); - - // Reset the error reporting when modified within a test. - if ( is_int( $this->error_reporting_level ) ) { - error_reporting( $this->error_reporting_level ); - $this->error_reporting_level = null; - } - - if ( self::$requires_switch_theme_fixtures ) { - $GLOBALS['wp_theme_directories'] = $this->orig_theme_dir; - remove_filter( 'theme_root', array( $this, 'filter_set_theme_root' ) ); - remove_filter( 'stylesheet_root', array( $this, 'filter_set_theme_root' ) ); - remove_filter( 'template_root', array( $this, 'filter_set_theme_root' ) ); - - wp_clean_themes_cache(); - // @core-merge: the function_exists() is not needed in Core. - if ( function_exists( 'wp_clean_theme_json_cache' ) ) { - wp_clean_theme_json_cache(); - } - - // @core-merge: start of the plugin only code block. Do not merge into Core. - if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) { - WP_Theme_JSON_Resolver_Gutenberg::clean_cached_data(); - } - if ( function_exists( '_gutenberg_clean_theme_json_caches' ) ) { - _gutenberg_clean_theme_json_caches(); - } - // @core-merge: end of the plugin only code block. - - unset( $GLOBALS['wp_themes'] ); - } - - parent::tear_down(); - } - - public function filter_set_theme_root() { - return self::$theme_root; - } -} diff --git a/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php b/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php deleted file mode 100644 index 00ae66e865a89..0000000000000 --- a/phpunit/tests/fonts/font-face/wp-font-face-tests-dataset.php +++ /dev/null @@ -1,274 +0,0 @@ - array( - 'fonts' => array( - 'Inter' => - array( - array( - 'src' => - array( - 'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf', - ), - 'font-family' => 'Inter', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '200', - ), - ), - ), - 'expected' => << array( - 'fonts' => array( - 'Inter' => - array( - array( - 'src' => - array( - 'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt,wght.ttf', - ), - 'font-family' => 'Inter', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '200', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/inter/Inter-VariableFont_slnt-Italic,wght.ttf', - ), - 'font-family' => 'Inter', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '900', - ), - ), - ), - 'expected' => << array( - 'fonts' => array( - 'DM Sans' => - array( - array( - 'src' => - array( - 'https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2', - ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '400', - ), - ), - ), - 'expected' => << array( - 'fonts' => array( - 'DM Sans' => - array( - array( - 'src' => - array( - 'https://example.org/assets/fonts/dm-sans/DMSans-Regular.woff2', - ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '400', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2', - ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '400', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/dm-sans/DMSans-Bold.woff2', - ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '700', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2', - ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '700', - ), - ), - 'IBM Plex Mono' => - array( - array( - 'src' => - array( - 'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Light.woff2', - ), - 'font-family' => 'IBM Plex Mono', - 'font-display' => 'block', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '300', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Regular.woff2', - ), - 'font-family' => 'IBM Plex Mono', - 'font-display' => 'block', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '400', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Italic.woff2', - ), - 'font-family' => 'IBM Plex Mono', - 'font-display' => 'block', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '400', - ), - array( - 'src' => - array( - 'https://example.org/assets/fonts/ibm-plex-mono/IBMPlexMono-Bold.woff2', - ), - 'font-family' => 'IBM Plex Mono', - 'font-display' => 'block', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '700', - ), - ), - ), - 'expected' => << array( - 'DM Sans' => array( - array( - 'src' => array( $uri . 'dm-sans/DMSans-Regular.woff2' ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '400', - ), - array( - 'src' => array( $uri . 'dm-sans/DMSans-Regular-Italic.woff2' ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '400', - ), - array( - 'src' => array( $uri . 'dm-sans/DMSans-Bold.woff2' ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '700', - ), - array( - 'src' => array( $uri . 'dm-sans/DMSans-Bold-Italic.woff2' ), - 'font-family' => 'DM Sans', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '700', - ), - ), - 'Source Serif Pro' => array( - array( - 'src' => array( $uri . 'source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ), - 'font-family' => 'Source Serif Pro', - 'font-stretch' => 'normal', - 'font-style' => 'normal', - 'font-weight' => '200 900', - ), - array( - 'src' => array( $uri . 'source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2' ), - 'font-family' => 'Source Serif Pro', - 'font-stretch' => 'normal', - 'font-style' => 'italic', - 'font-weight' => '200 900', - ), - ), - ), - 'font_face_styles' => <<expectOutputString( '' ); - $font_face->generate_and_print( $fonts ); - } - - /** - * @dataProvider data_should_print_given_fonts - * - * @param array $fonts Prepared fonts. - * @param string $expected Expected CSS. - */ - public function test_should_generate_and_print_given_fonts( array $fonts, $expected ) { - $font_face = new WP_Font_Face(); - $style_element = "\n"; - $expected_output = sprintf( $style_element, $expected ); - - $this->expectOutputString( $expected_output ); - $font_face->generate_and_print( $fonts ); - } -} diff --git a/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php b/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php deleted file mode 100644 index 481c451bbafa0..0000000000000 --- a/phpunit/tests/fonts/font-face/wpFontFaceResolver/getFontsFromThemeJson.php +++ /dev/null @@ -1,104 +0,0 @@ -assertIsArray( $fonts, 'Should return an array data type' ); - $this->assertEmpty( $fonts, 'Should return an empty array' ); - } - - public function test_should_return_all_fonts_from_theme() { - switch_theme( static::FONTS_THEME ); - - $actual = WP_Font_Face_Resolver::get_fonts_from_theme_json(); - $expected = $this->get_expected_fonts_for_fonts_block_theme( 'fonts' ); - $this->assertSame( $expected, $actual ); - } - - /** - * @dataProvider data_should_replace_src_file_placeholder - * - * @param string $font_name Font's name. - * @param string $font_index Font's index in the $fonts array. - * @param string $expected Expected src. - */ - public function test_should_replace_src_file_placeholder( $font_name, $font_index, $expected ) { - switch_theme( static::FONTS_THEME ); - - $fonts = WP_Font_Face_Resolver::get_fonts_from_theme_json(); - - $actual = $fonts[ $font_name ][ $font_index ]['src'][0]; - $expected = get_stylesheet_directory_uri() . $expected; - - $this->assertStringNotContainsString( 'file:./', $actual, 'Font src should not contain the "file:./" placeholder' ); - $this->assertSame( $expected, $actual, 'Font src should be an URL to its file' ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_should_replace_src_file_placeholder() { - return array( - // Theme's theme.json. - 'DM Sans: 400 normal' => array( - 'font_name' => 'DM Sans', - 'font_index' => 0, - 'expected' => '/assets/fonts/dm-sans/DMSans-Regular.woff2', - ), - 'DM Sans: 400 italic' => array( - 'font_name' => 'DM Sans', - 'font_index' => 1, - 'expected' => '/assets/fonts/dm-sans/DMSans-Regular-Italic.woff2', - ), - 'DM Sans: 700 normal' => array( - 'font_name' => 'DM Sans', - 'font_index' => 2, - 'expected' => '/assets/fonts/dm-sans/DMSans-Bold.woff2', - ), - 'DM Sans: 700 italic' => array( - 'font_name' => 'DM Sans', - 'font_index' => 3, - 'expected' => '/assets/fonts/dm-sans/DMSans-Bold-Italic.woff2', - ), - 'Source Serif Pro: 200-900 normal' => array( - 'font_name' => 'Source Serif Pro', - 'font_index' => 0, - 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2', - ), - 'Source Serif Pro: 200-900 italic' => array( - 'font_name' => 'Source Serif Pro', - 'font_index' => 1, - 'expected' => '/assets/fonts/source-serif-pro/SourceSerif4Variable-Italic.ttf.woff2', - ), - ); - } -} diff --git a/phpunit/tests/fonts/font-face/wpPrintFontFaces.php b/phpunit/tests/fonts/font-face/wpPrintFontFaces.php deleted file mode 100644 index 25b02d026e73e..0000000000000 --- a/phpunit/tests/fonts/font-face/wpPrintFontFaces.php +++ /dev/null @@ -1,87 +0,0 @@ -expectOutputString( '' ); - wp_print_font_faces(); - } - - /** - * @dataProvider data_should_print_given_fonts - * - * @param array $fonts Fonts to process. - * @param string $expected Expected CSS. - */ - public function test_should_print_given_fonts( array $fonts, $expected ) { - $expected_output = $this->get_expected_styles_output( $expected ); - - $this->expectOutputString( $expected_output ); - wp_print_font_faces( $fonts ); - } - - public function test_should_escape_tags() { - $fonts = array( - 'Source Serif Pro' => array( - array( - 'src' => array( 'http://example.com/assets/source-serif-pro/SourceSerif4Variable-Roman.ttf.woff2' ), - 'font-family' => 'Source Serif Pro', - 'font-style' => 'normal', - 'font-weight' => '200 900', - 'font-stretch' => ' - -CSS; - $this->expectOutputString( $expected_output ); - - wp_print_font_faces( $fonts ); - } - - public function test_should_print_fonts_in_merged_data() { - switch_theme( static::FONTS_THEME ); - - $expected = $this->get_expected_fonts_for_fonts_block_theme( 'font_face_styles' ); - $expected_output = $this->get_expected_styles_output( $expected ); - - $this->expectOutputString( $expected_output ); - wp_print_font_faces(); - } - - private function get_expected_styles_output( $styles ) { - $style_element = "\n"; - return sprintf( $style_element, $styles ); - } -}