Skip to content

Commit

Permalink
I18N: Correctly invalidate language file paths in `WP_Textdomain_Regi…
Browse files Browse the repository at this point in the history
…stry`.

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
  • Loading branch information
SergeyBiryukov committed Jan 16, 2024
1 parent 9d7bc51 commit bfcf293
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions src/wp-includes/class-wp-textdomain-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,13 @@ public function invalidate_mo_files_cache( $upgrader, $hook_extra ) {
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;
}
}
Expand Down
24 changes: 12 additions & 12 deletions tests/phpunit/tests/l10n/wpTextdomainRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ public function set_up() {
}

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();
}
Expand Down Expand Up @@ -100,10 +100,10 @@ public function test_get_language_files_from_path_caches_results() {
*/
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 );
Expand All @@ -113,9 +113,9 @@ public function test_get_language_files_from_path_short_circuit() {
* @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,
Expand Down Expand Up @@ -144,9 +144,9 @@ public function test_invalidate_mo_files_cache() {
)
);

$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() {
Expand Down

0 comments on commit bfcf293

Please sign in to comment.