From 987acb5954b06d1f34ccb4c1a9a2b67410564f65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Zi=C3=83=C2=B3=C3=85=E2=80=9Akowski?= Date: Mon, 24 May 2021 09:49:48 +0000 Subject: [PATCH] Editor: Fix failing unit test for i18n support in `theme.json` As part of the change, I also did some code reorganization to match with how other test fixtures are handled. Follow-up [50959]. See #52991. git-svn-id: https://develop.svn.wordpress.org/trunk@50960 602fd350-edb4-49c9-b593-d223f7449a82 --- .../data/languages/themes/fse-pl_PL.mo | Bin 0 -> 734 bytes .../data/languages/themes/fse-pl_PL.po | 0 tests/phpunit/data/themedir1/fse/index.php | 4 +++ .../blocks => }/data/themedir1/fse/style.css | 0 .../blocks => }/data/themedir1/fse/theme.json | 0 .../class-wp-theme-json-resolver.php} | 16 +++++++++-- .../class-wp-theme-json.php} | 27 +++++++++++++++++- tests/phpunit/tests/theme/themeDir.php | 1 + 8 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 tests/phpunit/data/languages/themes/fse-pl_PL.mo rename tests/phpunit/{tests/blocks => }/data/languages/themes/fse-pl_PL.po (100%) create mode 100644 tests/phpunit/data/themedir1/fse/index.php rename tests/phpunit/{tests/blocks => }/data/themedir1/fse/style.css (100%) rename tests/phpunit/{tests/blocks => }/data/themedir1/fse/theme.json (100%) rename tests/phpunit/tests/{blocks/class-wp-theme-json-resolver-test.php => theme/class-wp-theme-json-resolver.php} (93%) rename tests/phpunit/tests/{blocks/class-wp-theme-json-test.php => theme/class-wp-theme-json.php} (97%) diff --git a/tests/phpunit/data/languages/themes/fse-pl_PL.mo b/tests/phpunit/data/languages/themes/fse-pl_PL.mo new file mode 100644 index 0000000000000000000000000000000000000000..0ff620e64ae4adbb89fd2f1ea31f2ea65bab72e1 GIT binary patch literal 734 zcmYjO!EVz)5M3Z}@CC$)1Bc~;KxBjM6sfYwg|vl2Dl8HZ2PA9j46$2#*X(X+!wo(G zi7(*-Cl08;!KWaePl@D6CK2Cf4ifE&PP;4bhL z_rxx8WJSFlX^#KrlVXuOHeOn%EAFVO zOX;XR`b<|;%LR35mKc3RnG^eS@rH~ow2HWwycDnKW6?0NgXV~bei#UUD1t{k7)F8r zzz=-in@F`-VqC=QGEFAl!T!PSW=t^fy|Gq~loPX6jZ=lmRfP^ Rj8-eYIQ#PZ`-!3>_79nA*+&2X literal 0 HcmV?d00001 diff --git a/tests/phpunit/tests/blocks/data/languages/themes/fse-pl_PL.po b/tests/phpunit/data/languages/themes/fse-pl_PL.po similarity index 100% rename from tests/phpunit/tests/blocks/data/languages/themes/fse-pl_PL.po rename to tests/phpunit/data/languages/themes/fse-pl_PL.po diff --git a/tests/phpunit/data/themedir1/fse/index.php b/tests/phpunit/data/themedir1/fse/index.php new file mode 100644 index 0000000000..c674182076 --- /dev/null +++ b/tests/phpunit/data/themedir1/fse/index.php @@ -0,0 +1,4 @@ +theme_root = realpath( __DIR__ . '/data/themedir1' ); + $this->theme_root = realpath( DIR_TESTDATA . '/themedir1' ); $this->orig_theme_dir = $GLOBALS['wp_theme_directories']; @@ -40,6 +41,9 @@ class WP_Theme_JSON_Resolver_Test extends WP_UnitTestCase { return 'pl_PL'; } + /** + * @ticket 52991 + */ function test_fields_are_extracted() { $actual = WP_Theme_JSON_Resolver::get_fields_to_translate(); @@ -84,9 +88,12 @@ class WP_Theme_JSON_Resolver_Test extends WP_UnitTestCase { $this->assertEquals( $expected, $actual ); } + /** + * @ticket 52991 + */ function test_translations_are_applied() { add_filter( 'locale', array( $this, 'filter_set_locale_to_polish' ) ); - load_textdomain( 'fse', realpath( __DIR__ . '/data/languages/themes/fse-pl_PL.mo' ) ); + load_textdomain( 'fse', realpath( DIR_TESTDATA . '/languages/themes/fse-pl_PL.mo' ) ); switch_theme( 'fse' ); @@ -131,6 +138,9 @@ class WP_Theme_JSON_Resolver_Test extends WP_UnitTestCase { ); } + /** + * @ticket 52991 + */ function test_switching_themes_recalculates_data() { // By default, the theme for unit tests is "default", // which doesn't have theme.json support. diff --git a/tests/phpunit/tests/blocks/class-wp-theme-json-test.php b/tests/phpunit/tests/theme/class-wp-theme-json.php similarity index 97% rename from tests/phpunit/tests/blocks/class-wp-theme-json-test.php rename to tests/phpunit/tests/theme/class-wp-theme-json.php index 0f338e061a..b981bd798e 100644 --- a/tests/phpunit/tests/blocks/class-wp-theme-json-test.php +++ b/tests/phpunit/tests/theme/class-wp-theme-json.php @@ -3,11 +3,15 @@ /** * Test WP_Theme_JSON class. * - * @package Gutenberg + * @package WordPress + * @since 5.8.0 */ class WP_Theme_JSON_Test extends WP_UnitTestCase { + /** + * @ticket 52991 + */ function test_get_settings() { $theme_json = new WP_Theme_JSON( array( @@ -52,6 +56,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 52991 + */ public function test_merge_incoming_data() { $initial = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA, @@ -259,6 +266,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 52991 + */ function test_get_from_editor_settings() { $input = array( 'disableCustomColors' => true, @@ -332,6 +342,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 52991 + */ function test_get_editor_settings_no_theme_support() { $input = array( '__unstableEnableFullSiteEditingBlocks' => false, @@ -384,6 +397,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 52991 + */ function test_get_editor_settings_blank() { $expected = array( 'version' => WP_Theme_JSON::LATEST_SCHEMA, @@ -394,6 +410,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual ); } + /** + * @ticket 52991 + */ function test_get_editor_settings_custom_units_can_be_disabled() { add_theme_support( 'custom-units', array() ); $input = get_default_block_editor_settings(); @@ -408,6 +427,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] ); } + /** + * @ticket 52991 + */ function test_get_editor_settings_custom_units_can_be_enabled() { add_theme_support( 'custom-units' ); $input = get_default_block_editor_settings(); @@ -422,6 +444,9 @@ class WP_Theme_JSON_Test extends WP_UnitTestCase { $this->assertEqualSetsWithIndex( $expected, $actual['settings']['spacing'] ); } + /** + * @ticket 52991 + */ function test_get_editor_settings_custom_units_can_be_filtered() { add_theme_support( 'custom-units', 'rem', 'em' ); $input = get_default_block_editor_settings(); diff --git a/tests/phpunit/tests/theme/themeDir.php b/tests/phpunit/tests/theme/themeDir.php index b2a2542895..b7dc139521 100644 --- a/tests/phpunit/tests/theme/themeDir.php +++ b/tests/phpunit/tests/theme/themeDir.php @@ -161,6 +161,7 @@ class Tests_Theme_ThemeDir extends WP_UnitTestCase { 'Internationalized Theme', 'camelCase', 'REST Theme', + 'FSE Theme', ); sort( $theme_names );