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 $p WikiPage */
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()->getNativeData() );
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->getNativeData() );
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, is_null( $t ) ?
null : $t->getFullText() );
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 $c = $page->replaceSectionContent( $section, $content, $sectionTitle );
1114 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
1118 * @dataProvider dataReplaceSection
1119 * @covers WikiPage::replaceSectionAtRev
1121 public function testReplaceSectionAtRev( $title, $model, $text, $section,
1122 $with, $sectionTitle, $expected
1124 $page = $this->createPage( $title, $text, $model );
1125 $baseRevId = $page->getLatest();
1127 $content = ContentHandler
::makeContent( $with, $page->getTitle(), $page->getContentModel() );
1128 $c = $page->replaceSectionAtRev( $section, $content, $sectionTitle, $baseRevId );
1130 $this->assertEquals( $expected, is_null( $c ) ?
null : trim( $c->getNativeData() ) );
1134 * @covers WikiPage::getOldestRevision
1136 public function testGetOldestRevision() {
1137 $page = $this->newPage( __METHOD__
);
1138 $page->doEditContent(
1139 new WikitextContent( 'one' ),
1143 $rev1 = $page->getRevision();
1145 $page = new WikiPage( $page->getTitle() );
1146 $page->doEditContent(
1147 new WikitextContent( 'two' ),
1152 $page = new WikiPage( $page->getTitle() );
1153 $page->doEditContent(
1154 new WikitextContent( 'three' ),
1160 $this->assertNotEquals(
1162 $page->getRevision()->getId(),
1163 '$page->getRevision()->getId()'
1167 $this->assertEquals(
1169 $page->getOldestRevision()->getId(),
1170 '$page->getOldestRevision()->getId()'
1175 * @covers WikiPage::doRollback
1176 * @covers WikiPage::commitRollback
1178 public function testDoRollback() {
1179 // FIXME: fails under postgres
1180 $this->markTestSkippedIfDbType( 'postgres' );
1182 $admin = $this->getTestSysop()->getUser();
1183 $user1 = $this->getTestUser()->getUser();
1184 // Use the confirmed group for user2 to make sure the user is different
1185 $user2 = $this->getTestUser( [ 'confirmed' ] )->getUser();
1187 // make sure we can test autopatrolling
1188 $this->setMwGlobals( 'wgUseRCPatrol', true );
1190 // TODO: MCR: test rollback of multiple slots!
1191 $page = $this->newPage( __METHOD__
);
1195 $status1 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1196 "section one", EDIT_NEW
, false, $admin );
1199 $status2 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1200 "adding section two", 0, false, $user1 );
1202 $text .= "\n\nthree";
1203 $status3 = $page->doEditContent( ContentHandler
::makeContent( $text, $page->getTitle() ),
1204 "adding section three", 0, false, $user2 );
1206 /** @var Revision $rev1 */
1207 /** @var Revision $rev2 */
1208 /** @var Revision $rev3 */
1209 $rev1 = $status1->getValue()['revision'];
1210 $rev2 = $status2->getValue()['revision'];
1211 $rev3 = $status3->getValue()['revision'];
1214 * We are having issues with doRollback spuriously failing. Apparently
1215 * the last revision somehow goes missing or not committed under some
1216 * circumstances. So, make sure the revisions have the correct usernames.
1218 $this->assertEquals( 3, Revision
::countByPageId( wfGetDB( DB_REPLICA
), $page->getId() ) );
1219 $this->assertEquals( $admin->getName(), $rev1->getUserText() );
1220 $this->assertEquals( $user1->getName(), $rev2->getUserText() );
1221 $this->assertEquals( $user2->getName(), $rev3->getUserText() );
1223 // Now, try the actual rollback
1224 $token = $admin->getEditToken( 'rollback' );
1225 $rollbackErrors = $page->doRollback(
1234 if ( $rollbackErrors ) {
1236 "Rollback failed:\n" .
1237 print_r( $rollbackErrors, true ) . ";\n" .
1238 print_r( $resultDetails, true )
1242 $page = new WikiPage( $page->getTitle() );
1243 $this->assertEquals( $rev2->getSha1(), $page->getRevision()->getSha1(),
1244 "rollback did not revert to the correct revision" );
1245 $this->assertEquals( "one\n\ntwo", $page->getContent()->getNativeData() );
1247 $rc = MediaWikiServices
::getInstance()->getRevisionStore()->getRecentChange(
1248 $page->getRevision()->getRevisionRecord()
1251 $this->assertNotNull( $rc, 'RecentChanges entry' );
1252 $this->assertEquals(
1253 RecentChange
::PRC_AUTOPATROLLED
,
1254 $rc->getAttribute( 'rc_patrolled' ),
1258 // TODO: MCR: assert origin once we write slot data
1259 // $mainSlot = $page->getRevision()->getRevisionRecord()->getSlot( SlotRecord::MAIN );
1260 // $this->assertTrue( $mainSlot->isInherited(), 'isInherited' );
1261 // $this->assertSame( $rev2->getId(), $mainSlot->getOrigin(), 'getOrigin' );
1265 * @covers WikiPage::doRollback
1266 * @covers WikiPage::commitRollback
1268 public function testDoRollbackFailureSameContent() {
1269 $admin = $this->getTestSysop()->getUser();
1272 $page = $this->newPage( __METHOD__
);
1273 $page->doEditContent(
1274 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1280 $rev1 = $page->getRevision();
1282 $user1 = $this->getTestUser( [ 'sysop' ] )->getUser();
1284 $page = new WikiPage( $page->getTitle() );
1285 $page->doEditContent(
1286 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1287 "adding section two",
1293 # now, do a the rollback from the same user was doing the edit before
1294 $resultDetails = [];
1295 $token = $user1->getEditToken( 'rollback' );
1296 $errors = $page->doRollback(
1298 "testing revert same user",
1305 $this->assertEquals( [], $errors, "Rollback failed same user" );
1307 # now, try the rollback
1308 $resultDetails = [];
1309 $token = $admin->getEditToken( 'rollback' );
1310 $errors = $page->doRollback(
1319 $this->assertEquals(
1329 "Rollback not failed"
1332 $page = new WikiPage( $page->getTitle() );
1333 $this->assertEquals( $rev1->getSha1(), $page->getRevision()->getSha1(),
1334 "rollback did not revert to the correct revision" );
1335 $this->assertEquals( "one", $page->getContent()->getNativeData() );
1339 * Tests tagging for edits that do rollback action
1340 * @covers WikiPage::doRollback
1342 public function testDoRollbackTagging() {
1343 if ( !in_array( 'mw-rollback', ChangeTags
::getSoftwareTags() ) ) {
1344 $this->markTestSkipped( 'Rollback tag deactivated, skipped the test.' );
1347 $admin = new User();
1348 $admin->setName( 'Administrator' );
1349 $admin->addToDatabase();
1351 $text = 'First line';
1352 $page = $this->newPage( 'WikiPageTest_testDoRollbackTagging' );
1353 $page->doEditContent(
1354 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1361 $secondUser = new User();
1362 $secondUser->setName( '92.65.217.32' );
1363 $text .= '\n\nSecond line';
1364 $page = new WikiPage( $page->getTitle() );
1365 $page->doEditContent(
1366 ContentHandler
::makeContent( $text, $page->getTitle(), CONTENT_MODEL_WIKITEXT
),
1367 'Adding second line',
1373 // Now, try the rollback
1374 $admin->addGroup( 'sysop' ); // Make the test user a sysop
1375 $token = $admin->getEditToken( 'rollback' );
1376 $errors = $page->doRollback(
1377 $secondUser->getName(),
1385 // If doRollback completed without errors
1386 if ( $errors === [] ) {
1387 $tags = $resultDetails[ 'tags' ];
1388 $this->assertContains( 'mw-rollback', $tags );
1392 public function provideGetAutoDeleteReason() {
1402 [ "first edit", null ],
1404 "/first edit.*only contributor/",
1410 [ "first edit", null ],
1411 [ "second edit", null ],
1413 "/second edit.*only contributor/",
1419 [ "first edit", "127.0.2.22" ],
1420 [ "second edit", "127.0.3.33" ],
1430 . "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam "
1431 . " nonumy eirmod tempor invidunt ut labore et dolore magna "
1432 . "aliquyam erat, sed diam voluptua. At vero eos et accusam "
1433 . "et justo duo dolores et ea rebum. Stet clita kasd gubergren, "
1434 . "no sea takimata sanctus est Lorem ipsum dolor sit amet.'",
1438 '/first edit:.*\.\.\."/',
1444 [ "first edit", "127.0.2.22" ],
1445 [ "", "127.0.3.33" ],
1447 "/before blanking.*first edit/",
1455 * @dataProvider provideGetAutoDeleteReason
1456 * @covers WikiPage::getAutoDeleteReason
1458 public function testGetAutoDeleteReason( $edits, $expectedResult, $expectedHistory ) {
1461 // NOTE: assume Help namespace to contain wikitext
1462 $page = $this->newPage( "Help:WikiPageTest_testGetAutoDeleteReason" );
1466 foreach ( $edits as $edit ) {
1469 if ( !empty( $edit[1] ) ) {
1470 $user->setName( $edit[1] );
1475 $content = ContentHandler
::makeContent( $edit[0], $page->getTitle(), $page->getContentModel() );
1477 $page->doEditContent( $content, "test edit $c", $c < 2 ? EDIT_NEW
: 0, false, $user );
1482 $reason = $page->getAutoDeleteReason( $hasHistory );
1484 if ( is_bool( $expectedResult ) ||
is_null( $expectedResult ) ) {
1485 $this->assertEquals( $expectedResult, $reason );
1487 $this->assertTrue( (bool)preg_match( $expectedResult, $reason ),
1488 "Autosummary didn't match expected pattern $expectedResult: $reason" );
1491 $this->assertEquals( $expectedHistory, $hasHistory,
1492 "expected \$hasHistory to be " . var_export( $expectedHistory, true ) );
1494 $page->doDeleteArticle( "done" );
1497 public function providePreSaveTransform() {
1499 [ 'hello this is ~~~',
1500 "hello this is [[Special:Contributions/127.0.0.1|127.0.0.1]]",
1502 [ 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1503 'hello \'\'this\'\' is <nowiki>~~~</nowiki>',
1509 * @covers WikiPage::factory
1511 public function testWikiPageFactory() {
1512 $title = Title
::makeTitle( NS_FILE
, 'Someimage.png' );
1513 $page = WikiPage
::factory( $title );
1514 $this->assertEquals( WikiFilePage
::class, get_class( $page ) );
1516 $title = Title
::makeTitle( NS_CATEGORY
, 'SomeCategory' );
1517 $page = WikiPage
::factory( $title );
1518 $this->assertEquals( WikiCategoryPage
::class, get_class( $page ) );
1520 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1521 $page = WikiPage
::factory( $title );
1522 $this->assertEquals( WikiPage
::class, get_class( $page ) );
1526 * @covers WikiPage::loadPageData
1527 * @covers WikiPage::wasLoadedFrom
1529 public function testLoadPageData() {
1530 $title = Title
::makeTitle( NS_MAIN
, 'SomePage' );
1531 $page = WikiPage
::factory( $title );
1533 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1534 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1535 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1536 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1538 $page->loadPageData( IDBAccessObject
::READ_NORMAL
);
1539 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1540 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1541 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1542 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1544 $page->loadPageData( IDBAccessObject
::READ_LATEST
);
1545 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1546 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1547 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1548 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1550 $page->loadPageData( IDBAccessObject
::READ_LOCKING
);
1551 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1552 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1553 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1554 $this->assertFalse( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1556 $page->loadPageData( IDBAccessObject
::READ_EXCLUSIVE
);
1557 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_NORMAL
) );
1558 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LATEST
) );
1559 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_LOCKING
) );
1560 $this->assertTrue( $page->wasLoadedFrom( IDBAccessObject
::READ_EXCLUSIVE
) );
1564 * @covers WikiPage::updateCategoryCounts
1566 public function testUpdateCategoryCounts() {
1567 $page = new WikiPage( Title
::newFromText( __METHOD__
) );
1569 // Add an initial category
1570 $page->updateCategoryCounts( [ 'A' ], [], 0 );
1572 $this->assertEquals( 1, Category
::newFromName( 'A' )->getPageCount() );
1573 $this->assertEquals( 0, Category
::newFromName( 'B' )->getPageCount() );
1574 $this->assertEquals( 0, Category
::newFromName( 'C' )->getPageCount() );
1576 // Add a new category
1577 $page->updateCategoryCounts( [ 'B' ], [], 0 );
1579 $this->assertEquals( 1, Category
::newFromName( 'A' )->getPageCount() );
1580 $this->assertEquals( 1, Category
::newFromName( 'B' )->getPageCount() );
1581 $this->assertEquals( 0, Category
::newFromName( 'C' )->getPageCount() );
1583 // Add and remove a category
1584 $page->updateCategoryCounts( [ 'C' ], [ 'A' ], 0 );
1586 $this->assertEquals( 0, Category
::newFromName( 'A' )->getPageCount() );
1587 $this->assertEquals( 1, Category
::newFromName( 'B' )->getPageCount() );
1588 $this->assertEquals( 1, Category
::newFromName( 'C' )->getPageCount() );
1591 public function provideUpdateRedirectOn() {
1592 yield
[ '#REDIRECT [[Foo]]', true, null, true, true, 0 ];
1593 yield
[ '#REDIRECT [[Foo]]', true, 'Foo', true, false, 1 ];
1594 yield
[ 'SomeText', false, null, false, true, 0 ];
1595 yield
[ 'SomeText', false, 'Foo', false, false, 1 ];
1599 * @dataProvider provideUpdateRedirectOn
1600 * @covers WikiPage::updateRedirectOn
1602 * @param string $initialText
1603 * @param bool $initialRedirectState
1604 * @param string|null $redirectTitle
1605 * @param bool|null $lastRevIsRedirect
1606 * @param bool $expectedSuccess
1607 * @param int $expectedRowCount
1609 public function testUpdateRedirectOn(
1611 $initialRedirectState,
1617 // FIXME: fails under sqlite and postgres
1618 $this->markTestSkippedIfDbType( 'sqlite' );
1619 $this->markTestSkippedIfDbType( 'postgres' );
1620 static $pageCounter = 0;
1623 $page = $this->createPage( Title
::newFromText( __METHOD__
. $pageCounter ), $initialText );
1624 $this->assertSame( $initialRedirectState, $page->isRedirect() );
1626 $redirectTitle = is_string( $redirectTitle )
1627 ? Title
::newFromText( $redirectTitle )
1630 $success = $page->updateRedirectOn( $this->db
, $redirectTitle, $lastRevIsRedirect );
1631 $this->assertSame( $expectedSuccess, $success, 'Success assertion' );
1633 * updateRedirectOn explicitly updates the redirect table (and not the page table).
1634 * Most of core checks the page table for redirect status, so we have to be ugly and
1635 * assert a select from the table here.
1637 $this->assertRedirectTableCountForPageId( $page->getId(), $expectedRowCount );
1640 private function assertRedirectTableCountForPageId( $pageId, $expected ) {
1641 $this->assertSelect(
1644 [ 'rd_from' => $pageId ],
1645 [ [ strval( $expected ) ] ]
1650 * @covers WikiPage::insertRedirectEntry
1652 public function testInsertRedirectEntry_insertsRedirectEntry() {
1653 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1654 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1656 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1657 $targetTitle->mInterwiki
= 'eninter';
1658 $page->insertRedirectEntry( $targetTitle, null );
1660 $this->assertSelect(
1662 [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
1663 [ 'rd_from' => $page->getId() ],
1665 strval( $page->getId() ),
1666 strval( $targetTitle->getNamespace() ),
1667 strval( $targetTitle->getDBkey() ),
1668 strval( $targetTitle->getFragment() ),
1669 strval( $targetTitle->getInterwiki() ),
1675 * @covers WikiPage::insertRedirectEntry
1677 public function testInsertRedirectEntry_insertsRedirectEntryWithPageLatest() {
1678 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1679 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1681 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1682 $targetTitle->mInterwiki
= 'eninter';
1683 $page->insertRedirectEntry( $targetTitle, $page->getLatest() );
1685 $this->assertSelect(
1687 [ 'rd_from', 'rd_namespace', 'rd_title', 'rd_fragment', 'rd_interwiki' ],
1688 [ 'rd_from' => $page->getId() ],
1690 strval( $page->getId() ),
1691 strval( $targetTitle->getNamespace() ),
1692 strval( $targetTitle->getDBkey() ),
1693 strval( $targetTitle->getFragment() ),
1694 strval( $targetTitle->getInterwiki() ),
1700 * @covers WikiPage::insertRedirectEntry
1702 public function testInsertRedirectEntry_doesNotInsertIfPageLatestIncorrect() {
1703 $page = $this->createPage( Title
::newFromText( __METHOD__
), 'A' );
1704 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1706 $targetTitle = Title
::newFromText( 'SomeTarget#Frag' );
1707 $targetTitle->mInterwiki
= 'eninter';
1708 $page->insertRedirectEntry( $targetTitle, 215251 );
1710 $this->assertRedirectTableCountForPageId( $page->getId(), 0 );
1713 private function getRow( array $overrides = [] ) {
1717 'page_is_redirect' => '1',
1718 'page_latest' => '99',
1719 'page_namespace' => '3',
1720 'page_title' => 'JaJaTitle',
1721 'page_restrictions' => 'edit=autoconfirmed,sysop:move=sysop',
1722 'page_touched' => '20120101020202',
1723 'page_links_updated' => '20140101020202',
1725 foreach ( $overrides as $key => $value ) {
1726 $row[$key] = $value;
1728 return (object)$row;
1731 public function provideNewFromRowSuccess() {
1732 yield
'basic row' => [
1734 function ( WikiPage
$wikiPage, self
$test ) {
1735 $test->assertSame( 44, $wikiPage->getId() );
1736 $test->assertSame( 76, $wikiPage->getTitle()->getLength() );
1737 $test->assertTrue( $wikiPage->isRedirect() );
1738 $test->assertSame( 99, $wikiPage->getLatest() );
1739 $test->assertSame( 3, $wikiPage->getTitle()->getNamespace() );
1740 $test->assertSame( 'JaJaTitle', $wikiPage->getTitle()->getDBkey() );
1743 'edit' => [ 'autoconfirmed', 'sysop' ],
1744 'move' => [ 'sysop' ],
1746 $wikiPage->getTitle()->getAllRestrictions()
1748 $test->assertSame( '20120101020202', $wikiPage->getTouched() );
1749 $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
1752 yield
'different timestamp formats' => [
1754 'page_touched' => '2012-01-01 02:02:02',
1755 'page_links_updated' => '2014-01-01 02:02:02',
1757 function ( WikiPage
$wikiPage, self
$test ) {
1758 $test->assertSame( '20120101020202', $wikiPage->getTouched() );
1759 $test->assertSame( '20140101020202', $wikiPage->getLinksTimestamp() );
1762 yield
'no restrictions' => [
1764 'page_restrictions' => '',
1766 function ( WikiPage
$wikiPage, self
$test ) {
1772 $wikiPage->getTitle()->getAllRestrictions()
1776 yield
'not redirect' => [
1778 'page_is_redirect' => '0',
1780 function ( WikiPage
$wikiPage, self
$test ) {
1781 $test->assertFalse( $wikiPage->isRedirect() );
1787 * @covers WikiPage::newFromRow
1788 * @covers WikiPage::loadFromRow
1789 * @dataProvider provideNewFromRowSuccess
1791 * @param object $row
1792 * @param callable $assertions
1794 public function testNewFromRow( $row, $assertions ) {
1795 $page = WikiPage
::newFromRow( $row, 'fromdb' );
1796 $assertions( $page, $this );
1799 public function provideTestNewFromId_returnsNullOnBadPageId() {
1805 * @covers WikiPage::newFromID
1806 * @dataProvider provideTestNewFromId_returnsNullOnBadPageId
1808 public function testNewFromId_returnsNullOnBadPageId( $pageId ) {
1809 $this->assertNull( WikiPage
::newFromID( $pageId ) );
1813 * @covers WikiPage::newFromID
1815 public function testNewFromId_appearsToFetchCorrectRow() {
1816 $createdPage = $this->createPage( __METHOD__
, 'Xsfaij09' );
1817 $fetchedPage = WikiPage
::newFromID( $createdPage->getId() );
1818 $this->assertSame( $createdPage->getId(), $fetchedPage->getId() );
1819 $this->assertEquals(
1820 $createdPage->getContent()->getNativeData(),
1821 $fetchedPage->getContent()->getNativeData()
1826 * @covers WikiPage::newFromID
1828 public function testNewFromId_returnsNullOnNonExistingId() {
1829 $this->assertNull( WikiPage
::newFromID( 2147483647 ) );
1832 public function provideTestInsertProtectNullRevision() {
1833 // phpcs:disable Generic.Files.LineLength
1836 [ 'edit' => 'sysop' ],
1837 [ 'edit' => '20200101040404' ],
1841 '(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)))'
1845 [ 'edit' => 'sysop', 'move' => 'something' ],
1846 [ 'edit' => '20200101040404', 'move' => '20210101050505' ],
1850 '(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)))'
1856 * @dataProvider provideTestInsertProtectNullRevision
1857 * @covers WikiPage::insertProtectNullRevision
1858 * @covers WikiPage::protectDescription
1860 * @param string $revCommentMsg
1861 * @param array $limit
1862 * @param array $expiry
1863 * @param bool $cascade
1864 * @param string $reason
1865 * @param bool|null $user true if the test sysop should be used, or null
1866 * @param string $expectedComment
1868 public function testInsertProtectNullRevision(
1877 $this->setContentLang( 'qqx' );
1879 $page = $this->createPage( __METHOD__
, 'Goat' );
1881 $user = $user === null ?
$user : $this->getTestSysop()->getUser();
1883 $result = $page->insertProtectNullRevision(
1892 $this->assertTrue( $result instanceof Revision
);
1893 $this->assertSame( $expectedComment, $result->getComment( Revision
::RAW
) );
1897 * @covers WikiPage::updateRevisionOn
1899 public function testUpdateRevisionOn_existingPage() {
1900 $user = $this->getTestSysop()->getUser();
1901 $page = $this->createPage( __METHOD__
, 'StartText' );
1903 $revision = new Revision(
1906 'page' => $page->getId(),
1907 'title' => $page->getTitle(),
1908 'comment' => __METHOD__
,
1909 'minor_edit' => true,
1910 'text' => __METHOD__
. '-text',
1911 'len' => strlen( __METHOD__
. '-text' ),
1912 'user' => $user->getId(),
1913 'user_text' => $user->getName(),
1914 'timestamp' => '20170707040404',
1915 'content_model' => CONTENT_MODEL_WIKITEXT
,
1916 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1920 $result = $page->updateRevisionOn( $this->db
, $revision );
1921 $this->assertTrue( $result );
1922 $this->assertSame( 9989, $page->getLatest() );
1923 $this->assertEquals( $revision, $page->getRevision() );
1927 * @covers WikiPage::updateRevisionOn
1929 public function testUpdateRevisionOn_NonExistingPage() {
1930 $user = $this->getTestSysop()->getUser();
1931 $page = $this->createPage( __METHOD__
, 'StartText' );
1932 $page->doDeleteArticle( 'reason' );
1934 $revision = new Revision(
1937 'page' => $page->getId(),
1938 'title' => $page->getTitle(),
1939 'comment' => __METHOD__
,
1940 'minor_edit' => true,
1941 'text' => __METHOD__
. '-text',
1942 'len' => strlen( __METHOD__
. '-text' ),
1943 'user' => $user->getId(),
1944 'user_text' => $user->getName(),
1945 'timestamp' => '20170707040404',
1946 'content_model' => CONTENT_MODEL_WIKITEXT
,
1947 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1951 $result = $page->updateRevisionOn( $this->db
, $revision );
1952 $this->assertFalse( $result );
1956 * @covers WikiPage::updateIfNewerOn
1958 public function testUpdateIfNewerOn_olderRevision() {
1959 $user = $this->getTestSysop()->getUser();
1960 $page = $this->createPage( __METHOD__
, 'StartText' );
1961 $initialRevision = $page->getRevision();
1963 $olderTimeStamp = wfTimestamp(
1965 wfTimestamp( TS_UNIX
, $initialRevision->getTimestamp() ) - 1
1968 $olderRevision = new Revision(
1971 'page' => $page->getId(),
1972 'title' => $page->getTitle(),
1973 'comment' => __METHOD__
,
1974 'minor_edit' => true,
1975 'text' => __METHOD__
. '-text',
1976 'len' => strlen( __METHOD__
. '-text' ),
1977 'user' => $user->getId(),
1978 'user_text' => $user->getName(),
1979 'timestamp' => $olderTimeStamp,
1980 'content_model' => CONTENT_MODEL_WIKITEXT
,
1981 'content_format' => CONTENT_FORMAT_WIKITEXT
,
1985 $result = $page->updateIfNewerOn( $this->db
, $olderRevision );
1986 $this->assertFalse( $result );
1990 * @covers WikiPage::updateIfNewerOn
1992 public function testUpdateIfNewerOn_newerRevision() {
1993 $user = $this->getTestSysop()->getUser();
1994 $page = $this->createPage( __METHOD__
, 'StartText' );
1995 $initialRevision = $page->getRevision();
1997 $newerTimeStamp = wfTimestamp(
1999 wfTimestamp( TS_UNIX
, $initialRevision->getTimestamp() ) +
1
2002 $newerRevision = new Revision(
2005 'page' => $page->getId(),
2006 'title' => $page->getTitle(),
2007 'comment' => __METHOD__
,
2008 'minor_edit' => true,
2009 'text' => __METHOD__
. '-text',
2010 'len' => strlen( __METHOD__
. '-text' ),
2011 'user' => $user->getId(),
2012 'user_text' => $user->getName(),
2013 'timestamp' => $newerTimeStamp,
2014 'content_model' => CONTENT_MODEL_WIKITEXT
,
2015 'content_format' => CONTENT_FORMAT_WIKITEXT
,
2018 $result = $page->updateIfNewerOn( $this->db
, $newerRevision );
2019 $this->assertTrue( $result );
2023 * @covers WikiPage::insertOn
2025 public function testInsertOn() {
2026 $title = Title
::newFromText( __METHOD__
);
2027 $page = new WikiPage( $title );
2029 $startTimeStamp = wfTimestampNow();
2030 $result = $page->insertOn( $this->db
);
2031 $endTimeStamp = wfTimestampNow();
2033 $this->assertInternalType( 'int', $result );
2034 $this->assertTrue( $result > 0 );
2036 $condition = [ 'page_id' => $result ];
2038 // Check the default fields have been filled
2039 $this->assertSelect(
2044 'page_restrictions',
2062 // Check the page_random field has been filled
2063 $pageRandom = $this->db
->selectField( 'page', 'page_random', $condition );
2064 $this->assertTrue( (float)$pageRandom < 1 && (float)$pageRandom > 0 );
2066 // Assert the touched timestamp in the DB is roughly when we inserted the page
2067 $pageTouched = $this->db
->selectField( 'page', 'page_touched', $condition );
2069 wfTimestamp( TS_UNIX
, $startTimeStamp )
2070 <= wfTimestamp( TS_UNIX
, $pageTouched )
2073 wfTimestamp( TS_UNIX
, $endTimeStamp )
2074 >= wfTimestamp( TS_UNIX
, $pageTouched )
2077 // Try inserting the same page again and checking the result is false (no change)
2078 $result = $page->insertOn( $this->db
);
2079 $this->assertFalse( $result );
2083 * @covers WikiPage::insertOn
2085 public function testInsertOn_idSpecified() {
2086 $title = Title
::newFromText( __METHOD__
);
2087 $page = new WikiPage( $title );
2090 $result = $page->insertOn( $this->db
, $id );
2092 $this->assertSame( $id, $result );
2094 $condition = [ 'page_id' => $result ];
2096 // Check there is actually a row in the db
2097 $this->assertSelect(
2105 public function provideTestDoUpdateRestrictions_setBasicRestrictions() {
2106 // Note: Once the current dates passes the date in these tests they will fail.
2107 yield
'move something' => [
2109 [ 'move' => 'something' ],
2111 [ 'edit' => [], 'move' => [ 'something' ] ],
2114 yield
'move something, edit blank' => [
2116 [ 'move' => 'something', 'edit' => '' ],
2118 [ 'edit' => [], 'move' => [ 'something' ] ],
2121 yield
'edit sysop, with expiry' => [
2123 [ 'edit' => 'sysop' ],
2124 [ 'edit' => '21330101020202' ],
2125 [ 'edit' => [ 'sysop' ], 'move' => [] ],
2126 [ 'edit' => '21330101020202' ],
2128 yield
'move and edit, move with expiry' => [
2130 [ 'move' => 'something', 'edit' => 'another' ],
2131 [ 'move' => '22220202010101' ],
2132 [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
2133 [ 'move' => '22220202010101' ],
2135 yield
'move and edit, edit with infinity expiry' => [
2137 [ 'move' => 'something', 'edit' => 'another' ],
2138 [ 'edit' => 'infinity' ],
2139 [ 'edit' => [ 'another' ], 'move' => [ 'something' ] ],
2140 [ 'edit' => 'infinity' ],
2142 yield
'non existing, create something' => [
2144 [ 'create' => 'something' ],
2146 [ 'create' => [ 'something' ] ],
2149 yield
'non existing, create something with expiry' => [
2151 [ 'create' => 'something' ],
2152 [ 'create' => '23451212112233' ],
2153 [ 'create' => [ 'something' ] ],
2154 [ 'create' => '23451212112233' ],
2159 * @dataProvider provideTestDoUpdateRestrictions_setBasicRestrictions
2160 * @covers WikiPage::doUpdateRestrictions
2162 public function testDoUpdateRestrictions_setBasicRestrictions(
2166 array $expectedRestrictions,
2167 array $expectedRestrictionExpiries
2169 if ( $pageExists ) {
2170 $page = $this->createPage( __METHOD__
, 'ABC' );
2172 $page = new WikiPage( Title
::newFromText( __METHOD__
. '-nonexist' ) );
2174 $user = $this->getTestSysop()->getUser();
2177 $status = $page->doUpdateRestrictions( $limit, $expiry, $cascade, 'aReason', $user, [] );
2179 $logId = $status->getValue();
2180 $allRestrictions = $page->getTitle()->getAllRestrictions();
2182 $this->assertTrue( $status->isGood() );
2183 $this->assertInternalType( 'int', $logId );
2184 $this->assertSame( $expectedRestrictions, $allRestrictions );
2185 foreach ( $expectedRestrictionExpiries as $key => $value ) {
2186 $this->assertSame( $value, $page->getTitle()->getRestrictionExpiry( $key ) );
2189 // Make sure the log entry looks good
2190 // log_params is not checked here
2191 $actorQuery = ActorMigration
::newMigration()->getJoin( 'log_user' );
2192 $commentQuery = MediaWikiServices
::getInstance()->getCommentStore()->getJoin( 'log_comment' );
2193 $this->assertSelect(
2194 [ 'logging' ] +
$actorQuery['tables'] +
$commentQuery['tables'],
2196 'log_comment' => $commentQuery['fields']['log_comment_text'],
2197 'log_user' => $actorQuery['fields']['log_user'],
2198 'log_user_text' => $actorQuery['fields']['log_user_text'],
2202 [ 'log_id' => $logId ],
2205 (string)$user->getId(),
2207 (string)$page->getTitle()->getNamespace(),
2208 $page->getTitle()->getDBkey(),
2211 $actorQuery['joins'] +
$commentQuery['joins']
2216 * @covers WikiPage::doUpdateRestrictions
2218 public function testDoUpdateRestrictions_failsOnReadOnly() {
2219 $page = $this->createPage( __METHOD__
, 'ABC' );
2220 $user = $this->getTestSysop()->getUser();
2224 $readOnly = $this->getMockBuilder( ReadOnlyMode
::class )
2225 ->disableOriginalConstructor()
2226 ->setMethods( [ 'isReadOnly', 'getReason' ] )
2228 $readOnly->expects( $this->once() )
2229 ->method( 'isReadOnly' )
2230 ->will( $this->returnValue( true ) );
2231 $readOnly->expects( $this->once() )
2232 ->method( 'getReason' )
2233 ->will( $this->returnValue( 'Some Read Only Reason' ) );
2234 $this->setService( 'ReadOnlyMode', $readOnly );
2236 $status = $page->doUpdateRestrictions( [], [], $cascade, 'aReason', $user, [] );
2237 $this->assertFalse( $status->isOK() );
2238 $this->assertSame( 'readonlytext', $status->getMessage()->getKey() );
2242 * @covers WikiPage::doUpdateRestrictions
2244 public function testDoUpdateRestrictions_returnsGoodIfNothingChanged() {
2245 $page = $this->createPage( __METHOD__
, 'ABC' );
2246 $user = $this->getTestSysop()->getUser();
2248 $limit = [ 'edit' => 'sysop' ];
2250 $status = $page->doUpdateRestrictions(
2259 // The first entry should have a logId as it did something
2260 $this->assertTrue( $status->isGood() );
2261 $this->assertInternalType( 'int', $status->getValue() );
2263 $status = $page->doUpdateRestrictions(
2272 // The second entry should not have a logId as nothing changed
2273 $this->assertTrue( $status->isGood() );
2274 $this->assertNull( $status->getValue() );
2278 * @covers WikiPage::doUpdateRestrictions
2280 public function testDoUpdateRestrictions_logEntryTypeAndAction() {
2281 $page = $this->createPage( __METHOD__
, 'ABC' );
2282 $user = $this->getTestSysop()->getUser();
2286 $status = $page->doUpdateRestrictions(
2287 [ 'edit' => 'sysop' ],
2294 $this->assertTrue( $status->isGood() );
2295 $this->assertInternalType( 'int', $status->getValue() );
2296 $this->assertSelect(
2298 [ 'log_type', 'log_action' ],
2299 [ 'log_id' => $status->getValue() ],
2300 [ [ 'protect', 'protect' ] ]
2303 // Modify the protection
2304 $status = $page->doUpdateRestrictions(
2305 [ 'edit' => 'somethingElse' ],
2312 $this->assertTrue( $status->isGood() );
2313 $this->assertInternalType( 'int', $status->getValue() );
2314 $this->assertSelect(
2316 [ 'log_type', 'log_action' ],
2317 [ 'log_id' => $status->getValue() ],
2318 [ [ 'protect', 'modify' ] ]
2321 // Remove the protection
2322 $status = $page->doUpdateRestrictions(
2330 $this->assertTrue( $status->isGood() );
2331 $this->assertInternalType( 'int', $status->getValue() );
2332 $this->assertSelect(
2334 [ 'log_type', 'log_action' ],
2335 [ 'log_id' => $status->getValue() ],
2336 [ [ 'protect', 'unprotect' ] ]
2341 * @covers WikiPage::newPageUpdater
2342 * @covers WikiPage::getDerivedDataUpdater
2344 public function testNewPageUpdater() {
2345 $user = $this->getTestUser()->getUser();
2346 $page = $this->newPage( __METHOD__
, __METHOD__
);
2348 /** @var Content $content */
2349 $content = $this->getMockBuilder( WikitextContent
::class )
2350 ->setConstructorArgs( [ 'Hello World' ] )
2351 ->setMethods( [ 'getParserOutput' ] )
2353 $content->expects( $this->once() )
2354 ->method( 'getParserOutput' )
2355 ->willReturn( new ParserOutput( 'HTML' ) );
2357 $preparedEditBefore = $page->prepareContentForEdit( $content, null, $user );
2359 // provide context, so the cache can be kept in place
2360 $slotsUpdate = new revisionSlotsUpdate();
2361 $slotsUpdate->modifyContent( SlotRecord
::MAIN
, $content );
2363 $updater = $page->newPageUpdater( $user, $slotsUpdate );
2364 $updater->setContent( SlotRecord
::MAIN
, $content );
2365 $revision = $updater->saveRevision(
2366 CommentStoreComment
::newUnsavedComment( 'test' ),
2370 $preparedEditAfter = $page->prepareContentForEdit( $content, $revision, $user );
2372 $this->assertSame( $revision->getId(), $page->getLatest() );
2374 // Parsed output must remain cached throughout.
2375 $this->assertSame( $preparedEditBefore->output
, $preparedEditAfter->output
);
2379 * @covers WikiPage::newPageUpdater
2380 * @covers WikiPage::getDerivedDataUpdater
2382 public function testGetDerivedDataUpdater() {
2383 $admin = $this->getTestSysop()->getUser();
2385 /** @var object $page */
2386 $page = $this->createPage( __METHOD__
, __METHOD__
);
2387 $page = TestingAccessWrapper
::newFromObject( $page );
2389 $revision = $page->getRevision()->getRevisionRecord();
2390 $user = $revision->getUser();
2392 $slotsUpdate = new RevisionSlotsUpdate();
2393 $slotsUpdate->modifyContent( SlotRecord
::MAIN
, new WikitextContent( 'Hello World' ) );
2395 // get a virgin updater
2396 $updater1 = $page->getDerivedDataUpdater( $user );
2397 $this->assertFalse( $updater1->isUpdatePrepared() );
2399 $updater1->prepareUpdate( $revision );
2401 // Re-use updater with same revision or content, even if base changed
2402 $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, $revision ) );
2404 $slotsUpdate = RevisionSlotsUpdate
::newFromContent(
2405 [ SlotRecord
::MAIN
=> $revision->getContent( SlotRecord
::MAIN
) ]
2407 $this->assertSame( $updater1, $page->getDerivedDataUpdater( $user, null, $slotsUpdate ) );
2409 // Don't re-use for edit if base revision ID changed
2410 $this->assertNotSame(
2412 $page->getDerivedDataUpdater( $user, null, $slotsUpdate, true )
2415 // Don't re-use with different user
2416 $updater2a = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
2417 $updater2a->prepareContent( $admin, $slotsUpdate, false );
2419 $updater2b = $page->getDerivedDataUpdater( $user, null, $slotsUpdate );
2420 $updater2b->prepareContent( $user, $slotsUpdate, false );
2421 $this->assertNotSame( $updater2a, $updater2b );
2423 // Don't re-use with different content
2424 $updater3 = $page->getDerivedDataUpdater( $admin, null, $slotsUpdate );
2425 $updater3->prepareUpdate( $revision );
2426 $this->assertNotSame( $updater2b, $updater3 );
2428 // Don't re-use if no context given
2429 $updater4 = $page->getDerivedDataUpdater( $admin );
2430 $updater4->prepareUpdate( $revision );
2431 $this->assertNotSame( $updater3, $updater4 );
2433 // Don't re-use if AGAIN no context given
2434 $updater5 = $page->getDerivedDataUpdater( $admin );
2435 $this->assertNotSame( $updater4, $updater5 );
2437 // Don't re-use cached "virgin" unprepared updater
2438 $updater6 = $page->getDerivedDataUpdater( $admin, $revision );
2439 $this->assertNotSame( $updater5, $updater6 );
2442 protected function assertPreparedEditEquals(
2443 PreparedEdit
$edit, PreparedEdit
$edit2, $message = ''
2445 // suppress differences caused by a clock tick between generating the two PreparedEdits
2446 if ( abs( $edit->timestamp
- $edit2->timestamp
) < 3 ) {
2447 $edit2 = clone $edit2;
2448 $edit2->timestamp
= $edit->timestamp
;
2450 $this->assertEquals( $edit, $edit2, $message );
2453 protected function assertPreparedEditNotEquals(
2454 PreparedEdit
$edit, PreparedEdit
$edit2, $message = ''
2456 if ( abs( $edit->timestamp
- $edit2->timestamp
) < 3 ) {
2457 $edit2 = clone $edit2;
2458 $edit2->timestamp
= $edit->timestamp
;
2460 $this->assertNotEquals( $edit, $edit2, $message );