diff --git a/test/unit/php/includes/core/classes/class-test-event-setup.php b/test/unit/php/includes/core/classes/class-test-event-setup.php index a54e7aed5..eb4eb3974 100644 --- a/test/unit/php/includes/core/classes/class-test-event-setup.php +++ b/test/unit/php/includes/core/classes/class-test-event-setup.php @@ -125,9 +125,32 @@ public function test_get_localized_post_type_slug(): void { $this->assertSame( 'event', Event_Setup::get_localized_post_type_slug(), - 'Failed to assert english post type slug is "event".' + 'Failed to assert English post type slug is "event".' ); + $user_id = $this->factory->user->create(); + update_user_meta( $user_id, 'locale', 'es_ES' ); + switch_to_user_locale( $user_id ); + + // @todo This assertion CAN NOT FAIL, + // until real translations do exist in the wp-env instance. + // Because WordPress doesn't have any translation files to load, + // it will return the string in English. + $this->assertSame( + 'event', + Event_Setup::get_localized_post_type_slug(), + 'Failed to assert post type slug is "event", even the locale is not English anymore.' + ); + // But at least the restoring of the user locale can be tested, without .po files. + $this->assertSame( + 'es_ES', + determine_locale(), + 'Failed to assert locale was reset to Spanish, after switching to ~ and restoring from English.' + ); + + // Restore default locale for following tests. + switch_to_locale( 'en_US' ); + // This also checks that the post type is still registered with the same 'Post Type Singular Name' label, // which is used by the method under test and the test itself. $filter = static function ( string $translation, string $text, string $context ): string { diff --git a/test/unit/php/includes/core/classes/class-test-topic.php b/test/unit/php/includes/core/classes/class-test-topic.php index b5e6b0fd1..cc16b2097 100644 --- a/test/unit/php/includes/core/classes/class-test-topic.php +++ b/test/unit/php/includes/core/classes/class-test-topic.php @@ -70,9 +70,32 @@ public function test_get_localized_taxonomy_slug(): void { $this->assertSame( 'topic', Topic::get_localized_taxonomy_slug(), - 'Failed to assert english taxonomy slug is "topic".' + 'Failed to assert English taxonomy slug is "topic".' ); + $user_id = $this->factory->user->create(); + update_user_meta( $user_id, 'locale', 'es_ES' ); + switch_to_user_locale( $user_id ); + + // @todo This assertion CAN NOT FAIL, + // until real translations do exist in the wp-env instance. + // Because WordPress doesn't have any translation files to load, + // it will return the string in English. + $this->assertSame( + 'topic', + Topic::get_localized_taxonomy_slug(), + 'Failed to assert taxonomy slug is "topic", even the locale is not English anymore.' + ); + // But at least the restoring of the user locale can be tested, without .po files. + $this->assertSame( + 'es_ES', + determine_locale(), + 'Failed to assert locale was reset to Spanish, after switching to ~ and restoring from English.' + ); + + // Restore default locale for following tests. + switch_to_locale( 'en_US' ); + // This also checks that the taxonomy is still registered with the same 'Taxonomy Singular Name' label, // which is used by the method under test and the test itself. $filter = static function ( string $translation, string $text, string $context ): string { diff --git a/test/unit/php/includes/core/classes/class-test-venue.php b/test/unit/php/includes/core/classes/class-test-venue.php index 39590efa4..a3332175f 100644 --- a/test/unit/php/includes/core/classes/class-test-venue.php +++ b/test/unit/php/includes/core/classes/class-test-venue.php @@ -100,9 +100,32 @@ public function test_get_localized_post_type_slug(): void { $this->assertSame( 'venue', Venue::get_localized_post_type_slug(), - 'Failed to assert english post type slug is "venue".' + 'Failed to assert English post type slug is "venue".' ); + $user_id = $this->factory->user->create(); + update_user_meta( $user_id, 'locale', 'es_ES' ); + switch_to_user_locale( $user_id ); + + // @todo This assertion CAN NOT FAIL, + // until real translations do exist in the wp-env instance. + // Because WordPress doesn't have any translation files to load, + // it will return the string in English. + $this->assertSame( + 'venue', + Venue::get_localized_post_type_slug(), + 'Failed to assert post type slug is "venue", even the locale is not English anymore.' + ); + // But at least the restoring of the user locale can be tested, without .po files. + $this->assertSame( + 'es_ES', + determine_locale(), + 'Failed to assert locale was reset to Spanish, after switching to ~ and restoring from English.' + ); + + // Restore default locale for following tests. + switch_to_locale( 'en_US' ); + // This also checks that the post type is still registered with the same 'Post Type Singular Name' label, // which is used by the method under test and the test itself. $filter = static function ( string $translation, string $text, string $context ): string {