3 namespace MediaWiki\Tests\Storage
;
5 use CommentStoreComment
;
8 use MediaWiki\MediaWikiServices
;
9 use MediaWiki\Storage\DerivedPageDataUpdater
;
10 use MediaWiki\Storage\MutableRevisionRecord
;
11 use MediaWiki\Storage\MutableRevisionSlots
;
12 use MediaWiki\Storage\RevisionRecord
;
13 use MediaWiki\Storage\RevisionSlotsUpdate
;
14 use MediaWiki\Storage\SlotRecord
;
15 use MediaWikiTestCase
;
18 use Wikimedia\TestingAccessWrapper
;
25 * @covers MediaWiki\Storage\DerivedPageDataUpdater
27 class DerivedPageDataUpdaterTest
extends MediaWikiTestCase
{
30 * @param string $title
34 private function getTitle( $title ) {
35 return Title
::makeTitleSafe( $this->getDefaultWikitextNS(), $title );
39 * @param string|Title $title
43 private function getPage( $title ) {
44 $title = ( $title instanceof Title
) ?
$title : $this->getTitle( $title );
46 return WikiPage
::factory( $title );
50 * @param string|Title|WikiPage $page
52 * @return DerivedPageDataUpdater
54 private function getDerivedPageDataUpdater( $page, RevisionRecord
$rec = null ) {
55 if ( is_string( $page ) ||
$page instanceof Title
) {
56 $page = $this->getPage( $page );
59 $page = TestingAccessWrapper
::newFromObject( $page );
60 return $page->getDerivedDataUpdater( null, $rec );
64 * Creates a revision in the database.
66 * @param WikiPage $page
68 * @param null|string|Content $content
70 * @return RevisionRecord|null
72 private function createRevision( WikiPage
$page, $summary, $content = null ) {
73 $user = $this->getTestUser()->getUser();
74 $comment = CommentStoreComment
::newUnsavedComment( $summary );
76 if ( !$content instanceof Content
) {
77 $content = new WikitextContent( $content ??
$summary );
80 $this->getDerivedPageDataUpdater( $page ); // flush cached instance before.
82 $updater = $page->newPageUpdater( $user );
83 $updater->setContent( 'main', $content );
84 $rev = $updater->saveRevision( $comment );
86 $this->getDerivedPageDataUpdater( $page ); // flush cached instance after.
90 // TODO: test setArticleCountMethod() and isCountable();
91 // TODO: test isRedirect() and wasRedirect()
94 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getCanonicalParserOptions()
96 public function testGetCanonicalParserOptions() {
97 $user = $this->getTestUser()->getUser();
98 $page = $this->getPage( __METHOD__
);
100 $parentRev = $this->createRevision( $page, 'first' );
102 $mainContent = new WikitextContent( 'Lorem ipsum' );
104 $update = new RevisionSlotsUpdate();
105 $update->modifyContent( 'main', $mainContent );
106 $updater = $this->getDerivedPageDataUpdater( $page );
107 $updater->prepareContent( $user, $update, false );
109 $options1 = $updater->getCanonicalParserOptions();
110 $this->assertSame( MediaWikiServices
::getInstance()->getContentLanguage(),
111 $options1->getUserLangObj() );
113 $speculativeId = call_user_func( $options1->getSpeculativeRevIdCallback(), $page->getTitle() );
114 $this->assertSame( $parentRev->getId() +
1, $speculativeId );
116 $rev = $this->makeRevision(
120 $parentRev->getId() +
7,
123 $updater->prepareUpdate( $rev );
125 $options2 = $updater->getCanonicalParserOptions();
126 $this->assertNotSame( $options1, $options2 );
128 $currentRev = call_user_func( $options2->getCurrentRevisionCallback(), $page->getTitle() );
129 $this->assertSame( $rev->getId(), $currentRev->getId() );
133 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::grabCurrentRevision()
134 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::pageExisted()
136 public function testGrabCurrentRevision() {
137 $page = $this->getPage( __METHOD__
);
139 $updater0 = $this->getDerivedPageDataUpdater( $page );
140 $this->assertNull( $updater0->grabCurrentRevision() );
141 $this->assertFalse( $updater0->pageExisted() );
143 $rev1 = $this->createRevision( $page, 'first' );
144 $updater1 = $this->getDerivedPageDataUpdater( $page );
145 $this->assertSame( $rev1->getId(), $updater1->grabCurrentRevision()->getId() );
146 $this->assertFalse( $updater0->pageExisted() );
147 $this->assertTrue( $updater1->pageExisted() );
149 $rev2 = $this->createRevision( $page, 'second' );
150 $updater2 = $this->getDerivedPageDataUpdater( $page );
151 $this->assertSame( $rev1->getId(), $updater1->grabCurrentRevision()->getId() );
152 $this->assertSame( $rev2->getId(), $updater2->grabCurrentRevision()->getId() );
156 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::prepareContent()
157 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isContentPrepared()
158 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::pageExisted()
159 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isCreation()
160 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isChange()
161 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getSlots()
162 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getRawSlot()
163 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getRawContent()
164 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getModifiedSlotRoles()
165 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getTouchedSlotRoles()
166 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getSlotParserOutput()
167 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getCanonicalParserOutput()
169 public function testPrepareContent() {
170 $user = $this->getTestUser()->getUser();
171 $updater = $this->getDerivedPageDataUpdater( __METHOD__
);
173 $this->assertFalse( $updater->isContentPrepared() );
176 // TODO: MCR: Test multiple slots. Test slot removal.
177 $mainContent = new WikitextContent( 'first [[main]] ~~~' );
178 $auxContent = new WikitextContent( 'inherited ~~~ content' );
179 $auxSlot = SlotRecord
::newSaved(
181 SlotRecord
::newUnsaved( 'aux', $auxContent )
184 $update = new RevisionSlotsUpdate();
185 $update->modifyContent( 'main', $mainContent );
186 $update->modifySlot( SlotRecord
::newInherited( $auxSlot ) );
187 // TODO: MCR: test removing slots!
189 $updater->prepareContent( $user, $update, false );
191 // second be ok to call again with the same params
192 $updater->prepareContent( $user, $update, false );
194 $this->assertNull( $updater->grabCurrentRevision() );
195 $this->assertTrue( $updater->isContentPrepared() );
196 $this->assertFalse( $updater->isUpdatePrepared() );
197 $this->assertFalse( $updater->pageExisted() );
198 $this->assertTrue( $updater->isCreation() );
199 $this->assertTrue( $updater->isChange() );
200 $this->assertTrue( $updater->isContentPublic() );
202 $this->assertEquals( [ 'main', 'aux' ], $updater->getSlots()->getSlotRoles() );
203 $this->assertEquals( [ 'main' ], array_keys( $updater->getSlots()->getOriginalSlots() ) );
204 $this->assertEquals( [ 'aux' ], array_keys( $updater->getSlots()->getInheritedSlots() ) );
205 $this->assertEquals( [ 'main', 'aux' ], $updater->getModifiedSlotRoles() );
206 $this->assertEquals( [ 'main', 'aux' ], $updater->getTouchedSlotRoles() );
208 $mainSlot = $updater->getRawSlot( 'main' );
209 $this->assertInstanceOf( SlotRecord
::class, $mainSlot );
210 $this->assertNotContains( '~~~', $mainSlot->getContent()->serialize(), 'PST should apply.' );
211 $this->assertContains( $user->getName(), $mainSlot->getContent()->serialize() );
213 $auxSlot = $updater->getRawSlot( 'aux' );
214 $this->assertInstanceOf( SlotRecord
::class, $auxSlot );
215 $this->assertContains( '~~~', $auxSlot->getContent()->serialize(), 'No PST should apply.' );
217 $mainOutput = $updater->getCanonicalParserOutput();
218 $this->assertContains( 'first', $mainOutput->getText() );
219 $this->assertContains( '<a ', $mainOutput->getText() );
220 $this->assertNotEmpty( $mainOutput->getLinks() );
222 $canonicalOutput = $updater->getCanonicalParserOutput();
223 $this->assertContains( 'first', $canonicalOutput->getText() );
224 $this->assertContains( '<a ', $canonicalOutput->getText() );
225 $this->assertNotEmpty( $canonicalOutput->getLinks() );
229 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::prepareContent()
230 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::pageExisted()
231 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isCreation()
232 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isChange()
234 public function testPrepareContentInherit() {
235 $user = $this->getTestUser()->getUser();
236 $page = $this->getPage( __METHOD__
);
238 $mainContent1 = new WikitextContent( 'first [[main]] ~~~' );
239 $mainContent2 = new WikitextContent( 'second' );
241 $this->createRevision( $page, 'first', $mainContent1 );
243 $update = new RevisionSlotsUpdate();
244 $update->modifyContent( 'main', $mainContent1 );
245 $updater1 = $this->getDerivedPageDataUpdater( $page );
246 $updater1->prepareContent( $user, $update, false );
248 $this->assertNotNull( $updater1->grabCurrentRevision() );
249 $this->assertTrue( $updater1->isContentPrepared() );
250 $this->assertTrue( $updater1->pageExisted() );
251 $this->assertFalse( $updater1->isCreation() );
252 $this->assertFalse( $updater1->isChange() );
254 // TODO: MCR: test inheritance from parent
255 $update = new RevisionSlotsUpdate();
256 $update->modifyContent( 'main', $mainContent2 );
257 $updater2 = $this->getDerivedPageDataUpdater( $page );
258 $updater2->prepareContent( $user, $update, false );
260 $this->assertFalse( $updater2->isCreation() );
261 $this->assertTrue( $updater2->isChange() );
264 // TODO: test failure of prepareContent() when called again...
265 // - with different user
266 // - with different update
267 // - after calling prepareUpdate()
270 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::prepareUpdate()
271 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isUpdatePrepared()
272 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isCreation()
273 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getSlots()
274 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getRawSlot()
275 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getRawContent()
276 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getModifiedSlotRoles()
277 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getTouchedSlotRoles()
278 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getSlotParserOutput()
279 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getCanonicalParserOutput()
281 public function testPrepareUpdate() {
282 $page = $this->getPage( __METHOD__
);
284 $mainContent1 = new WikitextContent( 'first [[main]] ~~~' );
285 $rev1 = $this->createRevision( $page, 'first', $mainContent1 );
286 $updater1 = $this->getDerivedPageDataUpdater( $page, $rev1 );
288 $options = []; // TODO: test *all* the options...
289 $updater1->prepareUpdate( $rev1, $options );
291 $this->assertTrue( $updater1->isUpdatePrepared() );
292 $this->assertTrue( $updater1->isContentPrepared() );
293 $this->assertTrue( $updater1->isCreation() );
294 $this->assertTrue( $updater1->isChange() );
295 $this->assertTrue( $updater1->isContentPublic() );
297 $this->assertEquals( [ 'main' ], $updater1->getSlots()->getSlotRoles() );
298 $this->assertEquals( [ 'main' ], array_keys( $updater1->getSlots()->getOriginalSlots() ) );
299 $this->assertEquals( [], array_keys( $updater1->getSlots()->getInheritedSlots() ) );
300 $this->assertEquals( [ 'main' ], $updater1->getModifiedSlotRoles() );
301 $this->assertEquals( [ 'main' ], $updater1->getTouchedSlotRoles() );
303 // TODO: MCR: test multiple slots, test slot removal!
305 $this->assertInstanceOf( SlotRecord
::class, $updater1->getRawSlot( 'main' ) );
306 $this->assertNotContains( '~~~~', $updater1->getRawContent( 'main' )->serialize() );
308 $mainOutput = $updater1->getCanonicalParserOutput();
309 $this->assertContains( 'first', $mainOutput->getText() );
310 $this->assertContains( '<a ', $mainOutput->getText() );
311 $this->assertNotEmpty( $mainOutput->getLinks() );
313 $canonicalOutput = $updater1->getCanonicalParserOutput();
314 $this->assertContains( 'first', $canonicalOutput->getText() );
315 $this->assertContains( '<a ', $canonicalOutput->getText() );
316 $this->assertNotEmpty( $canonicalOutput->getLinks() );
318 $mainContent2 = new WikitextContent( 'second' );
319 $rev2 = $this->createRevision( $page, 'second', $mainContent2 );
320 $updater2 = $this->getDerivedPageDataUpdater( $page, $rev2 );
322 $options = []; // TODO: test *all* the options...
323 $updater2->prepareUpdate( $rev2, $options );
325 $this->assertFalse( $updater2->isCreation() );
326 $this->assertTrue( $updater2->isChange() );
328 $canonicalOutput = $updater2->getCanonicalParserOutput();
329 $this->assertContains( 'second', $canonicalOutput->getText() );
333 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::prepareUpdate()
335 public function testPrepareUpdateReusesParserOutput() {
336 $user = $this->getTestUser()->getUser();
337 $page = $this->getPage( __METHOD__
);
339 $mainContent1 = new WikitextContent( 'first [[main]] ~~~' );
341 $update = new RevisionSlotsUpdate();
342 $update->modifyContent( 'main', $mainContent1 );
343 $updater = $this->getDerivedPageDataUpdater( $page );
344 $updater->prepareContent( $user, $update, false );
346 $mainOutput = $updater->getSlotParserOutput( 'main' );
347 $canonicalOutput = $updater->getCanonicalParserOutput();
349 $rev = $this->createRevision( $page, 'first', $mainContent1 );
351 $options = []; // TODO: test *all* the options...
352 $updater->prepareUpdate( $rev, $options );
354 $this->assertTrue( $updater->isUpdatePrepared() );
355 $this->assertTrue( $updater->isContentPrepared() );
357 $this->assertSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
358 $this->assertSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
362 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::prepareUpdate()
363 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getSlotParserOutput()
365 public function testPrepareUpdateOutputReset() {
366 $user = $this->getTestUser()->getUser();
367 $page = $this->getPage( __METHOD__
);
369 $mainContent1 = new WikitextContent( 'first --{{REVISIONID}}--' );
371 $update = new RevisionSlotsUpdate();
372 $update->modifyContent( 'main', $mainContent1 );
373 $updater = $this->getDerivedPageDataUpdater( $page );
374 $updater->prepareContent( $user, $update, false );
376 $mainOutput = $updater->getSlotParserOutput( 'main' );
377 $canonicalOutput = $updater->getCanonicalParserOutput();
379 // prevent optimization on matching speculative ID
380 $mainOutput->setSpeculativeRevIdUsed( 0 );
381 $canonicalOutput->setSpeculativeRevIdUsed( 0 );
383 $rev = $this->createRevision( $page, 'first', $mainContent1 );
385 $options = []; // TODO: test *all* the options...
386 $updater->prepareUpdate( $rev, $options );
388 $this->assertTrue( $updater->isUpdatePrepared() );
389 $this->assertTrue( $updater->isContentPrepared() );
391 // ParserOutput objects should have been flushed.
392 $this->assertNotSame( $mainOutput, $updater->getSlotParserOutput( 'main' ) );
393 $this->assertNotSame( $canonicalOutput, $updater->getCanonicalParserOutput() );
395 $html = $updater->getCanonicalParserOutput()->getText();
396 $this->assertContains( '--' . $rev->getId() . '--', $html );
398 // TODO: MCR: ensure that when the main slot uses {{REVISIONID}} but another slot is
399 // updated, the main slot is still re-rendered!
402 // TODO: test failure of prepareUpdate() when called again with a different revision
403 // TODO: test failure of prepareUpdate() on inconsistency with prepareContent.
406 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getPreparedEdit()
408 public function testGetPreparedEditAfterPrepareContent() {
409 $user = $this->getTestUser()->getUser();
411 $mainContent = new WikitextContent( 'first [[main]] ~~~' );
412 $update = new RevisionSlotsUpdate();
413 $update->modifyContent( 'main', $mainContent );
415 $updater = $this->getDerivedPageDataUpdater( __METHOD__
);
416 $updater->prepareContent( $user, $update, false );
418 $canonicalOutput = $updater->getCanonicalParserOutput();
420 $preparedEdit = $updater->getPreparedEdit();
421 $this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp
);
422 $this->assertSame( $canonicalOutput, $preparedEdit->output
);
423 $this->assertSame( $mainContent, $preparedEdit->newContent
);
424 $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent
);
425 $this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts
);
426 $this->assertSame( null, $preparedEdit->revid
);
430 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::getPreparedEdit()
432 public function testGetPreparedEditAfterPrepareUpdate() {
433 $page = $this->getPage( __METHOD__
);
435 $mainContent = new WikitextContent( 'first [[main]] ~~~' );
436 $update = new MutableRevisionSlots();
437 $update->setContent( 'main', $mainContent );
439 $rev = $this->createRevision( $page, __METHOD__
);
441 $updater = $this->getDerivedPageDataUpdater( $page );
442 $updater->prepareUpdate( $rev );
444 $canonicalOutput = $updater->getCanonicalParserOutput();
446 $preparedEdit = $updater->getPreparedEdit();
447 $this->assertSame( $canonicalOutput->getCacheTime(), $preparedEdit->timestamp
);
448 $this->assertSame( $canonicalOutput, $preparedEdit->output
);
449 $this->assertSame( $updater->getRawContent( 'main' ), $preparedEdit->pstContent
);
450 $this->assertSame( $updater->getCanonicalParserOptions(), $preparedEdit->popts
);
451 $this->assertSame( $rev->getId(), $preparedEdit->revid
);
454 public function testGetSecondaryDataUpdatesAfterPrepareContent() {
455 $user = $this->getTestUser()->getUser();
456 $page = $this->getPage( __METHOD__
);
457 $this->createRevision( $page, __METHOD__
);
459 $mainContent1 = new WikitextContent( 'first' );
461 $update = new RevisionSlotsUpdate();
462 $update->modifyContent( 'main', $mainContent1 );
463 $updater = $this->getDerivedPageDataUpdater( $page );
464 $updater->prepareContent( $user, $update, false );
466 $dataUpdates = $updater->getSecondaryDataUpdates();
468 // TODO: MCR: assert updates from all slots!
469 $this->assertNotEmpty( $dataUpdates );
471 $linksUpdates = array_filter( $dataUpdates, function ( $du ) {
472 return $du instanceof LinksUpdate
;
474 $this->assertCount( 1, $linksUpdates );
478 * Creates a dummy revision object without touching the database.
480 * @param Title $title
481 * @param RevisionSlotsUpdate $update
483 * @param string $comment
485 * @param int $parentId
487 * @return MutableRevisionRecord
489 private function makeRevision(
491 RevisionSlotsUpdate
$update,
497 $rev = new MutableRevisionRecord( $title );
499 $rev->applyUpdate( $update );
500 $rev->setUser( $user );
501 $rev->setComment( CommentStoreComment
::newUnsavedComment( $comment ) );
503 $rev->setPageId( $title->getArticleID() );
504 $rev->setParentId( $parentId );
509 public function provideIsReusableFor() {
510 $title = Title
::makeTitleSafe( NS_MAIN
, __METHOD__
);
512 $user1 = User
::newFromName( 'Alice' );
513 $user2 = User
::newFromName( 'Bob' );
515 $content1 = new WikitextContent( 'one' );
516 $content2 = new WikitextContent( 'two' );
518 $update1 = new RevisionSlotsUpdate();
519 $update1->modifyContent( 'main', $content1 );
521 $update1b = new RevisionSlotsUpdate();
522 $update1b->modifyContent( 'xyz', $content1 );
524 $update2 = new RevisionSlotsUpdate();
525 $update2->modifyContent( 'main', $content2 );
527 $rev1 = $this->makeRevision( $title, $update1, $user1, 'rev1', 11 );
528 $rev1b = $this->makeRevision( $title, $update1b, $user1, 'rev1', 11 );
530 $rev2 = $this->makeRevision( $title, $update2, $user1, 'rev2', 12 );
531 $rev2x = $this->makeRevision( $title, $update2, $user2, 'rev2', 12 );
532 $rev2y = $this->makeRevision( $title, $update2, $user1, 'rev2', 122 );
536 '$prepRevision' => null,
537 '$prepUpdate' => null,
539 '$forRevision' => null,
540 '$forUpdate' => null,
541 '$forParent' => null,
542 '$isReusable' => true,
545 '$prepUser' => $user1,
546 '$prepRevision' => $rev1,
547 '$prepUpdate' => $update1,
549 '$forRevision' => null,
550 '$forUpdate' => null,
551 '$forParent' => null,
552 '$isReusable' => true,
554 yield
'unprepared' => [
556 '$prepRevision' => null,
557 '$prepUpdate' => null,
558 '$forUser' => $user1,
559 '$forRevision' => $rev1,
560 '$forUpdate' => $update1,
562 '$isReusable' => true,
564 yield
'match prepareContent' => [
565 '$prepUser' => $user1,
566 '$prepRevision' => null,
567 '$prepUpdate' => $update1,
568 '$forUser' => $user1,
569 '$forRevision' => null,
570 '$forUpdate' => $update1,
572 '$isReusable' => true,
574 yield
'match prepareUpdate' => [
576 '$prepRevision' => $rev1,
577 '$prepUpdate' => null,
578 '$forUser' => $user1,
579 '$forRevision' => $rev1,
580 '$forUpdate' => null,
582 '$isReusable' => true,
584 yield
'match all' => [
585 '$prepUser' => $user1,
586 '$prepRevision' => $rev1,
587 '$prepUpdate' => $update1,
588 '$forUser' => $user1,
589 '$forRevision' => $rev1,
590 '$forUpdate' => $update1,
592 '$isReusable' => true,
594 yield
'mismatch prepareContent update' => [
595 '$prepUser' => $user1,
596 '$prepRevision' => null,
597 '$prepUpdate' => $update1,
598 '$forUser' => $user1,
599 '$forRevision' => null,
600 '$forUpdate' => $update1b,
602 '$isReusable' => false,
604 yield
'mismatch prepareContent user' => [
605 '$prepUser' => $user1,
606 '$prepRevision' => null,
607 '$prepUpdate' => $update1,
608 '$forUser' => $user2,
609 '$forRevision' => null,
610 '$forUpdate' => $update1,
612 '$isReusable' => false,
614 yield
'mismatch prepareContent parent' => [
615 '$prepUser' => $user1,
616 '$prepRevision' => null,
617 '$prepUpdate' => $update1,
618 '$forUser' => $user1,
619 '$forRevision' => null,
620 '$forUpdate' => $update1,
622 '$isReusable' => false,
624 yield
'mismatch prepareUpdate revision update' => [
626 '$prepRevision' => $rev1,
627 '$prepUpdate' => null,
629 '$forRevision' => $rev1b,
630 '$forUpdate' => null,
632 '$isReusable' => false,
634 yield
'mismatch prepareUpdate revision user' => [
636 '$prepRevision' => $rev2,
637 '$prepUpdate' => null,
639 '$forRevision' => $rev2x,
640 '$forUpdate' => null,
642 '$isReusable' => false,
644 yield
'mismatch prepareUpdate revision id' => [
646 '$prepRevision' => $rev2,
647 '$prepUpdate' => null,
649 '$forRevision' => $rev2y,
650 '$forUpdate' => null,
652 '$isReusable' => false,
657 * @dataProvider provideIsReusableFor
658 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::isReusableFor()
660 * @param User|null $prepUser
661 * @param RevisionRecord|null $prepRevision
662 * @param RevisionSlotsUpdate|null $prepUpdate
663 * @param User|null $forUser
664 * @param RevisionRecord|null $forRevision
665 * @param RevisionSlotsUpdate|null $forUpdate
666 * @param int|null $forParent
667 * @param bool $isReusable
669 public function testIsReusableFor(
670 User
$prepUser = null,
671 RevisionRecord
$prepRevision = null,
672 RevisionSlotsUpdate
$prepUpdate = null,
673 User
$forUser = null,
674 RevisionRecord
$forRevision = null,
675 RevisionSlotsUpdate
$forUpdate = null,
679 $updater = $this->getDerivedPageDataUpdater( __METHOD__
);
682 $updater->prepareContent( $prepUser, $prepUpdate, false );
685 if ( $prepRevision ) {
686 $updater->prepareUpdate( $prepRevision );
691 $updater->isReusableFor( $forUser, $forRevision, $forUpdate, $forParent )
696 * @covers \MediaWiki\Storage\DerivedPageDataUpdater::doUpdates()
698 public function testDoUpdates() {
699 $page = $this->getPage( __METHOD__
);
701 $mainContent1 = new WikitextContent( 'first [[main]]' );
702 $rev = $this->createRevision( $page, 'first', $mainContent1 );
703 $pageId = $page->getId();
704 $oldStats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
706 $updater = $this->getDerivedPageDataUpdater( $page, $rev );
707 $updater->setArticleCountMethod( 'link' );
709 $options = []; // TODO: test *all* the options...
710 $updater->prepareUpdate( $rev, $options );
712 $updater->doUpdates();
714 // links table update
715 $linkCount = $this->db
->selectRowCount( 'pagelinks', '*', [ 'pl_from' => $pageId ] );
716 $this->assertSame( 1, $linkCount );
718 $pageLinksRow = $this->db
->selectRow( 'pagelinks', '*', [ 'pl_from' => $pageId ] );
719 $this->assertInternalType( 'object', $pageLinksRow );
720 $this->assertSame( 'Main', $pageLinksRow->pl_title
);
722 // parser cache update
723 $pcache = MediaWikiServices
::getInstance()->getParserCache();
724 $cached = $pcache->get( $page, $updater->getCanonicalParserOptions() );
725 $this->assertInternalType( 'object', $cached );
726 $this->assertSame( $updater->getCanonicalParserOutput(), $cached );
729 $stats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
730 $this->assertSame( $oldStats->ss_total_pages +
1, (int)$stats->ss_total_pages
);
731 $this->assertSame( $oldStats->ss_total_edits +
1, (int)$stats->ss_total_edits
);
732 $this->assertSame( $oldStats->ss_good_articles +
1, (int)$stats->ss_good_articles
);
734 // TODO: MCR: test data updates for additional slots!
735 // TODO: test update for edit without page creation
736 // TODO: test message cache purge
737 // TODO: test module cache purge
738 // TODO: test CDN purge
739 // TODO: test newtalk update
740 // TODO: test search update
741 // TODO: test site stats good_articles while turning the page into (or back from) a redir.
742 // TODO: test category membership update (with setRcWatchCategoryMembership())