3 use MediaWiki\Edit\PreparedEdit
;
4 use MediaWiki\MediaWikiServices
;
5 use MediaWiki\Revision\SlotRecord
;
6 use MediaWiki\Storage\RevisionSlotsUpdate
;
7 use PHPUnit\Framework\MockObject\MockObject
;
8 use Wikimedia\TestingAccessWrapper
;
13 abstract class WikiPageDbTestBase
extends MediaWikiLangTestCase
{
15 private $pagesToDelete;
17 public function __construct( $name = null, array $data = [], $dataName = '' ) {
18 parent
::__construct( $name, $data, $dataName );
20 $this->tablesUsed
= array_merge(
43 protected function addCoreDBData() {
44 // Blank out. This would fail with a modified schema, and we don't need it.
50 abstract protected function getMcrMigrationStage();
55 abstract protected function getMcrTablesToReset();
57 protected function setUp() {
60 $this->tablesUsed +
= $this->getMcrTablesToReset();
62 $this->setMwGlobals( 'wgContentHandlerUseDB', $this->getContentHandlerUseDB() );
64 'wgMultiContentRevisionSchemaMigrationStage',
65 $this->getMcrMigrationStage()
67 $this->pagesToDelete
= [];
69 $this->overrideMwServices();
72 protected function tearDown() {
73 foreach ( $this->pagesToDelete
as $p ) {
74 /* @var WikiPage $p */
78 $p->doDeleteArticle( "testing done." );
80 } catch ( MWException
$ex ) {
87 abstract protected function getContentHandlerUseDB();
90 * @param Title|string $title
91 * @param string|null $model
94 private function newPage( $title, $model = null ) {
95 if ( is_string( $title ) ) {
96 $ns = $this->getDefaultWikitextNS();
97 $title = Title
::newFromText( $title, $ns );
100 $p = new WikiPage( $title );
102 $this->pagesToDelete
[] = $p;
108 * @param string|Title|WikiPage $page
109 * @param string|Content|Content[] $content
110 * @param int|null $model
114 protected function createPage( $page, $content, $model = null, $user = null ) {
115 if ( is_string( $page ) ||
$page instanceof Title
) {
116 $page = $this->newPage( $page, $model );
120 $user = $this->getTestUser()->getUser();
123 if ( is_string( $content ) ) {
124 $content = ContentHandler
::makeContent( $content, $page->getTitle(), $model );
127 if ( !is_array( $content ) ) {
128 $content = [ 'main' => $content ];
131 $updater = $page->newPageUpdater( $user );
133 foreach ( $content as $role => $cnt ) {
134 $updater->setContent( $role, $cnt );
137 $updater->saveRevision( CommentStoreComment
::newUnsavedComment( "testing" ) );
138 if ( !$updater->wasSuccessful() ) {
139 $this->fail( $updater->getStatus()->getWikiText() );
146 * @covers WikiPage::prepareContentForEdit
148 public function testPrepareContentForEdit() {
149 $user = $this->getTestUser()->getUser();
150 $sysop = $this->getTestUser( [ 'sysop' ] )->getUser();
152 $page = $this->createPage( __METHOD__
, __METHOD__
, null, $user );
153 $title = $page->getTitle();
155 $content = ContentHandler
::makeContent(
156 "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
157 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
159 CONTENT_MODEL_WIKITEXT
161 $content2 = ContentHandler
::makeContent(
162 "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
163 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est. ~~~~",
165 CONTENT_MODEL_WIKITEXT
168 $edit = $page->prepareContentForEdit( $content, null, $user, null, false );
170 $this->assertInstanceOf(
171 ParserOptions
::class,
175 $this->assertContains( '</a>', $edit->output
->getText(), "output" );
176 $this->assertContains(
177 'consetetur sadipscing elitr',
178 $edit->output
->getText(),
182 $this->assertTrue( $content->equals( $edit->newContent
), "newContent field" );
183 $this->assertTrue( $content->equals( $edit->pstContent
), "pstContent field" );
184 $this->assertSame( $edit->output
, $edit->output
, "output field" );
185 $this->assertSame( $edit->popts
, $edit->popts
, "popts field" );
186 $this->assertSame( null, $edit->revid
, "revid field" );
188 // Re-using the prepared info if possible
189 $sameEdit = $page->prepareContentForEdit( $content, null, $user, null, false );
190 $this->assertPreparedEditEquals( $edit, $sameEdit, 'equivalent PreparedEdit' );
191 $this->assertSame( $edit->pstContent
, $sameEdit->pstContent
, 're-use output' );
192 $this->assertSame( $edit->output
, $sameEdit->output
, 're-use output' );
194 // Not re-using the same PreparedEdit if not possible
195 $rev = $page->getRevision();
196 $edit2 = $page->prepareContentForEdit( $content2, null, $user, null, false );
197 $this->assertPreparedEditNotEquals( $edit, $edit2 );
198 $this->assertContains( 'At vero eos', $edit2->pstContent
->serialize(), "content" );
200 // Check pre-safe transform
201 $this->assertContains( '[[gubergren]]', $edit2->pstContent
->serialize() );
202 $this->assertNotContains( '~~~~', $edit2->pstContent
->serialize() );
204 $edit3 = $page->prepareContentForEdit( $content2, null, $sysop, null, false );
205 $this->assertPreparedEditNotEquals( $edit2, $edit3 );
207 // TODO: test with passing revision, then same without revision.
211 * @covers WikiPage::doEditUpdates
213 public function testDoEditUpdates() {
214 $user = $this->getTestUser()->getUser();
216 // NOTE: if site stats get out of whack and drop below 0,
217 // that causes a DB error during tear-down. So bump the
218 // numbers high enough to not drop below 0.
219 $siteStatsUpdate = SiteStatsUpdate
::factory(
220 [ 'edits' => 1000, 'articles' => 1000, 'pages' => 1000 ]
222 $siteStatsUpdate->doUpdate();
224 $page = $this->createPage( __METHOD__
, __METHOD__
);
226 $revision = new Revision(
229 'page' => $page->getId(),
230 'title' => $page->getTitle(),
231 'comment' => __METHOD__
,
232 'minor_edit' => true,
233 'text' => __METHOD__
. ' [[|foo]][[bar]]', // PST turns [[|foo]] into [[foo]]
234 'user' => $user->getId(),
235 'user_text' => $user->getName(),
236 'timestamp' => '20170707040404',
237 'content_model' => CONTENT_MODEL_WIKITEXT
,
238 'content_format' => CONTENT_FORMAT_WIKITEXT
,
242 $page->doEditUpdates( $revision, $user );
244 // TODO: test various options; needs temporary hooks
246 $dbr = wfGetDB( DB_REPLICA
);
247 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $page->getId() ] );
248 $n = $res->numRows();
251 $this->assertEquals( 1, $n, 'pagelinks should contain only one link if PST was not applied' );
255 * @covers WikiPage::doEditContent
256 * @covers WikiPage::prepareContentForEdit
258 public function testDoEditContent() {
259 $this->setMwGlobals( 'wgPageCreationLog', true );
261 $page = $this->newPage( __METHOD__
);
262 $title = $page->getTitle();
264 $user1 = $this->getTestUser()->getUser();
265 // Use the confirmed group for user2 to make sure the user is different
266 $user2 = $this->getTestUser( [ 'confirmed' ] )->getUser();
268 $content = ContentHandler
::makeContent(
269 "[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
270 . " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
272 CONTENT_MODEL_WIKITEXT
275 $preparedEditBefore = $page->prepareContentForEdit( $content, null, $user1 );
277 $status = $page->doEditContent( $content, "[[testing]] 1", EDIT_NEW
, false, $user1 );
279 $this->assertTrue( $status->isOK(), 'OK' );
280 $this->assertTrue( $status->value
['new'], 'new' );
281 $this->assertNotNull( $status->value
['revision'], 'revision' );
282 $this->assertSame( $status->value
['revision']->getId(), $page->getRevision()->getId() );
283 $this->assertSame( $status->value
['revision']->getSha1(), $page->getRevision()->getSha1() );
284 $this->assertTrue( $status->value
['revision']->getContent()->equals( $content ), 'equals' );
286 $rev = $page->getRevision();
287 $preparedEditAfter = $page->prepareContentForEdit( $content, $rev, $user1 );
289 $this->assertNotNull( $rev->getRecentChange() );
290 $this->assertSame( $rev->getId(), (int)$rev->getRecentChange()->getAttribute( 'rc_this_oldid' ) );
292 // make sure that cached ParserOutput gets re-used throughout
293 $this->assertSame( $preparedEditBefore->output
, $preparedEditAfter->output
);
295 $id = $page->getId();
297 // Test page creation logging
300 [ 'log_type', 'log_action' ],
301 [ 'log_page' => $id ],
302 [ [ 'create', 'create' ] ]
305 $this->assertTrue( $title->getArticleID() > 0, "Title object should have new page id" );
306 $this->assertTrue( $id > 0, "WikiPage should have new page id" );
307 $this->assertTrue( $title->exists(), "Title object should indicate that the page now exists" );
308 $this->assertTrue( $page->exists(), "WikiPage object should indicate that the page now exists" );
310 # ------------------------
311 $dbr = wfGetDB( DB_REPLICA
);
312 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
313 $n = $res->numRows();
316 $this->assertEquals( 1, $n, 'pagelinks should contain one link from the page' );
318 # ------------------------
319 $page = new WikiPage( $title );
321 $retrieved = $page->getContent();
322 $this->assertTrue( $content->equals( $retrieved ), 'retrieved content doesn\'t equal original' );
324 # ------------------------
325 $page = new WikiPage( $title );
327 // try null edit, with a different user
328 $status = $page->doEditContent( $content, 'This changes nothing', EDIT_UPDATE
, false, $user2 );
329 $this->assertTrue( $status->isOK(), 'OK' );
330 $this->assertFalse( $status->value
['new'], 'new' );
331 $this->assertNull( $status->value
['revision'], 'revision' );
332 $this->assertNotNull( $page->getRevision() );
333 $this->assertTrue( $page->getRevision()->getContent()->equals( $content ), 'equals' );
335 # ------------------------
336 $content = ContentHandler
::makeContent(
337 "At vero eos et accusam et justo duo [[dolores]] et ea rebum. "
338 . "Stet clita kasd [[gubergren]], no sea takimata sanctus est. ~~~~",
340 CONTENT_MODEL_WIKITEXT
343 $status = $page->doEditContent( $content, "testing 2", EDIT_UPDATE
);
344 $this->assertTrue( $status->isOK(), 'OK' );
345 $this->assertFalse( $status->value
['new'], 'new' );
346 $this->assertNotNull( $status->value
['revision'], 'revision' );
347 $this->assertSame( $status->value
['revision']->getId(), $page->getRevision()->getId() );
348 $this->assertSame( $status->value
['revision']->getSha1(), $page->getRevision()->getSha1() );
350 $status->value
['revision']->getContent()->equals( $content ),
351 'not equals (PST must substitute signature)'
354 $rev = $page->getRevision();
355 $this->assertNotNull( $rev->getRecentChange() );
356 $this->assertSame( $rev->getId(), (int)$rev->getRecentChange()->getAttribute( 'rc_this_oldid' ) );
358 # ------------------------
359 $page = new WikiPage( $title );
361 $retrieved = $page->getContent();
362 $newText = $retrieved->serialize();
363 $this->assertContains( '[[gubergren]]', $newText, 'New text must replace old text.' );
364 $this->assertNotContains( '~~~~', $newText, 'PST must substitute signature.' );
366 # ------------------------
367 $dbr = wfGetDB( DB_REPLICA
);
368 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
369 $n = $res->numRows();
372 $this->assertEquals( 2, $n, 'pagelinks should contain two links from the page' );
376 * @covers WikiPage::doEditContent
378 public function testDoEditContent_twice() {
379 $title = Title
::newFromText( __METHOD__
);
380 $page = WikiPage
::factory( $title );
381 $content = ContentHandler
::makeContent( '$1 van $2', $title );
383 // Make sure we can do the exact same save twice.
384 // This tests checks that internal caches are reset as appropriate.
385 $status1 = $page->doEditContent( $content, __METHOD__
);
386 $status2 = $page->doEditContent( $content, __METHOD__
);
388 $this->assertTrue( $status1->isOK(), 'OK' );
389 $this->assertTrue( $status2->isOK(), 'OK' );
391 $this->assertTrue( isset( $status1->value
['revision'] ), 'OK' );
392 $this->assertFalse( isset( $status2->value
['revision'] ), 'OK' );
396 * Undeletion is covered in PageArchiveTest::testUndeleteRevisions()
397 * TODO: Revision deletion
399 * @covers WikiPage::doDeleteArticle
400 * @covers WikiPage::doDeleteArticleReal
402 public function testDoDeleteArticle() {
403 $page = $this->createPage(
405 "[[original text]] foo",
406 CONTENT_MODEL_WIKITEXT
408 $id = $page->getId();
410 $page->doDeleteArticle( "testing deletion" );
413 $page->getTitle()->getArticleID() > 0,
414 "Title object should now have page id 0"
416 $this->assertFalse( $page->getId() > 0, "WikiPage should now have page id 0" );
419 "WikiPage::exists should return false after page was deleted"
423 "WikiPage::getContent should return null after page was deleted"
426 $t = Title
::newFromText( $page->getTitle()->getPrefixedText() );
429 "Title::exists should return false after page was deleted"
433 JobQueueGroup
::destroySingletons();
435 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
438 # ------------------------
439 $dbr = wfGetDB( DB_REPLICA
);
440 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
441 $n = $res->numRows();
444 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
448 * @covers WikiPage::doDeleteArticleReal
450 public function testDoDeleteArticleReal_user0() {
451 $page = $this->createPage(
453 "[[original text]] foo",
454 CONTENT_MODEL_WIKITEXT
456 $id = $page->getId();
459 $status = $page->doDeleteArticleReal(
460 /* reason */ "testing user 0 deletion",
461 /* suppress */ false,
464 /* errorStack */ $errorStack,
467 $logId = $status->getValue();
468 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
469 $commentQuery = MediaWikiServices
::getInstance()->getCommentStore()->getJoin( 'log_comment' );
471 [ 'logging' ] +
$actorQuery['tables'] +
$commentQuery['tables'], /* table */
475 'log_comment' => $commentQuery['fields']['log_comment_text'],
476 'log_user' => $actorQuery['fields']['log_user'],
477 'log_user_text' => $actorQuery['fields']['log_user_text'],
481 [ 'log_id' => $logId ],
485 'testing user 0 deletion',
488 (string)$page->getTitle()->getNamespace(),
489 $page->getTitle()->getDBkey(),
492 $actorQuery['joins'] +
$commentQuery['joins']
497 * @covers WikiPage::doDeleteArticleReal
499 public function testDoDeleteArticleReal_userSysop() {
500 $page = $this->createPage(
502 "[[original text]] foo",
503 CONTENT_MODEL_WIKITEXT
505 $id = $page->getId();
507 $user = $this->getTestSysop()->getUser();
509 $status = $page->doDeleteArticleReal(
510 /* reason */ "testing sysop deletion",
511 /* suppress */ false,
514 /* errorStack */ $errorStack,
517 $logId = $status->getValue();
518 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
519 $commentQuery = MediaWikiServices
::getInstance()->getCommentStore()->getJoin( 'log_comment' );
521 [ 'logging' ] +
$actorQuery['tables'] +
$commentQuery['tables'], /* table */
525 'log_comment' => $commentQuery['fields']['log_comment_text'],
526 'log_user' => $actorQuery['fields']['log_user'],
527 'log_user_text' => $actorQuery['fields']['log_user_text'],
531 [ 'log_id' => $logId ],
535 'testing sysop deletion',
536 (string)$user->getId(),
538 (string)$page->getTitle()->getNamespace(),
539 $page->getTitle()->getDBkey(),
542 $actorQuery['joins'] +
$commentQuery['joins']
547 * TODO: Test more stuff about suppression.
549 * @covers WikiPage::doDeleteArticleReal
551 public function testDoDeleteArticleReal_suppress() {
552 $page = $this->createPage(
554 "[[original text]] foo",
555 CONTENT_MODEL_WIKITEXT
557 $id = $page->getId();
559 $user = $this->getTestSysop()->getUser();
561 $status = $page->doDeleteArticleReal(
562 /* reason */ "testing deletion",
566 /* errorStack */ $errorStack,
569 $logId = $status->getValue();
570 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
571 $commentQuery = MediaWikiServices
::getInstance()->getCommentStore()->getJoin( 'log_comment' );
573 [ 'logging' ] +
$actorQuery['tables'] +
$commentQuery['tables'], /* table */
577 'log_comment' => $commentQuery['fields']['log_comment_text'],
578 'log_user' => $actorQuery['fields']['log_user'],
579 'log_user_text' => $actorQuery['fields']['log_user_text'],
583 [ 'log_id' => $logId ],
588 (string)$user->getId(),
590 (string)$page->getTitle()->getNamespace(),
591 $page->getTitle()->getDBkey(),
594 $actorQuery['joins'] +
$commentQuery['joins']
598 $page->getContent( Revision
::FOR_PUBLIC
),
599 "WikiPage::getContent should return null after the page was suppressed for general users"
603 $page->getContent( Revision
::FOR_THIS_USER
, null ),
604 "WikiPage::getContent should return null after the page was suppressed for user zero"
608 $page->getContent( Revision
::FOR_THIS_USER
, $user ),
609 "WikiPage::getContent should return null after the page was suppressed even for a sysop"
614 * @covers WikiPage::doDeleteUpdates
616 public function testDoDeleteUpdates() {
617 $user = $this->getTestUser()->getUser();
618 $page = $this->createPage(
620 "[[original text]] foo",
621 CONTENT_MODEL_WIKITEXT
623 $id = $page->getId();
624 $page->loadPageData(); // make sure the current revision is cached.
626 // Similar to MovePage logic
627 wfGetDB( DB_MASTER
)->delete( 'page', [ 'page_id' => $id ], __METHOD__
);
628 $page->doDeleteUpdates( $page->getId(), $page->getContent(), $page->getRevision(), $user );
631 JobQueueGroup
::destroySingletons();
633 $jobs->loadParamsAndArgs( null, [ 'quiet' => true ], null );
636 # ------------------------
637 $dbr = wfGetDB( DB_REPLICA
);
638 $res = $dbr->select( 'pagelinks', '*', [ 'pl_from' => $id ] );
639 $n = $res->numRows();
642 $this->assertEquals( 0, $n, 'pagelinks should contain no more links from the page' );
646 * @param string $name
648 * @return ContentHandler
650 protected function defineMockContentModelForUpdateTesting( $name ) {
651 /** @var ContentHandler|MockObject $handler */
652 $handler = $this->getMockBuilder( TextContentHandler
::class )
653 ->setConstructorArgs( [ $name ] )
655 [ 'getSecondaryDataUpdates', 'getDeletionUpdates', 'unserializeContent' ]
659 $dataUpdate = new MWCallableUpdate( 'time' );
660 $dataUpdate->_name
= "$name data update";
662 $deletionUpdate = new MWCallableUpdate( 'time' );
663 $deletionUpdate->_name
= "$name deletion update";
665 $handler->method( 'getSecondaryDataUpdates' )->willReturn( [ $dataUpdate ] );
666 $handler->method( 'getDeletionUpdates' )->willReturn( [ $deletionUpdate ] );
667 $handler->method( 'unserializeContent' )->willReturnCallback(
668 function ( $text ) use ( $handler ) {
669 return $this->createMockContent( $handler, $text );
673 $this->mergeMwGlobalArrayValue(
674 'wgContentHandlers', [
675 $name => function () use ( $handler ){
685 * @param ContentHandler $handler
686 * @param string $text
690 protected function createMockContent( ContentHandler
$handler, $text ) {
691 /** @var Content|MockObject $content */
692 $content = $this->getMockBuilder( TextContent
::class )
693 ->setConstructorArgs( [ $text ] )
694 ->setMethods( [ 'getModel', 'getContentHandler' ] )
697 $content->method( 'getModel' )->willReturn( $handler->getModelID() );
698 $content->method( 'getContentHandler' )->willReturn( $handler );
703 public function testGetDeletionUpdates() {
704 $m1 = $this->defineMockContentModelForUpdateTesting( 'M1' );
706 $mainContent1 = $this->createMockContent( $m1, 'main 1' );
708 $page = new WikiPage( Title
::newFromText( __METHOD__
) );
709 $page = $this->createPage(
711 [ 'main' => $mainContent1 ]
714 $dataUpdates = $page->getDeletionUpdates( $page->getRevisionRecord() );
715 $this->assertNotEmpty( $dataUpdates );
717 $updateNames = array_map( function ( $du ) {
718 return isset( $du->_name
) ?
$du->_name
: get_class( $du );
721 $this->assertContains( LinksDeletionUpdate
::class, $updateNames );
722 $this->assertContains( 'M1 deletion update', $updateNames );
726 * @covers WikiPage::getRevision
728 public function testGetRevision() {
729 $page = $this->newPage( __METHOD__
);
731 $rev = $page->getRevision();
732 $this->assertNull( $rev );
735 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
737 $rev = $page->getRevision();
739 $this->assertEquals( $page->getLatest(), $rev->getId() );
740 $this->assertEquals( "some text", $rev->getContent()->getText() );
744 * @covers WikiPage::getContent
746 public function testGetContent() {
747 $page = $this->newPage( __METHOD__
);
749 $content = $page->getContent();
750 $this->assertNull( $content );
753 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
755 $content = $page->getContent();
756 $this->assertEquals( "some text", $content->getText() );
760 * @covers WikiPage::exists
762 public function testExists() {
763 $page = $this->newPage( __METHOD__
);
764 $this->assertFalse( $page->exists() );
767 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
768 $this->assertTrue( $page->exists() );
770 $page = new WikiPage( $page->getTitle() );
771 $this->assertTrue( $page->exists() );
774 $page->doDeleteArticle( "done testing" );
775 $this->assertFalse( $page->exists() );
777 $page = new WikiPage( $page->getTitle() );
778 $this->assertFalse( $page->exists() );
781 public function provideHasViewableContent() {
783 [ 'WikiPageTest_testHasViewableContent', false, true ],
784 [ 'Special:WikiPageTest_testHasViewableContent', false ],
785 [ 'MediaWiki:WikiPageTest_testHasViewableContent', false ],
786 [ 'Special:Userlogin', true ],
787 [ 'MediaWiki:help', true ],
792 * @dataProvider provideHasViewableContent
793 * @covers WikiPage::hasViewableContent
795 public function testHasViewableContent( $title, $viewable, $create = false ) {
796 $page = $this->newPage( $title );
797 $this->assertEquals( $viewable, $page->hasViewableContent() );
800 $this->createPage( $page, "some text", CONTENT_MODEL_WIKITEXT
);
801 $this->assertTrue( $page->hasViewableContent() );
803 $page = new WikiPage( $page->getTitle() );
804 $this->assertTrue( $page->hasViewableContent() );
808 public function provideGetRedirectTarget() {
810 [ 'WikiPageTest_testGetRedirectTarget_1', CONTENT_MODEL_WIKITEXT
, "hello world", null ],
812 'WikiPageTest_testGetRedirectTarget_2',
813 CONTENT_MODEL_WIKITEXT
,
814 "#REDIRECT [[hello world]]",
817 // The below added to protect against Media namespace
818 // redirects which throw a fatal: (T203942)
820 'WikiPageTest_testGetRedirectTarget_3',
821 CONTENT_MODEL_WIKITEXT
,
822 "#REDIRECT [[Media:hello_world]]",
825 // Test fragments longer than 255 bytes (T207876)
827 'WikiPageTest_testGetRedirectTarget_4',
828 CONTENT_MODEL_WIKITEXT
,
829 // phpcs:ignore Generic.Files.LineLength
830 '#REDIRECT [[Foobar#🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴]]',
831 // phpcs:ignore Generic.Files.LineLength
832 'Foobar#🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴🏴...'
838 * @dataProvider provideGetRedirectTarget
839 * @covers WikiPage::getRedirectTarget
841 public function testGetRedirectTarget( $title, $model, $text, $target ) {
842 $this->setMwGlobals( [
843 'wgCapitalLinks' => true,
846 $page = $this->createPage( $title, $text, $model );
848 # sanity check, because this test seems to fail for no reason for some people.
849 $c = $page->getContent();
850 $this->assertEquals( WikitextContent
::class, get_class( $c ) );
852 # now, test the actual redirect
853 $t = $page->getRedirectTarget();
854 $this->assertEquals( $target, $t ?
$t->getFullText() : null );
858 * @dataProvider provideGetRedirectTarget
859 * @covers WikiPage::isRedirect
861 public function testIsRedirect( $title, $model, $text, $target ) {
862 $page = $this->createPage( $title, $text, $model );
863 $this->assertEquals( !is_null( $target ), $page->isRedirect() );
866 public function provideIsCountable() {
870 [ 'WikiPageTest_testIsCountable',
871 CONTENT_MODEL_WIKITEXT
,
876 [ 'WikiPageTest_testIsCountable',
877 CONTENT_MODEL_WIKITEXT
,
884 [ 'WikiPageTest_testIsCountable',
885 CONTENT_MODEL_WIKITEXT
,
890 [ 'WikiPageTest_testIsCountable',
891 CONTENT_MODEL_WIKITEXT
,
898 [ 'WikiPageTest_testIsCountable',
899 CONTENT_MODEL_WIKITEXT
,
904 [ 'WikiPageTest_testIsCountable',
905 CONTENT_MODEL_WIKITEXT
,
911 // not a content namespace
912 [ 'Talk:WikiPageTest_testIsCountable',
913 CONTENT_MODEL_WIKITEXT
,
918 [ 'Talk:WikiPageTest_testIsCountable',
919 CONTENT_MODEL_WIKITEXT
,
925 // not a content namespace, different model
926 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
932 [ 'MediaWiki:WikiPageTest_testIsCountable.js',
942 * @dataProvider provideIsCountable
943 * @covers WikiPage::isCountable
945 public function testIsCountable( $title, $model, $text, $mode, $expected ) {
946 global $wgContentHandlerUseDB;
948 $this->setMwGlobals( 'wgArticleCountMethod', $mode );
950 $title = Title
::newFromText( $title );
952 if ( !$wgContentHandlerUseDB
954 && ContentHandler
::getDefaultModelFor( $title ) != $model
956 $this->markTestSkipped( "Can not use non-default content model $model for "
957 . $title->getPrefixedDBkey() . " with \$wgContentHandlerUseDB disabled." );
960 $page = $this->createPage( $title, $text, $model );
962 $editInfo = $page->prepareContentForEdit( $page->getContent() );
964 $v = $page->isCountable();
965 $w = $page->isCountable( $editInfo );
970 "isCountable( null ) returned unexpected value " . var_export( $v, true )
971 . " instead of " . var_export( $expected, true )
972 . " in mode `$mode` for text \"$text\""
978 "isCountable( \$editInfo ) returned unexpected value " . var_export( $v, true )
979 . " instead of " . var_export( $expected, true )
980 . " in mode `$mode` for text \"$text\""
984 public function provideGetParserOutput() {
987 CONTENT_MODEL_WIKITEXT
,
989 "<div class=\"mw-parser-output\"><p>hello <i>world</i></p></div>"
996 * @dataProvider provideGetParserOutput
997 * @covers WikiPage::getParserOutput
999 public function testGetParserOutput( $model, $text, $expectedHtml ) {
1000 $page = $this->createPage( __METHOD__
, $text, $model );
1002 $opt = $page->makeParserOptions( 'canonical' );
1003 $po = $page->getParserOutput( $opt );
1004 $text = $po->getText();
1006 $text = trim( preg_replace( '/<!--.*?-->/sm', '', $text ) ); # strip injected comments
1007 $text = preg_replace( '!\s*(</p>|</div>)!sm', '\1', $text ); # don't let tidy confuse us
1009 $this->assertEquals( $expectedHtml, $text );
1015 * @covers WikiPage::getParserOutput
1017 public function testGetParserOutput_nonexisting() {
1018 $page = new WikiPage( Title
::newFromText( __METHOD__
) );
1020 $opt = new ParserOptions();
1021 $po = $page->getParserOutput( $opt );
1023 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing pages." );
1027 * @covers WikiPage::getParserOutput
1029 public function testGetParserOutput_badrev() {
1030 $page = $this->createPage( __METHOD__
, 'dummy', CONTENT_MODEL_WIKITEXT
);
1032 $opt = new ParserOptions();
1033 $po = $page->getParserOutput( $opt, $page->getLatest() +
1234 );
1035 // @todo would be neat to also test deleted revision
1037 $this->assertFalse( $po, "getParserOutput() shall return false for non-existing revisions." );
1040 public static $sections =
1054 public function dataReplaceSection() {
1055 // NOTE: assume the Help namespace to contain wikitext
1057 [ 'Help:WikiPageTest_testReplaceSection',
1058 CONTENT_MODEL_WIKITEXT
,
1063 trim( preg_replace( '/^Intro/sm', 'No more', self
::$sections ) )
1065 [ 'Help:WikiPageTest_testReplaceSection',
1066 CONTENT_MODEL_WIKITEXT
,
1073 [ 'Help:WikiPageTest_testReplaceSection',
1074 CONTENT_MODEL_WIKITEXT
,
1077 "== TEST ==\nmore fun",
1079 trim( preg_replace( '/^== test ==.*== foo ==/sm',
1080 "== TEST ==\nmore fun\n\n== foo ==",
1083 [ 'Help:WikiPageTest_testReplaceSection',
1084 CONTENT_MODEL_WIKITEXT
,
1089 trim( self
::$sections )
1091 [ 'Help:WikiPageTest_testReplaceSection',
1092 CONTENT_MODEL_WIKITEXT
,
1097 trim( self
::$sections ) . "\n\n== New ==\n\nNo more"
1103 * @dataProvider dataReplaceSection
1104 * @covers WikiPage::replaceSectionContent
1106 public function testReplaceSectionContent( $title, $model, $text, $section,
1107 $with, $sectionTitle, $expected
1109 $page = $this->createPage( $title, $text, $model );
1111 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
1112 /** @var TextContent $c */
1113 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
1115 $this->assertEquals( $expected, $c ?
trim( $c->getText() ) : null );
1119 * @dataProvider dataReplaceSection
1120 * @covers WikiPage::replaceSectionAtRev
1122 public function testReplaceSectionAtRev( $title, $model, $text, $section,
1123 $with, $sectionTitle, $expected
1125 $page = $this->createPage( $title, $text, $model );
1126 $baseRevId = $page->getLatest();
1128 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
1129 /** @var TextContent $c */
1130 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
1132 $this->assertEquals( $expected, $c ?
trim( $c->getText() ) : null );
1136 * @covers WikiPage::getOldestRevision
1138 public function testGetOldestRevision() {
1139 $page = $this->newPage( __METHOD__
);
1140 $page->doEditContent(
1141 new WikitextContent( 'one' ),
1145 $rev1 = $page->getRevision();
1147 $page = new WikiPage( $page->getTitle() );
1148 $page->doEditContent(
1149 new WikitextContent( 'two' ),
1154 $page = new WikiPage( $page->getTitle() );
1155 $page->doEditContent(
1156 new WikitextContent( 'three' ),
1162 $this->assertNotEquals(
1164 $page->getRevision()->getId(),
1165 '$page->getRevision()->getId()'
1169 $this->assertEquals(
1171 $page->getOldestRevision()->getId(),
1172 '$page->getOldestRevision()->getId()'
1177 * @covers WikiPage::doRollback
1178 * @covers WikiPage::commitRollback
1180 public function testDoRollback() {
1181 // FIXME: fails under postgres
1182 $this->markTestSkippedIfDbType( 'postgres' );
1184 $admin = $this->getTestSysop()->getUser();
1185 $user1 = $this->getTestUser()->getUser();
1186 // Use the confirmed group for user2 to make sure the user is different
1187 $user2 = $this->getTestUser( [ 'confirmed' ] )->getUser();
1189 // make sure we can test autopatrolling
1190 $this->setMwGlobals( 'wgUseRCPatrol', true );
1192 // TODO: MCR: test rollback of multiple slots!
1193 $page = $this->newPage( __METHOD__
);
1197 $status1 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1198 "section one", EDIT_NEW
, false, $admin );
1201 $status2 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1202 "adding section two", 0, false, $user1 );
1204 $text .= "\n\nthree";
1205 $status3 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1206 "adding section three", 0, false, $user2 );
1208 /** @var Revision $rev1 */
1209 /** @var Revision $rev2 */
1210 /** @var Revision $rev3 */
1211 $rev1 = $status1->getValue()['revision'];
1212 $rev2 = $status2->getValue()['revision'];
1213 $rev3 = $status3->getValue()['revision'];
1216 * We are having issues with doRollback spuriously failing. Apparently
1217 * the last revision somehow goes missing or not committed under some
1218 * circumstances. So, make sure the revisions have the correct usernames.
1220 $this->assertEquals( 3, Revision
::countByPageId( wfGetDB( DB_REPLICA
), $page->getId() ) );
1221 $this->assertEquals( $admin->getName(), $rev1->getUserText() );
1222 $this->assertEquals( $user1->getName(), $rev2->getUserText() );
1223 $this->assertEquals( $user2->getName(), $rev3->getUserText() );
1225 // Now, try the actual rollback
1226 $token = $admin->getEditToken( 'rollback' );
1227 $rollbackErrors = $page->doRollback(
1236 if ( $rollbackErrors ) {
1238 "Rollback failed:\n" .
1239 print_r( $rollbackErrors, true ) . ";\n" .
1240 print_r( $resultDetails, true )
1244 $page = new WikiPage( $page->getTitle() );
1245 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
1246 "rollback did not revert to the correct revision" );
1247 $this->assertEquals( "one\n\ntwo", $page->getContent()->getText() );
1249 $rc = MediaWikiServices
::getInstance()->getRevisionStore()->getRecentChange(
1250 $page->getRevision()->getRevisionRecord()
1253 $this->assertNotNull( $rc, 'RecentChanges entry' );
1254 $this->assertEquals(
1255 RecentChange
::PRC_AUTOPATROLLED
,
1256 $rc->getAttribute( 'rc_patrolled' ),
1260 // TODO: MCR: assert origin once we write slot data
1261 // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( SlotRecord::MAIN );
1262 // $this->assertTrue( $mainSlot->isInherited(), 'isInherited' );
1263 // $this->assertSame( $rev2->getId(), $mainSlot->getOrigin(), 'getOrigin' );
1267 * @covers WikiPage::doRollback
1268 * @covers WikiPage::commitRollback
1270 public function testDoRollbackFailureSameContent() {
1271 $admin = $this->getTestSysop()->getUser();
1274 $page = $this->newPage( __METHOD__
);
1275 $page->doEditContent(
1276 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1282 $rev1 = $page->getRevision();
1284 $user1 = $this->getTestUser( [ 'sysop' ] )->getUser();
1286 $page = new WikiPage( $page->getTitle() );
1287 $page->doEditContent(
1288 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1289 "adding section two",
1295 # now, do a the rollback from the same user was doing the edit before
1296 $resultDetails = [];
1297 $token = $user1->getEditToken( 'rollback' );
1298 $errors = $page->doRollback(
1300 "testing revert same user",
1307 $this->assertEquals( [], $errors, "Rollback failed same user" );
1309 # now, try the rollback
1310 $resultDetails = [];
1311 $token = $admin->getEditToken( 'rollback' );
1312 $errors = $page->doRollback(
1321 $this->assertEquals(
1331 "Rollback not failed"
1334 $page = new WikiPage( $page->getTitle() );
1335 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
1336 "rollback did not revert to the correct revision" );
1337 $this->assertEquals( "one", $page->getContent()->getText() );
1341 * Tests tagging for edits that do rollback action
1342 * @covers WikiPage::doRollback
1344 public function testDoRollbackTagging() {
1345 if ( !in_array( 'mw-rollback', ChangeTags
::getSoftwareTags() ) ) {
1346 $this->markTestSkipped( 'Rollback tag deactivated, skipped the test.' );
1349 $admin = new User();
1350 $admin->setName( 'Administrator' );
1351 $admin->addToDatabase();
1353 $text = 'First line';
1354 $page = $this->newPage( 'WikiPageTest_testDoRollbackTagging' );
1355 $page->doEditContent(
1356 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1363 $secondUser = new User();
1364 $secondUser->setName( '92.65.217.32' );
1365 $text .= '\n\nSecond line';
1366 $page = new WikiPage( $page->getTitle() );
1367 $page->doEditContent(
1368 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1369 'Adding second line',
1375 // Now, try the rollback
1376 $admin->addGroup( 'sysop' ); // Make the test user a sysop
1377 MediaWikiServices
::getInstance()->getPermissionManager()->invalidateUsersRightsCache();
1378 $token = $admin->getEditToken( 'rollback' );
1379 $errors = $page->doRollback(
1380 $secondUser->getName(),
1388 // If doRollback completed without errors
1389 if ( $errors === [] ) {
1390 $tags = $resultDetails[ 'tags' ];
1391 $this->assertContains( 'mw-rollback', $tags );
1395 public function provideGetAutoDeleteReason() {
1405 [ "first edit", null ],
1407 "/first edit.*only contributor/",
1413 [ "first edit", null ],
1414 [ "second edit", null ],
1416 "/second edit.*only contributor/",
1422 [ "first edit", "127.0.2.22" ],
1423 [ "second edit", "127.0.3.33" ],
1433 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
1434 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
1435 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
1436 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
1437 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1441 '/first edit:.*\.\.\."/',
1447 [ "first edit", "127.0.2.22" ],
1448 [ "", "127.0.3.33" ],
1450 "/before blanking.*first edit/",
1458 * @dataProvider provideGetAutoDeleteReason
1459 * @covers WikiPage::getAutoDeleteReason
1461 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1464 // NOTE: assume Help namespace to contain wikitext
1465 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1469 foreach ( $edits as $edit ) {
1472 if ( !empty( $edit[1] ) ) {
1473 $user->setName( $edit[1] );
1478 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1480 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1485 $reason = $page->getAutoDeleteReason( $hasHistory );
1487 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1488 $this->assertEquals( $expectedResult, $reason );
1490 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1491 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1494 $this->assertEquals( $expectedHistory, $hasHistory,
1495 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1497 $page->doDeleteArticle( "done" );
1500 public function providePreSaveTransform() {
1502 [ 'hello this is ~~~',
1503 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1505 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1506 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1512 * @covers WikiPage::factory
1514 public function testWikiPageFactory() {
1515 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1516 $page = WikiPage
::factory( $title );
1517 $this->assertEquals( WikiFilePage
::class, get_class( $page ) );
1519 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1520 $page = WikiPage
::factory( $title );
1521 $this->assertEquals( WikiCategoryPage
::class, get_class( $page ) );
1523 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1524 $page = WikiPage
::factory( $title );
1525 $this->assertEquals( WikiPage
::class, get_class( $page ) );
1529 * @covers WikiPage::loadPageData
1530 * @covers WikiPage::wasLoadedFrom
1532 public function testLoadPageData() {
1533 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1534 $page = WikiPage
::factory( $title );
1536 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1537 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1538 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1539 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1541 $page->loadPageData( IDBAccessObject
::READ_NORMAL
);
1542 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1543 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1544 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1545 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1547 $page->loadPageData( IDBAccessObject
::READ_LATEST
);
1548 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1549 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1550 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1551 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1553 $page->loadPageData( IDBAccessObject
::READ_LOCKING
);
1554 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1555 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1556 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1557 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1559 $page->loadPageData( IDBAccessObject
::READ_EXCLUSIVE
);
1560 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1561 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1562 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1563 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1567 * @covers WikiPage::updateCategoryCounts
1569 public function testUpdateCategoryCounts() {
1570 $page = new WikiPage( Title
::newFromText( __METHOD__
) );
1572 // Add an initial category
1573 $page->updateCategoryCounts( [ 'A' ], [], 0 );
1575 $this->assertEquals( 1, Category
::newFromName( 'A' )->getPageCount() );
1576 $this->assertEquals( 0, Category
::newFromName( 'B' )->getPageCount() );
1577 $this->assertEquals( 0, Category
::newFromName( 'C' )->getPageCount() );
1579 // Add a new category
1580 $page->updateCategoryCounts( [ 'B' ], [], 0 );
1582 $this->assertEquals( 1, Category
::newFromName( 'A' )->getPageCount() );
1583 $this->assertEquals( 1, Category
::newFromName( 'B' )->getPageCount() );
1584 $this->assertEquals( 0, Category
::newFromName( 'C' )->getPageCount() );
1586 // Add and remove a category
1587 $page->updateCategoryCounts( [ 'C' ], [ 'A' ], 0 );
1589 $this->assertEquals( 0, Category
::newFromName( 'A' )->getPageCount() );
1590 $this->assertEquals( 1, Category
::newFromName( 'B' )->getPageCount() );
1591 $this->assertEquals( 1, Category
::newFromName( 'C' )->getPageCount() );
1594 public function provideUpdateRedirectOn() {
1595 yield
[ '#REDIRECT [[Foo]]', true, null, true, true, 0 ];
1596 yield
[ '#REDIRECT [[Foo]]', true, 'Foo', true, false, 1 ];
1597 yield
[ 'SomeText', false, null, false, true, 0 ];
1598 yield
[ 'SomeText', false, 'Foo', false, false, 1 ];
1602 * @dataProvider provideUpdateRedirectOn
1603 * @covers WikiPage::updateRedirectOn
1605 * @param string $initialText
1606 * @param bool $initialRedirectState
1607 * @param string|null $redirectTitle
1608 * @param bool|null $lastRevIsRedirect
1609 * @param bool $expectedSuccess
1610 * @param int $expectedRowCount
1612 public function testUpdateRedirectOn(
1614 $initialRedirectState,
1620 // FIXME: fails under sqlite and postgres
1621 $this->markTestSkippedIfDbType( 'sqlite' );
1622 $this->markTestSkippedIfDbType( 'postgres' );
1623 static $pageCounter = 0;
1626 $page = $this->createPage( Title
::newFromText( __METHOD__
. $pageCounter ), $initialText );
1627 $this->assertSame( $initialRedirectState, $page->isRedirect() );
1629 $redirectTitle = is_string( $redirectTitle )
1630 ? Title
::newFromText( $redirectTitle )
1633 $success = $page->updateRedirectOn( $this->db
, $redirectTitle, $lastRevIsRedirect );
1634 $this->assertSame( $expectedSuccess, $success, 'Success assertion' );
1636 * updateRedirectOn explicitly updates the redirect table (and not the page table).
1637 * Most of core checks the page table for redirect status, so we have to be ugly and
1638 * assert a select from the table here.
1640 $this->assertRedirectTableCountForPageId( $page->getId(), $expectedRowCount );
1643 private function assertRedirectTableCountForPageId( $pageId, $expected ) {
1644 $this->assertSelect(
1647 [ 'rd_from' => $pageId ],
1648 [ [ strval( $expected ) ] ]
1653 * @covers WikiPage::insertRedirectEntry
1655 public function testInsertRedirectEntry_insertsRedirectEntry() {
1656 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1657 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1659 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1660 $targetTitle->mInterwiki
= 'eninter';
1661 $page->insertRedirectEntry( $targetTitle, null );
1663 $this->assertSelect(
1665 [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
1666 [ 'rd_from' => $page->getId() ],
1668 strval( $page->getId() ),
1669 strval( $targetTitle->getNamespace() ),
1670 strval( $targetTitle->getDBkey() ),
1671 strval( $targetTitle->getFragment() ),
1672 strval( $targetTitle->getInterwiki() ),
1678 * @covers WikiPage::insertRedirectEntry
1680 public function testInsertRedirectEntry_insertsRedirectEntryWithPageLatest() {
1681 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1682 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1684 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1685 $targetTitle->mInterwiki
= 'eninter';
1686 $page->insertRedirectEntry( $targetTitle, $page->getLatest() );
1688 $this->assertSelect(
1690 [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
1691 [ 'rd_from' => $page->getId() ],
1693 strval( $page->getId() ),
1694 strval( $targetTitle->getNamespace() ),
1695 strval( $targetTitle->getDBkey() ),
1696 strval( $targetTitle->getFragment() ),
1697 strval( $targetTitle->getInterwiki() ),
1703 * @covers WikiPage::insertRedirectEntry
1705 public function testInsertRedirectEntry_doesNotInsertIfPageLatestIncorrect() {
1706 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1707 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1709 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1710 $targetTitle->mInterwiki
= 'eninter';
1711 $page->insertRedirectEntry( $targetTitle, 215251 );
1713 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1716 private function getRow( array $overrides = [] ) {
1720 'page_is_redirect' => '1',
1721 'page_latest' => '99',
1722 'page_namespace' => '3',
1723 'page_title' => 'JaJaTitle',
1724 'page_restrictions' => 'edit=autoconfirmed,sysop:move=sysop',
1725 'page_touched' => '20120101020202',
1726 'page_links_updated' => '20140101020202',
1728 foreach ( $overrides as $key => $value ) {
1729 $row[$key] = $value;
1731 return (object)$row;
1734 public function provideNewFromRowSuccess() {
1735 yield
'basic row' => [
1737 function ( WikiPage
$wikiPage, self
$test ) {
1738 $test->assertSame( 44, $wikiPage->getId() );
1739 $test->assertSame( 76, $wikiPage->getTitle()->getLength() );
1740 $test->assertTrue( $wikiPage->isRedirect() );
1741 $test->assertSame( 99, $wikiPage->getLatest() );
1742 $test->assertSame( 3, $wikiPage->getTitle()->getNamespace() );
1743 $test->assertSame( 'JaJaTitle', $wikiPage->getTitle()->getDBkey() );
1746 'edit' => [ 'autoconfirmed', 'sysop' ],
1747 'move' => [ 'sysop' ],
1749 $wikiPage->getTitle()->getAllRestrictions()
1751 $test->assertSame( '20120101020202', $wikiPage->getTouched() );
1752 $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
1755 yield
'different timestamp formats' => [
1757 'page_touched' => '2012-01-01 02:02:02',
1758 'page_links_updated' => '2014-01-01 02:02:02',
1760 function ( WikiPage
$wikiPage, self
$test ) {
1761 $test->assertSame( '20120101020202', $wikiPage->getTouched() );
1762 $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
1765 yield
'no restrictions' => [
1767 'page_restrictions' => '',
1769 function ( WikiPage
$wikiPage, self
$test ) {
1775 $wikiPage->getTitle()->getAllRestrictions()
1779 yield
'not redirect' => [
1781 'page_is_redirect' => '0',
1783 function ( WikiPage
$wikiPage, self
$test ) {
1784 $test->assertFalse( $wikiPage->isRedirect() );
1790 * @covers WikiPage::newFromRow
1791 * @covers WikiPage::loadFromRow
1792 * @dataProvider provideNewFromRowSuccess
1794 * @param object $row
1795 * @param callable $assertions
1797 public function testNewFromRow( $row, $assertions ) {
1798 $page = WikiPage
::newFromRow( $row, 'fromdb' );
1799 $assertions( $page, $this );
1802 public function provideTestNewFromId_returnsNullOnBadPageId() {
1808 * @covers WikiPage::newFromID
1809 * @dataProvider provideTestNewFromId_returnsNullOnBadPageId
1811 public function testNewFromId_returnsNullOnBadPageId( $pageId ) {
1812 $this->assertNull( WikiPage
::newFromID( $pageId ) );
1816 * @covers WikiPage::newFromID
1818 public function testNewFromId_appearsToFetchCorrectRow() {
1819 $createdPage = $this->createPage( __METHOD__
, 'Xsfaij09' );
1820 $fetchedPage = WikiPage
::newFromID( $createdPage->getId() );
1821 $this->assertSame( $createdPage->getId(), $fetchedPage->getId() );
1822 $this->assertEquals(
1823 $createdPage->getContent()->getText(),
1824 $fetchedPage->getContent()->getText()
1829 * @covers WikiPage::newFromID
1831 public function testNewFromId_returnsNullOnNonExistingId() {
1832 $this->assertNull( WikiPage
::newFromID( 2147483647 ) );
1835 public function provideTestInsertProtectNullRevision() {
1836 // phpcs:disable Generic.Files.LineLength
1839 [ 'edit' => 'sysop' ],
1840 [ 'edit' => '20200101040404' ],
1844 '(goat-message-key: WikiPageDbTestBase::testInsertProtectNullRevision, UTSysop)(colon-separator)Goat Reason(word-separator)(parentheses: (protect-summary-desc: (restriction-edit), (protect-level-sysop), (protect-expiring: 04:04, 1 (january) 2020, 1 (january) 2020, 04:04)))'
1848 [ 'edit' => 'sysop', 'move' => 'something' ],
1849 [ 'edit' => '20200101040404', 'move' => '20210101050505' ],
1853 '(goat-key: WikiPageDbTestBase::testInsertProtectNullRevision, UTSysop)(colon-separator)Goat Goat(word-separator)(parentheses: (protect-summary-desc: (restriction-edit), (protect-level-sysop), (protect-expiring: 04:04, 1 (january) 2020, 1 (january) 2020, 04:04))(word-separator)(protect-summary-desc: (restriction-move), (protect-level-something), (protect-expiring: 05:05, 1 (january) 2021, 1 (january) 2021, 05:05)))'
1859 * @dataProvider provideTestInsertProtectNullRevision
1860 * @covers WikiPage::insertProtectNullRevision
1861 * @covers WikiPage::protectDescription
1863 * @param string $revCommentMsg
1864 * @param array $limit
1865 * @param array $expiry
1866 * @param bool $cascade
1867 * @param string $reason
1868 * @param bool|null $user true if the test sysop should be used, or null
1869 * @param string $expectedComment
1871 public function testInsertProtectNullRevision(
1880 $this->setContentLang( 'qqx' );
1882 $page = $this->createPage( __METHOD__
, 'Goat' );
1884 $user = $user === null ?
$user : $this->getTestSysop()->getUser();
1886 $result = $page->insertProtectNullRevision(
1895 $this->assertTrue( $result instanceof Revision
);
1896 $this->assertSame( $expectedComment, $result->getComment( Revision
::RAW
) );
1900 * @covers WikiPage::updateRevisionOn
1902 public function testUpdateRevisionOn_existingPage() {
1903 $user = $this->getTestSysop()->getUser();
1904 $page = $this->createPage( __METHOD__
, 'StartText' );
1906 $revision = new Revision(
1909 'page' => $page->getId(),
1910 'title' => $page->getTitle(),
1911 'comment' => __METHOD__
,
1912 'minor_edit' => true,
1913 'text' => __METHOD__
. '-text',
1914 'len' => strlen( __METHOD__
. '-text' ),
1915 'user' => $user->getId(),
1916 'user_text' => $user->getName(),
1917 'timestamp' => '20170707040404',
1918 'content_model' => CONTENT_MODEL_WIKITEXT
,
1919 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1923 $result = $page->updateRevisionOn( $this->db
, $revision );
1924 $this->assertTrue( $result );
1925 $this->assertSame( 9989, $page->getLatest() );
1926 $this->assertEquals( $revision, $page->getRevision() );
1930 * @covers WikiPage::updateRevisionOn
1932 public function testUpdateRevisionOn_NonExistingPage() {
1933 $user = $this->getTestSysop()->getUser();
1934 $page = $this->createPage( __METHOD__
, 'StartText' );
1935 $page->doDeleteArticle( 'reason' );
1937 $revision = new Revision(
1940 'page' => $page->getId(),
1941 'title' => $page->getTitle(),
1942 'comment' => __METHOD__
,
1943 'minor_edit' => true,
1944 'text' => __METHOD__
. '-text',
1945 'len' => strlen( __METHOD__
. '-text' ),
1946 'user' => $user->getId(),
1947 'user_text' => $user->getName(),
1948 'timestamp' => '20170707040404',
1949 'content_model' => CONTENT_MODEL_WIKITEXT
,
1950 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1954 $result = $page->updateRevisionOn( $this->db
, $revision );
1955 $this->assertFalse( $result );
1959 * @covers WikiPage::updateIfNewerOn
1961 public function testUpdateIfNewerOn_olderRevision() {
1962 $user = $this->getTestSysop()->getUser();
1963 $page = $this->createPage( __METHOD__
, 'StartText' );
1964 $initialRevision = $page->getRevision();
1966 $olderTimeStamp = wfTimestamp(
1968 wfTimestamp( TS_UNIX
, $initialRevision->getTimestamp() ) - 1
1971 $olderRevision = new Revision(
1974 'page' => $page->getId(),
1975 'title' => $page->getTitle(),
1976 'comment' => __METHOD__
,
1977 'minor_edit' => true,
1978 'text' => __METHOD__
. '-text',
1979 'len' => strlen( __METHOD__
. '-text' ),
1980 'user' => $user->getId(),
1981 'user_text' => $user->getName(),
1982 'timestamp' => $olderTimeStamp,
1983 'content_model' => CONTENT_MODEL_WIKITEXT
,
1984 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1988 $result = $page->updateIfNewerOn( $this->db
, $olderRevision );
1989 $this->assertFalse( $result );
1993 * @covers WikiPage::updateIfNewerOn
1995 public function testUpdateIfNewerOn_newerRevision() {
1996 $user = $this->getTestSysop()->getUser();
1997 $page = $this->createPage( __METHOD__
, 'StartText' );
1998 $initialRevision = $page->getRevision();
2000 $newerTimeStamp = wfTimestamp(
2002 wfTimestamp( TS_UNIX
, $initialRevision->getTimestamp() ) +
1
2005 $newerRevision = new Revision(
2008 'page' => $page->getId(),
2009 'title' => $page->getTitle(),
2010 'comment' => __METHOD__
,
2011 'minor_edit' => true,
2012 'text' => __METHOD__
. '-text',
2013 'len' => strlen( __METHOD__
. '-text' ),
2014 'user' => $user->getId(),
2015 'user_text' => $user->getName(),
2016 'timestamp' => $newerTimeStamp,
2017 'content_model' => CONTENT_MODEL_WIKITEXT
,
2018 'content_format' => CONTENT_FORMAT_WIKITEXT
,
2021 $result = $page->updateIfNewerOn( $this->db
, $newerRevision );
2022 $this->assertTrue( $result );
2026 * @covers WikiPage::insertOn
2028 public function testInsertOn() {
2029 $title = Title
::newFromText( __METHOD__
);
2030 $page = new WikiPage( $title );
2032 $startTimeStamp = wfTimestampNow();
2033 $result = $page->insertOn( $this->db
);
2034 $endTimeStamp = wfTimestampNow();
2036 $this->assertInternalType( 'int', $result );
2037 $this->assertTrue( $result > 0 );
2039 $condition = [ 'page_id' => $result ];
2041 // Check the default fields have been filled
2042 $this->assertSelect(
2047 'page_restrictions',
2065 // Check the page_random field has been filled
2066 $pageRandom = $this->db
->selectField( 'page', 'page_random', $condition );
2067 $this->assertTrue( (float)$pageRandom < 1 && (float)$pageRandom > 0 );
2069 // Assert the touched timestamp in the DB is roughly when we inserted the page
2070 $pageTouched = $this->db
->selectField( 'page', 'page_touched', $condition );
2072 wfTimestamp( TS_UNIX
, $startTimeStamp )
2073 <= wfTimestamp( TS_UNIX
, $pageTouched )
2076 wfTimestamp( TS_UNIX
, $endTimeStamp )
2077 >= wfTimestamp( TS_UNIX
, $pageTouched )
2080 // Try inserting the same page again and checking the result is false (no change)
2081 $result = $page->insertOn( $this->db
);
2082 $this->assertFalse( $result );
2086 * @covers WikiPage::insertOn
2088 public function testInsertOn_idSpecified() {
2089 $title = Title
::newFromText( __METHOD__
);
2090 $page = new WikiPage( $title );
2093 $result = $page->insertOn( $this->db
, $id );
2095 $this->assertSame( $id, $result );
2097 $condition = [ 'page_id' => $result ];
2099 // Check there is actually a row in the db
2100 $this->assertSelect(
2108 public function provideTestDoUpdateRestrictions_setBasicRestrictions() {
2109 // Note: Once the current dates passes the date in these tests they will fail.
2110 yield
'move something' => [
2112 [ 'move' => 'something' ],
2114 [ 'edit' => [], 'move' => [ 'something' ] ],
2117 yield
'move something, edit blank' => [
2119 [ 'move' => 'something', 'edit' => '' ],
2121 [ 'edit' => [], 'move' => [ 'something' ] ],
2124 yield
'edit sysop, with expiry' => [
2126 [ 'edit' => 'sysop' ],
2127 [ 'edit' => '21330101020202' ],
2128 [ 'edit' => [ 'sysop' ], 'move' => [] ],
2129 [ 'edit' => '21330101020202' ],
2131 yield
'move and edit, move with expiry' => [
2133 [ 'move' => 'something', 'edit' => 'another' ],
2134 [ 'move' => '22220202010101' ],
2135 [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
2136 [ 'move' => '22220202010101' ],
2138 yield
'move and edit, edit with infinity expiry' => [
2140 [ 'move' => 'something', 'edit' => 'another' ],
2141 [ 'edit' => 'infinity' ],
2142 [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
2143 [ 'edit' => 'infinity' ],
2145 yield
'non existing, create something' => [
2147 [ 'create' => 'something' ],
2149 [ 'create' => [ 'something' ] ],
2152 yield
'non existing, create something with expiry' => [
2154 [ 'create' => 'something' ],
2155 [ 'create' => '23451212112233' ],
2156 [ 'create' => [ 'something' ] ],
2157 [ 'create' => '23451212112233' ],
2162 * @dataProvider provideTestDoUpdateRestrictions_setBasicRestrictions
2163 * @covers WikiPage::doUpdateRestrictions
2165 public function testDoUpdateRestrictions_setBasicRestrictions(
2169 array $expectedRestrictions,
2170 array $expectedRestrictionExpiries
2172 if ( $pageExists ) {
2173 $page = $this->createPage( __METHOD__
, 'ABC' );
2175 $page = new WikiPage( Title
::newFromText( __METHOD__
. '-nonexist' ) );
2177 $user = $this->getTestSysop()->getUser();
2180 $status = $page->doUpdateRestrictions( $limit, $expiry, $cascade, 'aReason', $user, [] );
2182 $logId = $status->getValue();
2183 $allRestrictions = $page->getTitle()->getAllRestrictions();
2185 $this->assertTrue( $status->isGood() );
2186 $this->assertInternalType( 'int', $logId );
2187 $this->assertSame( $expectedRestrictions, $allRestrictions );
2188 foreach ( $expectedRestrictionExpiries as $key => $value ) {
2189 $this->assertSame( $value, $page->getTitle()->getRestrictionExpiry( $key ) );
2192 // Make sure the log entry looks good
2193 // log_params is not checked here
2194 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
2195 $commentQuery = MediaWikiServices
::getInstance()->getCommentStore()->getJoin( 'log_comment' );
2196 $this->assertSelect(
2197 [ 'logging' ] +
$actorQuery['tables'] +
$commentQuery['tables'],
2199 'log_comment' => $commentQuery['fields']['log_comment_text'],
2200 'log_user' => $actorQuery['fields']['log_user'],
2201 'log_user_text' => $actorQuery['fields']['log_user_text'],
2205 [ 'log_id' => $logId ],
2208 (string)$user->getId(),
2210 (string)$page->getTitle()->getNamespace(),
2211 $page->getTitle()->getDBkey(),
2214 $actorQuery['joins'] +
$commentQuery['joins']
2219 * @covers WikiPage::doUpdateRestrictions
2221 public function testDoUpdateRestrictions_failsOnReadOnly() {
2222 $page = $this->createPage( __METHOD__
, 'ABC' );
2223 $user = $this->getTestSysop()->getUser();
2227 $readOnly = $this->getMockBuilder( ReadOnlyMode
::class )
2228 ->disableOriginalConstructor()
2229 ->setMethods( [ 'isReadOnly', 'getReason' ] )
2231 $readOnly->expects( $this->once() )
2232 ->method( 'isReadOnly' )
2233 ->will( $this->returnValue( true ) );
2234 $readOnly->expects( $this->once() )
2235 ->method( 'getReason' )
2236 ->will( $this->returnValue( 'Some Read Only Reason' ) );
2237 $this->setService( 'ReadOnlyMode', $readOnly );
2239 $status = $page->doUpdateRestrictions( [], [], $cascade, 'aReason', $user, [] );
2240 $this->assertFalse( $status->isOK() );
2241 $this->assertSame( 'readonlytext', $status->getMessage()->getKey() );
2245 * @covers WikiPage::doUpdateRestrictions
2247 public function testDoUpdateRestrictions_returnsGoodIfNothingChanged() {
2248 $page = $this->createPage( __METHOD__
, 'ABC' );
2249 $user = $this->getTestSysop()->getUser();
2251 $limit = [ 'edit' => 'sysop' ];
2253 $status = $page->doUpdateRestrictions(
2262 // The first entry should have a logId as it did something
2263 $this->assertTrue( $status->isGood() );
2264 $this->assertInternalType( 'int', $status->getValue() );
2266 $status = $page->doUpdateRestrictions(
2275 // The second entry should not have a logId as nothing changed
2276 $this->assertTrue( $status->isGood() );
2277 $this->assertNull( $status->getValue() );
2281 * @covers WikiPage::doUpdateRestrictions
2283 public function testDoUpdateRestrictions_logEntryTypeAndAction() {
2284 $page = $this->createPage( __METHOD__
, 'ABC' );
2285 $user = $this->getTestSysop()->getUser();
2289 $status = $page->doUpdateRestrictions(
2290 [ 'edit' => 'sysop' ],
2297 $this->assertTrue( $status->isGood() );
2298 $this->assertInternalType( 'int', $status->getValue() );
2299 $this->assertSelect(
2301 [ 'log_type', 'log_action' ],
2302 [ 'log_id' => $status->getValue() ],
2303 [ [ 'protect', 'protect' ] ]
2306 // Modify the protection
2307 $status = $page->doUpdateRestrictions(
2308 [ 'edit' => 'somethingElse' ],
2315 $this->assertTrue( $status->isGood() );
2316 $this->assertInternalType( 'int', $status->getValue() );
2317 $this->assertSelect(
2319 [ 'log_type', 'log_action' ],
2320 [ 'log_id' => $status->getValue() ],
2321 [ [ 'protect', 'modify' ] ]
2324 // Remove the protection
2325 $status = $page->doUpdateRestrictions(
2333 $this->assertTrue( $status->isGood() );
2334 $this->assertInternalType( 'int', $status->getValue() );
2335 $this->assertSelect(
2337 [ 'log_type', 'log_action' ],
2338 [ 'log_id' => $status->getValue() ],
2339 [ [ 'protect', 'unprotect' ] ]
2344 * @covers WikiPage::newPageUpdater
2345 * @covers WikiPage::getDerivedDataUpdater
2347 public function testNewPageUpdater() {
2348 $user = $this->getTestUser()->getUser();
2349 $page = $this->newPage( __METHOD__
, __METHOD__
);
2351 /** @var Content $content */
2352 $content = $this->getMockBuilder( WikitextContent
::class )
2353 ->setConstructorArgs( [ 'Hello World' ] )
2354 ->setMethods( [ 'getParserOutput' ] )
2356 $content->expects( $this->once() )
2357 ->method( 'getParserOutput' )
2358 ->willReturn( new ParserOutput( 'HTML' ) );
2360 $preparedEditBefore = $page->prepareContentForEdit( $content, null, $user );
2362 // provide context, so the cache can be kept in place
2363 $slotsUpdate = new revisionSlotsUpdate();
2364 $slotsUpdate->modifyContent( SlotRecord
::MAIN
, $content );
2366 $updater = $page->newPageUpdater( $user, $slotsUpdate );
2367 $updater->setContent( SlotRecord
::MAIN
, $content );
2368 $revision = $updater->saveRevision(
2369 CommentStoreComment
::newUnsavedComment( 'test' ),
2373 $preparedEditAfter = $page->prepareContentForEdit( $content, $revision, $user );
2375 $this->assertSame( $revision->getId(), $page->getLatest() );
2377 // Parsed output must remain cached throughout.
2378 $this->assertSame( $preparedEditBefore->output
, $preparedEditAfter->output
);
2382 * @covers WikiPage::newPageUpdater
2383 * @covers WikiPage::getDerivedDataUpdater
2385 public function testGetDerivedDataUpdater() {
2386 $admin = $this->getTestSysop()->getUser();
2388 /** @var object $page */
2389 $page = $this->createPage( __METHOD__
, __METHOD__
);
2390 $page = TestingAccessWrapper
::newFromObject( $page );
2392 $revision = $page->getRevision()->getRevisionRecord();
2393 $user = $revision->getUser();
2395 $slotsUpdate = new RevisionSlotsUpdate();
2396 $slotsUpdate->modifyContent( SlotRecord
::MAIN
, new WikitextContent( 'Hello World' ) );
2398 // get a virgin updater
2399 $updater1 = $page->getDerivedDataUpdater( $user );
2400 $this->assertFalse( $updater1->isUpdatePrepared() );
2402 $updater1->prepareUpdate( $revision );
2404 // Re-use updater with same revision or content, even if base changed
2405 $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, $revision ) );
2407 $slotsUpdate = RevisionSlotsUpdate
::newFromContent(
2408 [ SlotRecord
::MAIN
=> $revision->getContent( SlotRecord
::MAIN
) ]
2410 $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, null, $slotsUpdate ) );
2412 // Don't re-use for edit if base revision ID changed
2413 $this->assertNotSame(
2415 $page->getDerivedDataUpdater( $user, null, $slotsUpdate, true )
2418 // Don't re-use with different user
2419 $updater2a = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
2420 $updater2a->prepareContent( $admin, $slotsUpdate, false );
2422 $updater2b = $page->getDerivedDataUpdater( $user, null, $slotsUpdate );
2423 $updater2b->prepareContent( $user, $slotsUpdate, false );
2424 $this->assertNotSame( $updater2a, $updater2b );
2426 // Don't re-use with different content
2427 $updater3 = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
2428 $updater3->prepareUpdate( $revision );
2429 $this->assertNotSame( $updater2b, $updater3 );
2431 // Don't re-use if no context given
2432 $updater4 = $page->getDerivedDataUpdater( $admin );
2433 $updater4->prepareUpdate( $revision );
2434 $this->assertNotSame( $updater3, $updater4 );
2436 // Don't re-use if AGAIN no context given
2437 $updater5 = $page->getDerivedDataUpdater( $admin );
2438 $this->assertNotSame( $updater4, $updater5 );
2440 // Don't re-use cached "virgin" unprepared updater
2441 $updater6 = $page->getDerivedDataUpdater( $admin, $revision );
2442 $this->assertNotSame( $updater5, $updater6 );
2445 protected function assertPreparedEditEquals(
2446 PreparedEdit
$edit, PreparedEdit
$edit2, $message = ''
2448 // suppress differences caused by a clock tick between generating the two PreparedEdits
2449 if ( abs( $edit->timestamp
- $edit2->timestamp
) < 3 ) {
2450 $edit2 = clone $edit2;
2451 $edit2->timestamp
= $edit->timestamp
;
2453 $this->assertEquals( $edit, $edit2, $message );
2456 protected function assertPreparedEditNotEquals(
2457 PreparedEdit
$edit, PreparedEdit
$edit2, $message = ''
2459 if ( abs( $edit->timestamp
- $edit2->timestamp
) < 3 ) {
2460 $edit2 = clone $edit2;
2461 $edit2->timestamp
= $edit->timestamp
;
2463 $this->assertNotEquals( $edit, $edit2, $message );