Tests for Revision::getRevisionText with ExternalStore usage
authoraddshore <addshorewiki@gmail.com>
Tue, 14 Nov 2017 12:03:39 +0000 (12:03 +0000)
committerAddshore <addshorewiki@gmail.com>
Tue, 14 Nov 2017 18:37:52 +0000 (18:37 +0000)
Bug: T180210
Change-Id: I20e47a44a064ede4f5e674f57ec4d8e39b379ad6

tests/phpunit/includes/RevisionTest.php
tests/phpunit/includes/externalstore/ExternalStoreForTesting.php

index ca8ed2b..b7e410c 100644 (file)
@@ -532,4 +532,49 @@ class RevisionTest extends MediaWikiTestCase {
                );
        }
 
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_external_noOldId() {
+               $this->setService(
+                       'ExternalStoreFactory',
+                       new ExternalStoreFactory( [ 'ForTesting' ] )
+               );
+               $this->assertSame(
+                       'AAAABBAAA',
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => 'ForTesting://cluster1/12345',
+                                       'old_flags' => 'external,gzip',
+                               ]
+                       )
+               );
+       }
+
+       /**
+        * @covers Revision::getRevisionText
+        */
+       public function testGetRevisionText_external_oldId() {
+               $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] );
+               $this->setService( 'MainWANObjectCache', $cache );
+               $this->setService(
+                       'ExternalStoreFactory',
+                       new ExternalStoreFactory( [ 'ForTesting' ] )
+               );
+
+               $cacheKey = $cache->makeKey( 'revisiontext', 'textid', '7777' );
+
+               $this->assertSame(
+                       'AAAABBAAA',
+                       Revision::getRevisionText(
+                               (object)[
+                                       'old_text' => 'ForTesting://cluster1/12345',
+                                       'old_flags' => 'external,gzip',
+                                       'old_id' => '7777',
+                               ]
+                       )
+               );
+               $this->assertSame( 'AAAABBAAA', $cache->get( $cacheKey ) );
+       }
+
 }
index b151957..50f1e52 100644 (file)
@@ -8,6 +8,8 @@ class ExternalStoreForTesting {
                        '300' => [
                                'Hello', 'World',
                        ],
+                       // gzip string below generated with gzdeflate( 'AAAABBAAA' )
+                       '12345' => "sttttr\002\022\000",
                ],
        ];