X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=tests%2Fphpunit%2Fincludes%2FStorage%2FDerivedPageDataUpdaterTest.php;h=92c6f62c627a2cb7f8c418a64edfeedeb81761ce;hb=cff7dac346df3baf88cf3004f81011f09d43fed4;hp=5f3cba333b622806e18c6a1f431108cd2c0cfbc1;hpb=93350da7f1ab397b87c3ac3073ddfc1c857b272e;p=lhc%2Fweb%2Fwiklou.git diff --git a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php index 5f3cba333b..92c6f62c62 100644 --- a/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php +++ b/tests/phpunit/includes/Storage/DerivedPageDataUpdaterTest.php @@ -76,7 +76,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase { * Creates a revision in the database. * * @param WikiPage $page - * @param $summary + * @param string|Message|CommentStoreComment $summary * @param null|string|Content $content * * @return RevisionRecord|null @@ -656,7 +656,7 @@ class DerivedPageDataUpdaterTest extends MediaWikiTestCase { RevisionSlotsUpdate $update, User $user, $comment, - $id, + $id = 0, $parentId = 0 ) { $rev = new MutableRevisionRecord( $title ); @@ -664,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; } @@ -942,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;