Changeset 57287 for trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php
- Timestamp:
- 01/15/2024 07:03:27 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/l10n/wpTextdomainRegistry.php
r55010 r57287 19 19 } 20 20 21 public function tear_down() { 22 wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/foobar/' ), 'translations' ); 23 wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ); 24 wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' ); 25 wp_cache_delete( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' ); 26 27 parent::tear_down(); 28 } 29 21 30 /** 22 31 * @covers ::has … … 25 34 */ 26 35 public function test_set_custom_path() { 27 $reflection = new ReflectionClass( $this->instance );28 $reflection_property = $reflection->getProperty( 'cached_mo_files' );29 $reflection_property->setAccessible( true );30 31 $this->assertEmpty(32 $reflection_property->getValue( $this->instance ),33 'Cache not empty by default'34 );35 36 36 $this->instance->set_custom_path( 'foo', WP_LANG_DIR . '/bar' ); 37 37 … … 49 49 'Custom path for textdomain not returned' 50 50 ); 51 $this->assertArrayHasKey( 52 WP_LANG_DIR . '/bar', 53 $reflection_property->getValue( $this->instance ), 54 'Custom path missing from cache' 51 $this->assertNotFalse( 52 wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . 'bar/' ), 'translations' ), 53 'List of files in custom path not cached' 55 54 ); 56 55 } … … 61 60 */ 62 61 public function test_get( $domain, $locale, $expected ) { 63 $reflection = new ReflectionClass( $this->instance );64 $reflection_property = $reflection->getProperty( 'cached_mo_files' );65 $reflection_property->setAccessible( true );66 67 62 $actual = $this->instance->get( $domain, $locale ); 68 63 $this->assertSame( … … 70 65 $actual, 71 66 'Expected languages directory path not matching actual one' 72 );73 74 $this->assertArrayHasKey(75 WP_LANG_DIR . '/plugins',76 $reflection_property->getValue( $this->instance ),77 'Default plugins path missing from cache'78 67 ); 79 68 } … … 90 79 $this->instance->get( 'foo-plugin', 'de_DE' ) 91 80 ); 81 } 82 83 /** 84 * @covers ::get_language_files_from_path 85 */ 86 public function test_get_language_files_from_path_caches_results() { 87 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/foobar/' ); 88 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' ); 89 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/themes/' ); 90 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) ); 91 92 $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ) ); 93 $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' ) ); 94 $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/foobar/' ), 'translations' ) ); 95 $this->assertNotFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' ) ); 96 } 97 98 /** 99 * @covers ::get_language_files_from_path 100 */ 101 public function test_get_language_files_from_path_short_circuit() { 102 add_filter( 'pre_get_language_files_from_path', '__return_empty_array' ); 103 $result = $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' ); 104 remove_filter( 'pre_get_language_files_from_path', '__return_empty_array' ); 105 106 $cache = wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ); 107 108 $this->assertEmpty( $result ); 109 $this->assertFalse( $cache ); 110 } 111 112 /** 113 * @covers ::invalidate_mo_files_cache 114 */ 115 public function test_invalidate_mo_files_cache() { 116 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/plugins/' ); 117 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) . '/themes/' ); 118 $this->instance->get_language_files_from_path( trailingslashit( WP_LANG_DIR ) ); 119 120 $this->instance->invalidate_mo_files_cache( 121 null, 122 array( 123 'type' => 'translation', 124 'translations' => array( 125 (object) array( 126 'type' => 'plugin', 127 'slug' => 'internationalized-plugin', 128 'language' => 'de_DE', 129 'version' => '99.9.9', 130 ), 131 (object) array( 132 'type' => 'theme', 133 'slug' => 'internationalized-theme', 134 'language' => 'de_DE', 135 'version' => '99.9.9', 136 ), 137 (object) array( 138 'type' => 'core', 139 'slug' => 'default', 140 'language' => 'es_ES', 141 'version' => '99.9.9', 142 ), 143 ), 144 ) 145 ); 146 147 $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/plugins/' ), 'translations' ) ); 148 $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) . '/themes/' ), 'translations' ) ); 149 $this->assertFalse( wp_cache_get( 'cached_mo_files_' . md5( trailingslashit( WP_LANG_DIR ) ), 'translations' ) ); 92 150 } 93 151
Note: See TracChangeset
for help on using the changeset viewer.