use ContentHandler;
use LinksUpdate;
use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\MutableRevisionRecord;
+use MediaWiki\Revision\MutableRevisionSlots;
+use MediaWiki\Revision\RevisionRecord;
+use MediaWiki\Revision\SlotRecord;
use MediaWiki\Storage\DerivedPageDataUpdater;
-use MediaWiki\Storage\MutableRevisionRecord;
-use MediaWiki\Storage\MutableRevisionSlots;
-use MediaWiki\Storage\RevisionRecord;
use MediaWiki\Storage\RevisionSlotsUpdate;
-use MediaWiki\Storage\SlotRecord;
use MediaWikiTestCase;
use MWCallableUpdate;
+use MWTimestamp;
use PHPUnit\Framework\MockObject\MockObject;
use TextContent;
use TextContentHandler;
*/
class DerivedPageDataUpdaterTest extends MediaWikiTestCase {
+ public function tearDown() {
+ MWTimestamp::setFakeTime( false );
+
+ parent::tearDown();
+ }
+
/**
* @param string $title
*
$mainContent = new WikitextContent( 'Lorem ipsum' );
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent );
$updater = $this->getDerivedPageDataUpdater( $page );
$updater->prepareContent( $user, $update, false );
);
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent );
$update->modifySlot( SlotRecord::newInherited( $auxSlot ) );
// TODO: MCR: test removing slots!
$this->assertEquals( [ 'main', 'aux' ], $updater->getModifiedSlotRoles() );
$this->assertEquals( [ 'main', 'aux' ], $updater->getTouchedSlotRoles() );
- $mainSlot = $updater->getRawSlot( 'main' );
+ $mainSlot = $updater->getRawSlot( SlotRecord::MAIN );
$this->assertInstanceOf( SlotRecord::class, $mainSlot );
$this->assertNotContains( '~~~', $mainSlot->getContent()->serialize(), 'PST should apply.' );
$this->assertContains( $sysop->getName(), $mainSlot->getContent()->serialize() );
$mainContent2 = new WikitextContent( 'second ({{subst:REVISIONUSER}}) #~~~#' );
$rev = $this->createRevision( $page, 'first', $mainContent1 );
- $mainContent1 = $rev->getContent( 'main' ); // get post-pst content
+ $mainContent1 = $rev->getContent( SlotRecord::MAIN ); // get post-pst content
$userName = $rev->getUser()->getName();
$sysopName = $sysop->getName();
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent1 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
$updater1 = $this->getDerivedPageDataUpdater( $page );
$updater1->prepareContent( $sysop, $update, false );
// TODO: MCR: test inheritance from parent
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent2 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent2 );
$updater2 = $this->getDerivedPageDataUpdater( $page );
$updater2->prepareContent( $sysop, $update, false );
// non-null edit use the new user name in PST
- $pstText = $updater2->getSlots()->getContent( 'main' )->serialize();
+ $pstText = $updater2->getSlots()->getContent( SlotRecord::MAIN )->serialize();
$this->assertNotContains( '{{subst:REVISIONUSER}}', $pstText, '{{subst:REVISIONUSER}}' );
$this->assertNotContains( '~~~', $pstText, 'signature ~~~' );
$this->assertContains( '(' . $sysopName . ')', $pstText, '{{subst:REVISIONUSER}}' );
// TODO: MCR: test multiple slots, test slot removal!
- $this->assertInstanceOf( SlotRecord::class, $updater1->getRawSlot( 'main' ) );
- $this->assertNotContains( '~~~~', $updater1->getRawContent( 'main' )->serialize() );
+ $this->assertInstanceOf( SlotRecord::class, $updater1->getRawSlot( SlotRecord::MAIN ) );
+ $this->assertNotContains( '~~~~', $updater1->getRawContent( SlotRecord::MAIN )->serialize() );
$mainOutput = $updater1->getCanonicalParserOutput();
$this->assertContains( 'first', $mainOutput->getText() );
$mainContent1 = new WikitextContent( 'first [[main]] ~~~' );
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent1 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
$updater = $this->getDerivedPageDataUpdater( $page );
$updater->prepareContent( $user, $update, false );
- $mainOutput = $updater->getSlotParserOutput( 'main' );
+ $mainOutput = $updater->getSlotParserOutput( SlotRecord::MAIN );
$canonicalOutput = $updater->getCanonicalParserOutput();
$rev = $this->createRevision( $page, 'first', $mainContent1 );
$this->assertTrue( $updater->isUpdatePrepared() );
$this->assertTrue( $updater->isContentPrepared() );
- $this->assertSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
+ $this->assertSame( $mainOutput, $updater->getSlotParserOutput( SlotRecord::MAIN ) );
$this->assertSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
}
$mainContent1 = new WikitextContent( 'first --{{REVISIONID}}--' );
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent1 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
$updater = $this->getDerivedPageDataUpdater( $page );
$updater->prepareContent( $user, $update, false );
- $mainOutput = $updater->getSlotParserOutput( 'main' );
+ $mainOutput = $updater->getSlotParserOutput( SlotRecord::MAIN );
$canonicalOutput = $updater->getCanonicalParserOutput();
// prevent optimization on matching speculative ID
$this->assertTrue( $updater->isContentPrepared() );
// ParserOutput objects should have been flushed.
- $this->assertNotSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
+ $this->assertNotSame( $mainOutput, $updater->getSlotParserOutput( SlotRecord::MAIN ) );
$this->assertNotSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
$html = $updater->getCanonicalParserOutput()->getText();
$mainContent = new WikitextContent( 'first [[main]] ~~~' );
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent );
$updater = $this->getDerivedPageDataUpdater( __METHOD__ );
$updater->prepareContent( $user, $update, false );
$this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp );
$this->assertSame( $canonicalOutput, $preparedEdit->output );
$this->assertSame( $mainContent, $preparedEdit->newContent );
- $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent );
+ $this->assertSame( $updater->getRawContent( SlotRecord::MAIN ), $preparedEdit->pstContent );
$this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts );
$this->assertSame( null, $preparedEdit->revid );
}
* @covers \MediaWiki\Storage\DerivedPageDataUpdater::getPreparedEdit()
*/
public function testGetPreparedEditAfterPrepareUpdate() {
+ $clock = MWTimestamp::convert( TS_UNIX, '20100101000000' );
+ MWTimestamp::setFakeTime( function () use ( &$clock ) {
+ return $clock++;
+ } );
+
$page = $this->getPage( __METHOD__ );
$mainContent = new WikitextContent( 'first [[main]] ~~~' );
$update = new MutableRevisionSlots();
- $update->setContent( 'main', $mainContent );
+ $update->setContent( SlotRecord::MAIN, $mainContent );
$rev = $this->createRevision( $page, __METHOD__ );
$preparedEdit = $updater->getPreparedEdit();
$this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp );
$this->assertSame( $canonicalOutput, $preparedEdit->output );
- $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent );
+ $this->assertSame( $updater->getRawContent( SlotRecord::MAIN ), $preparedEdit->pstContent );
$this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts );
$this->assertSame( $rev->getId(), $preparedEdit->revid );
}
$mainContent1 = new WikitextContent( 'first' );
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent1 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent1 );
$updater = $this->getDerivedPageDataUpdater( $page );
$updater->prepareContent( $user, $update, false );
);
$update = new RevisionSlotsUpdate();
- $update->modifyContent( 'main', $mainContent2 );
+ $update->modifyContent( SlotRecord::MAIN, $mainContent2 );
$update->removeSlot( 'aux' );
$page = $this->getPage( __METHOD__ );
$content2 = new WikitextContent( 'two' );
$update1 = new RevisionSlotsUpdate();
- $update1->modifyContent( 'main', $content1 );
+ $update1->modifyContent( SlotRecord::MAIN, $content1 );
$update1b = new RevisionSlotsUpdate();
$update1b->modifyContent( 'xyz', $content1 );
$update2 = new RevisionSlotsUpdate();
- $update2->modifyContent( 'main', $content2 );
+ $update2->modifyContent( SlotRecord::MAIN, $content2 );
$rev1 = $this->makeRevision( $title, $update1, $user1, 'rev1', 11 );
$rev1b = $this->makeRevision( $title, $update1b, $user1, 'rev1', 11 );
'$forParent' => 0,
'$isReusable' => false,
];
- yield 'mismatch prepareUpdate revision user' => [
- '$prepUser' => null,
- '$prepRevision' => $rev2,
- '$prepUpdate' => null,
- '$forUser' => null,
- '$forRevision' => $rev2x,
- '$forUpdate' => null,
- '$forParent' => 0,
- '$isReusable' => false,
- ];
yield 'mismatch prepareUpdate revision id' => [
'$prepUser' => null,
'$prepRevision' => $rev2,