Merge "Add join conditions to ActiveUsersPager"
[lhc/web/wiklou.git] / tests / phpunit / includes / cache / MessageCacheTest.php
index b03eeba..661f325 100644 (file)
@@ -1,5 +1,7 @@
 <?php
 
+use MediaWiki\MediaWikiServices;
+
 /**
  * @group Database
  * @group Cache
@@ -10,6 +12,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
        protected function setUp() {
                parent::setUp();
                $this->configureLanguages();
+               MessageCache::destroyInstance();
                MessageCache::singleton()->enable();
        }
 
@@ -57,12 +60,10 @@ class MessageCacheTest extends MediaWikiLangTestCase {
         * @param string|null $content Content of the created page, or null for a generic string
         */
        protected function makePage( $title, $lang, $content = null ) {
-               global $wgContLang;
-
                if ( $content === null ) {
                        $content = $lang;
                }
-               if ( $lang !== $wgContLang->getCode() ) {
+               if ( $lang !== MediaWikiServices::getInstance()->getContentLanguage()->getCode() ) {
                        $title = "$title/$lang";
                }
 
@@ -73,7 +74,7 @@ class MessageCacheTest extends MediaWikiLangTestCase {
        }
 
        /**
-        * Test message fallbacks, bug #1495
+        * Test message fallbacks, T3495
         *
         * @dataProvider provideMessagesForFallback
         */
@@ -100,11 +101,9 @@ class MessageCacheTest extends MediaWikiLangTestCase {
        }
 
        public function testReplaceMsg() {
-               global $wgContLang;
-
                $messageCache = MessageCache::singleton();
                $message = 'go';
-               $uckey = $wgContLang->ucfirst( $message );
+               $uckey = MediaWikiServices::getInstance()->getContentLanguage()->ucfirst( $message );
                $oldText = $messageCache->get( $message ); // "Ausführen"
 
                $dbw = wfGetDB( DB_MASTER );
@@ -130,23 +129,49 @@ class MessageCacheTest extends MediaWikiLangTestCase {
                $this->assertEquals( $oldText, $messageCache->get( $message ), 'Content restored' );
        }
 
-       /**
-        * There's a fallback case where the message key is given as fully qualified -- this
-        * should ignore the passed $lang and use the language from the key
-        *
-        * @dataProvider provideMessagesForFullKeys
-        */
-       public function testFullKeyBehaviour( $message, $lang, $expectedContent ) {
-               $result = MessageCache::singleton()->get( $message, true, $lang, true );
-               $this->assertEquals( $expectedContent, $result, "Full key message fallback failed." );
-       }
+       public function testReplaceCache() {
+               global $wgWANObjectCaches;
+
+               // We need a WAN cache for this.
+               $this->setMwGlobals( [
+                       'wgMainWANCache' => 'hash',
+                       'wgWANObjectCaches' => $wgWANObjectCaches + [
+                               'hash' => [
+                                       'class'    => WANObjectCache::class,
+                                       'cacheId'  => 'hash',
+                                       'channels' => []
+                               ]
+                       ]
+               ] );
+               $this->overrideMwServices();
+
+               MessageCache::destroyInstance();
+               $messageCache = MessageCache::singleton();
+               $messageCache->enable();
 
-       function provideMessagesForFullKeys() {
-               return [
-                       [ 'MessageCacheTest-FullKeyTest/ru', 'ru', 'ru' ],
-                       [ 'MessageCacheTest-FullKeyTest/ru', 'ab', 'ru' ],
-                       [ 'MessageCacheTest-FullKeyTest/ru/foo', 'ru', false ],
-               ];
+               // Populate one key
+               $this->makePage( 'Key1', 'de', 'Value1' );
+               $this->assertEquals( 0,
+                       DeferredUpdates::pendingUpdatesCount(),
+                       'Post-commit deferred update triggers a run of all updates' );
+               $this->assertEquals( 'Value1', $messageCache->get( 'Key1' ), 'Key1 was successfully edited' );
+
+               // Screw up the database so MessageCache::loadFromDB() will
+               // produce the wrong result for reloading Key1
+               $this->db->delete(
+                       'page', [ 'page_namespace' => NS_MEDIAWIKI, 'page_title' => 'Key1' ], __METHOD__
+               );
+
+               // Populate the second key
+               $this->makePage( 'Key2', 'de', 'Value2' );
+               $this->assertEquals( 0,
+                       DeferredUpdates::pendingUpdatesCount(),
+                       'Post-commit deferred update triggers a run of all updates' );
+               $this->assertEquals( 'Value2', $messageCache->get( 'Key2' ), 'Key2 was successfully edited' );
+
+               // Now test that the second edit didn't reload Key1
+               $this->assertEquals( 'Value1', $messageCache->get( 'Key1' ),
+                       'Key1 wasn\'t reloaded by edit of Key2' );
        }
 
        /**