Test for Revision::newKnownCurrent
authoraddshore <addshorewiki@gmail.com>
Fri, 10 Nov 2017 14:37:44 +0000 (14:37 +0000)
committeraddshore <addshorewiki@gmail.com>
Fri, 10 Nov 2017 14:55:08 +0000 (14:55 +0000)
Bug: T180210
Change-Id: I2cc83cbc91583b4631f4798dd14612c49024eeb4

tests/phpunit/includes/RevisionDbTestBase.php

index 73559f3..1149307 100644 (file)
@@ -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 ) );
+       }
+
 }