Merge "auth: Follow up on e907d4328dc3e"
[lhc/web/wiklou.git] / tests / phpunit / includes / Storage / DerivedPageDataUpdaterTest.php
index 7320305..3339749 100644 (file)
@@ -102,6 +102,9 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                }
 
                $rev = $updater->saveRevision( $comment );
+               if ( !$updater->wasSuccessful() ) {
+                       $this->fail( $updater->getStatus()->getWikiText() );
+               }
 
                $this->getDerivedPageDataUpdater( $page ); // flush cached instance after.
                return $rev;
@@ -186,6 +189,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
         * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getCanonicalParserOutput()
         */
        public function testPrepareContent() {
+               MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
+                       'aux',
+                       CONTENT_MODEL_WIKITEXT
+               );
+
                $sysop = $this->getTestUser( [ 'sysop' ] )->getUser();
                $updater = $this->getDerivedPageDataUpdater( __METHOD__ );
 
@@ -584,9 +592,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
        }
 
        public function testGetSecondaryDataUpdatesWithSlotRemoval() {
-               global $wgMultiContentRevisionSchemaMigrationStage;
-
-               if ( ! ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_NEW ) ) {
+               if ( !$this->hasMultiSlotSupport() ) {
                        $this->markTestSkipped( 'Slot removal cannot happen with MCR being enabled' );
                }
 
@@ -594,6 +600,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $a1 = $this->defineMockContentModelForUpdateTesting( 'A1' );
                $m2 = $this->defineMockContentModelForUpdateTesting( 'M2' );
 
+               MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
+                       'aux',
+                       $a1->getModelID()
+               );
+
                $mainContent1 = $this->createMockContent( $m1, 'main 1' );
                $auxContent1 = $this->createMockContent( $a1, 'aux 1' );
                $mainContent2 = $this->createMockContent( $m2, 'main 2' );
@@ -645,7 +656,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                RevisionSlotsUpdate $update,
                User $user,
                $comment,
-               $id,
+               $id = 0,
                $parentId = 0
        ) {
                $rev = new MutableRevisionRecord( $title );
@@ -653,10 +664,13 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                $rev->applyUpdate( $update );
                $rev->setUser( $user );
                $rev->setComment( CommentStoreComment::newUnsavedComment( $comment ) );
-               $rev->setId( $id );
                $rev->setPageId( $title->getArticleID() );
                $rev->setParentId( $parentId );
 
+               if ( $id ) {
+                       $rev->setId( $id );
+               }
+
                return $rev;
        }
 
@@ -866,6 +880,11 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
 
                if ( $this->hasMultiSlotSupport() ) {
                        $content['aux'] = new WikitextContent( 'Aux [[Nix]]' );
+
+                       MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
+                               'aux',
+                               CONTENT_MODEL_WIKITEXT
+                       );
                }
 
                $rev = $this->createRevision( $page, 'first', $content );
@@ -926,6 +945,79 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
                // TODO: test category membership update (with setRcWatchCategoryMembership())
        }
 
+       /**
+        * @covers \MediaWiki\Storage\DerivedPageDataUpdater::doParserCacheUpdate()
+        */
+       public function testDoParserCacheUpdate() {
+               if ( $this->hasMultiSlotSupport() ) {
+                       MediaWikiServices::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
+                               'aux',
+                               CONTENT_MODEL_WIKITEXT
+                       );
+               }
+
+               $page = $this->getPage( __METHOD__ );
+               $this->createRevision( $page, 'Dummy' );
+
+               $user = $this->getTestUser()->getUser();
+
+               $update = new RevisionSlotsUpdate();
+               $update->modifyContent( 'main', new WikitextContent( 'first [[Main]]' ) );
+
+               if ( $this->hasMultiSlotSupport() ) {
+                       $update->modifyContent( 'aux', new WikitextContent( 'Aux [[Nix]]' ) );
+               }
+
+               // Emulate update after edit ----------
+               $pcache = MediaWikiServices::getInstance()->getParserCache();
+               $pcache->deleteOptionsKey( $page );
+
+               $rev = $this->makeRevision( $page->getTitle(), $update, $user, 'rev', null );
+               $rev->setTimestamp( '20100101000000' );
+               $rev->setParentId( $page->getLatest() );
+
+               $updater = $this->getDerivedPageDataUpdater( $page );
+               $updater->prepareContent( $user, $update, false );
+
+               $rev->setId( 11 );
+               $updater->prepareUpdate( $rev );
+
+               // Force the page timestamp, so we notice whether ParserOutput::getTimestamp
+               // or ParserOutput::getCacheTime are used.
+               $page->setTimestamp( $rev->getTimestamp() );
+               $updater->doParserCacheUpdate();
+
+               // The cached ParserOutput should not use the revision timestamp
+               $cached = $pcache->get( $page, $updater->getCanonicalParserOptions(), true );
+               $this->assertInternalType( 'object', $cached );
+               $this->assertSame( $updater->getCanonicalParserOutput(), $cached );
+
+               $this->assertSame( $rev->getTimestamp(), $cached->getCacheTime() );
+               $this->assertSame( $rev->getId(), $cached->getCacheRevisionId() );
+
+               // Emulate forced update of an old revision ----------
+               $pcache->deleteOptionsKey( $page );
+
+               $updater = $this->getDerivedPageDataUpdater( $page );
+               $updater->prepareUpdate( $rev );
+
+               // Force the page timestamp, so we notice whether ParserOutput::getTimestamp
+               // or ParserOutput::getCacheTime are used.
+               $page->setTimestamp( $rev->getTimestamp() );
+               $updater->doParserCacheUpdate();
+
+               // The cached ParserOutput should not use the revision timestamp
+               $cached = $pcache->get( $page, $updater->getCanonicalParserOptions(), true );
+               $this->assertInternalType( 'object', $cached );
+               $this->assertSame( $updater->getCanonicalParserOutput(), $cached );
+
+               $this->assertGreaterThan( $rev->getTimestamp(), $cached->getCacheTime() );
+               $this->assertSame( $rev->getId(), $cached->getCacheRevisionId() );
+       }
+
+       /**
+        * @return bool
+        */
        private function hasMultiSlotSupport() {
                global $wgMultiContentRevisionSchemaMigrationStage;