From ee78c151a19ae09dd5734ac089eaf75eea3bffbf Mon Sep 17 00:00:00 2001 From: addshore Date: Fri, 10 Nov 2017 14:37:44 +0000 Subject: [PATCH] Test for Revision::newKnownCurrent Bug: T180210 Change-Id: I2cc83cbc91583b4631f4798dd14612c49024eeb4 --- tests/phpunit/includes/RevisionDbTestBase.php | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/phpunit/includes/RevisionDbTestBase.php b/tests/phpunit/includes/RevisionDbTestBase.php index 73559f3b71..1149307d92 100644 --- a/tests/phpunit/includes/RevisionDbTestBase.php +++ b/tests/phpunit/includes/RevisionDbTestBase.php @@ -1222,4 +1222,28 @@ abstract class RevisionDbTestBase extends MediaWikiTestCase { $this->assertSame( $this->testPage->getContentHandler(), $rev->getContentHandler() ); } + /** + * @covers Revision::newKnownCurrent + */ + public function testNewKnownCurrent() { + // Setup the services + $cache = new WANObjectCache( [ 'cache' => new HashBagOStuff() ] ); + $this->setService( 'MainWANObjectCache', $cache ); + $db = wfGetDB( DB_MASTER ); + + // Get a fresh revision to use during testing + $this->testPage->doEditContent( new WikitextContent( __METHOD__ ), __METHOD__ ); + $rev = $this->testPage->getRevision(); + + // Clear any previous cache for the revision during creation + $key = $cache->makeGlobalKey( 'revision', $db->getDomainID(), $rev->getPage(), $rev->getId() ); + $cache->delete( $key, WANObjectCache::HOLDOFF_NONE ); + $this->assertFalse( $cache->get( $key ) ); + + // Get the new revision and make sure it is in the cache and correct + $newRev = Revision::newKnownCurrent( $db, $rev->getPage(), $rev->getId() ); + $this->assertRevEquals( $rev, $newRev ); + $this->assertRevEquals( $rev, $cache->get( $key ) ); + } + } -- 2.20.1