+ public function provideNewRevisionsFromBatchOptions() {
+ yield 'No preload slots or content, single page' => [
+ null,
+ []
+ ];
+ yield 'Preload slots and content, single page' => [
+ null,
+ [
+ 'slots' => [ SlotRecord::MAIN ],
+ 'content' => true
+ ]
+ ];
+ yield 'No preload slots or content, multiple pages' => [
+ 'Other_Page',
+ []
+ ];
+ yield 'Preload slots and content, multiple pages' => [
+ 'Other_Page',
+ [
+ 'slots' => [ SlotRecord::MAIN ],
+ 'content' => true
+ ]
+ ];
+ }
+
+ /**
+ * @dataProvider provideNewRevisionsFromBatchOptions
+ * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
+ * @param string|null $otherPageTitle
+ * @param array|null $options
+ * @throws \MWException
+ */
+ public function testNewRevisionsFromBatch_preloadContent(
+ $otherPageTitle = null,
+ array $options = []
+ ) {
+ $page1 = $this->getTestPage();
+ $text = __METHOD__ . 'b-ä';
+ $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
+ $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
+ /** @var Revision $rev1 */
+ $rev1 = $editStatus->getValue()['revision'];
+
+ $page2 = $this->getTestPage( $otherPageTitle );
+ $editStatus = $this->editPage( $page2->getTitle()->getPrefixedDBkey(), $text . '2' );
+ $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 2' );
+ /** @var Revision $rev2 */
+ $rev2 = $editStatus->getValue()['revision'];
+
+ $store = MediaWikiServices::getInstance()->getRevisionStore();
+ $result = $store->newRevisionsFromBatch(
+ [ $this->revisionToRow( $rev1 ), $this->revisionToRow( $rev2 ) ],
+ $options
+ );
+ $this->assertTrue( $result->isGood() );
+ $this->assertEmpty( $result->getErrors() );
+ /** @var RevisionRecord[] $records */
+ $records = $result->getValue();
+ $this->assertRevisionRecordMatchesRevision( $rev1, $records[$rev1->getId()] );
+ $this->assertRevisionRecordMatchesRevision( $rev2, $records[$rev2->getId()] );
+
+ $this->assertSame( $text . '1',
+ ContentHandler::getContentText( $records[$rev1->getId()]->getContent( SlotRecord::MAIN ) ) );
+ $this->assertSame( $text . '2',
+ ContentHandler::getContentText( $records[$rev2->getId()]->getContent( SlotRecord::MAIN ) ) );
+ $this->assertEquals( $page1->getTitle()->getDBkey(),
+ $records[$rev1->getId()]->getPageAsLinkTarget()->getDBkey() );
+ $this->assertEquals( $page2->getTitle()->getDBkey(),
+ $records[$rev2->getId()]->getPageAsLinkTarget()->getDBkey() );
+ }
+
+ /**
+ * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
+ */
+ public function testNewRevisionsFromBatch_emptyBatch() {
+ $result = MediaWikiServices::getInstance()->getRevisionStore()
+ ->newRevisionsFromBatch(
+ [],
+ [
+ 'slots' => [ SlotRecord::MAIN ],
+ 'content' => true
+ ]
+ );
+ $this->assertTrue( $result->isGood() );
+ $this->assertEmpty( $result->getValue() );
+ $this->assertEmpty( $result->getErrors() );
+ }
+
+ /**
+ * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
+ */
+ public function testNewRevisionsFromBatch_wrongTitle() {
+ $page1 = $this->getTestPage();
+ $text = __METHOD__ . 'b-ä';
+ $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
+ $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
+ /** @var Revision $rev1 */
+ $rev1 = $editStatus->getValue()['revision'];
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ MediaWikiServices::getInstance()->getRevisionStore()
+ ->newRevisionsFromBatch(
+ [ $this->revisionToRow( $rev1 ) ],
+ [],
+ IDBAccessObject::READ_NORMAL,
+ $this->getTestPage( 'Title_Other_Then_The_One_Revision_Belongs_To' )->getTitle()
+ );
+ }
+
+ /**
+ * @covers \MediaWiki\Revision\RevisionStore::newRevisionsFromBatch
+ */
+ public function testNewRevisionsFromBatch_DuplicateRows() {
+ $page1 = $this->getTestPage();
+ $text = __METHOD__ . 'b-ä';
+ $editStatus = $this->editPage( $page1->getTitle()->getPrefixedDBkey(), $text . '1' );
+ $this->assertTrue( $editStatus->isGood(), 'Sanity: must create revision 1' );
+ /** @var Revision $rev1 */
+ $rev1 = $editStatus->getValue()['revision'];
+
+ $this->setExpectedException( InvalidArgumentException::class );
+ MediaWikiServices::getInstance()->getRevisionStore()
+ ->newRevisionsFromBatch( [ $this->revisionToRow( $rev1 ), $this->revisionToRow( $rev1 ) ] );
+ }