From 962e7a4f2a78ad93e7354ff75d8529692afb1c1f Mon Sep 17 00:00:00 2001 From: addshore Date: Tue, 14 Nov 2017 12:03:39 +0000 Subject: [PATCH] Tests for Revision::getRevisionText with ExternalStore usage Bug: T180210 Change-Id: I20e47a44a064ede4f5e674f57ec4d8e39b379ad6 --- tests/phpunit/includes/RevisionTest.php | 45 +++++++++++++++++++ .../externalstore/ExternalStoreForTesting.php | 2 + 2 files changed, 47 insertions(+) diff --git a/tests/phpunit/includes/RevisionTest.php b/tests/phpunit/includes/RevisionTest.php index ca8ed2bcc1..b7e410c14d 100644 --- a/tests/phpunit/includes/RevisionTest.php +++ b/tests/phpunit/includes/RevisionTest.php @@ -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 ) ); + } + } diff --git a/tests/phpunit/includes/externalstore/ExternalStoreForTesting.php b/tests/phpunit/includes/externalstore/ExternalStoreForTesting.php index b151957f9b..50f1e523b1 100644 --- a/tests/phpunit/includes/externalstore/ExternalStoreForTesting.php +++ b/tests/phpunit/includes/externalstore/ExternalStoreForTesting.php @@ -8,6 +8,8 @@ class ExternalStoreForTesting { '300' => [ 'Hello', 'World', ], + // gzip string below generated with gzdeflate( 'AAAABBAAA' ) + '12345' => "sttttr\002\022\000", ], ]; -- 2.20.1