From bfcf2936dbd472fdcde7af84ddd16bbc3d63fb89 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Tue, 16 Jan 2024 21:43:11 +0000 Subject: [PATCH] I18N: Correctly invalidate language file paths in `WP_Textdomain_Registry`. Since the cache key in `::get_language_files_from_path()` is based on a path that always includes a trailing slash, the path in `::invalidate_mo_files_cache()` should include the trailing slash as well. Includes adjusting the test expectations accordingly. Follow-up to [57287], [57290], [57298]. See #58919. git-svn-id: https://develop.svn.wordpress.org/trunk@57299 602fd350-edb4-49c9-b593-d223f7449a82 --- .../class-wp-textdomain-registry.php | 6 ++--- .../tests/l10n/wpTextdomainRegistry.php | 24 +++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/wp-includes/class-wp-textdomain-registry.php b/src/wp-includes/class-wp-textdomain-registry.php index 4121ecb091..8ff8ad0ae2 100644 --- a/src/wp-includes/class-wp-textdomain-registry.php +++ b/src/wp-includes/class-wp-textdomain-registry.php @@ -237,13 +237,13 @@ class WP_Textdomain_Registry { foreach ( $translation_types as $type ) { switch ( $type ) { case 'plugin': - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ); break; case 'theme': - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ); break; default: - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ); break; } } diff --git a/tests/phpunit/tests/l10n/wpTextdomainRegistry.php b/tests/phpunit/tests/l10n/wpTextdomainRegistry.php index 8334c4ea2e..19a239428d 100644 --- a/tests/phpunit/tests/l10n/wpTextdomainRegistry.php +++ b/tests/phpunit/tests/l10n/wpTextdomainRegistry.php @@ -19,10 +19,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase { } public function tear_down() { - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar' ), 'translations' ); - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ); - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' ); - wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/foobar/' ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ); + wp_cache_delete( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ); parent::tear_down(); } @@ -100,10 +100,10 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase { */ public function test_get_language_files_from_path_short_circuit() { add_filter( 'pre_get_language_files_from_path', '__return_empty_array' ); - $result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' ); + $result = $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' ); remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' ); - $cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ); + $cache = wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ); $this->assertEmpty( $result ); $this->assertFalse( $cache ); @@ -113,9 +113,9 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase { * @covers ::invalidate_mo_files_cache */ public function test_invalidate_mo_files_cache() { - $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins' ); - $this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes' ); - $this->instance->get_language_files_from_path( WP_LANG_DIR ); + $this->instance->get_language_files_from_path( WP_LANG_DIR . '/plugins/' ); + $this->instance->get_language_files_from_path( WP_LANG_DIR . '/themes/' ); + $this->instance->get_language_files_from_path( WP_LANG_DIR . '/' ); $this->instance->invalidate_mo_files_cache( null, @@ -144,9 +144,9 @@ class Tests_L10n_wpTextdomainRegistry extends WP_UnitTestCase { ) ); - $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins' ), 'translations' ) ); - $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes' ), 'translations' ) ); - $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR ), 'translations' ) ); + $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/plugins/' ), 'translations' ) ); + $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/themes/' ), 'translations' ) ); + $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( WP_LANG_DIR . '/' ), 'translations' ) ); } public function data_domains_locales() {