3 namespace MediaWiki\Tests\Storage
;
5 use CommentStoreComment
;
7 use MediaWiki\MediaWikiServices
;
8 use MediaWiki\Revision\RevisionRecord
;
9 use MediaWiki\Revision\SlotRecord
;
10 use MediaWikiTestCase
;
20 * @covers \MediaWiki\Storage\PageUpdater
23 class PageUpdaterTest
extends MediaWikiTestCase
{
25 public function setUp() {
28 MediaWikiServices
::getInstance()->getSlotRoleRegistry()->defineRoleWithModel(
30 CONTENT_MODEL_WIKITEXT
34 private function getDummyTitle( $method ) {
35 return Title
::newFromText( $method, $this->getDefaultWikitextNS() );
41 * @return null|RecentChange
43 private function getRecentChangeFor( $revId ) {
44 $qi = RecentChange
::getQueryInfo();
45 $row = $this->db
->selectRow(
48 [ 'rc_this_oldid' => $revId ],
54 return $row ? RecentChange
::newFromRow( $row ) : null;
57 // TODO: test setAjaxEditStash();
60 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
61 * @covers \WikiPage::newPageUpdater()
63 public function testCreatePage() {
64 $user = $this->getTestUser()->getUser();
66 $title = $this->getDummyTitle( __METHOD__
);
67 $page = WikiPage
::factory( $title );
68 $updater = $page->newPageUpdater( $user );
70 $oldStats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
72 $this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
73 $this->assertFalse( $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
74 $this->assertSame( 0, $updater->getUndidRevisionId(), 'getUndidRevisionId' );
76 $updater->addTag( 'foo' );
77 $updater->addTags( [ 'bar', 'qux' ] );
79 $tags = $updater->getExplicitTags();
81 $this->assertSame( [ 'bar', 'foo', 'qux' ], $tags, 'getExplicitTags' );
83 // TODO: MCR: test additional slots
84 $content = new TextContent( 'Lorem Ipsum' );
85 $updater->setContent( SlotRecord
::MAIN
, $content );
87 $parent = $updater->grabParentRevision();
89 $this->assertNull( $parent, 'getParentRevision' );
90 $this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
92 // TODO: test that hasEditConflict() grabs the parent revision
93 $this->assertFalse( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
94 $this->assertTrue( $updater->hasEditConflict( 1 ), 'hasEditConflict' );
96 // TODO: test failure with EDIT_UPDATE
97 // TODO: test EDIT_MINOR, EDIT_BOT, etc
98 $summary = CommentStoreComment
::newUnsavedComment( 'Just a test' );
99 $rev = $updater->saveRevision( $summary );
101 $this->assertNotNull( $rev );
102 $this->assertSame( 0, $rev->getParentId() );
103 $this->assertSame( $summary->text
, $rev->getComment( RevisionRecord
::RAW
)->text
);
104 $this->assertSame( $user->getName(), $rev->getUser( RevisionRecord
::RAW
)->getName() );
106 $this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
107 $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
108 $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
109 $this->assertTrue( $updater->isNew(), 'isNew()' );
110 $this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
111 $this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
112 $this->assertInstanceOf( Revision
::class, $updater->getStatus()->value
['revision'] );
114 $rev = $updater->getNewRevision();
115 $revContent = $rev->getContent( SlotRecord
::MAIN
);
116 $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
118 // were the WikiPage and Title objects updated?
119 $this->assertTrue( $page->exists(), 'WikiPage::exists()' );
120 $this->assertTrue( $title->exists(), 'Title::exists()' );
121 $this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
122 $this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
125 $page2 = WikiPage
::factory( $title );
126 $this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
127 $this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
128 $this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
131 $rc = $this->getRecentChangeFor( $rev->getId() );
132 $this->assertNotNull( $rc, 'RecentChange' );
134 // check site stats - this asserts that derived data updates where run.
135 $stats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
136 $this->assertSame( $oldStats->ss_total_pages +
1, (int)$stats->ss_total_pages
);
137 $this->assertSame( $oldStats->ss_total_edits +
1, (int)$stats->ss_total_edits
);
139 // re-edit with same content - should be a "null-edit"
140 $updater = $page->newPageUpdater( $user );
141 $updater->setContent( SlotRecord
::MAIN
, $content );
143 $summary = CommentStoreComment
::newUnsavedComment( 'to to re-edit' );
144 $rev = $updater->saveRevision( $summary );
145 $status = $updater->getStatus();
147 $this->assertNull( $rev, 'getNewRevision()' );
148 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
149 $this->assertTrue( $updater->isUnchanged(), 'isUnchanged' );
150 $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
151 $this->assertTrue( $status->isOK(), 'getStatus()->isOK()' );
152 $this->assertTrue( $status->hasMessage( 'edit-no-change' ), 'edit-no-change' );
156 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
157 * @covers \WikiPage::newPageUpdater()
159 public function testUpdatePage() {
160 $user = $this->getTestUser()->getUser();
162 $title = $this->getDummyTitle( __METHOD__
);
163 $this->insertPage( $title );
165 $page = WikiPage
::factory( $title );
166 $parentId = $page->getLatest();
168 $updater = $page->newPageUpdater( $user );
170 $oldStats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
172 $updater->setOriginalRevisionId( 7 );
173 $this->assertSame( 7, $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
175 $this->assertFalse( $updater->hasEditConflict( $parentId ), 'hasEditConflict' );
176 $this->assertTrue( $updater->hasEditConflict( $parentId - 1 ), 'hasEditConflict' );
177 $this->assertTrue( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
179 // TODO: MCR: test additional slots
180 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem Ipsum' ) );
182 // TODO: test all flags for saveRevision()!
183 $summary = CommentStoreComment
::newUnsavedComment( 'Just a test' );
184 $rev = $updater->saveRevision( $summary );
186 $this->assertNotNull( $rev );
187 $this->assertSame( $parentId, $rev->getParentId() );
188 $this->assertSame( $summary->text
, $rev->getComment( RevisionRecord
::RAW
)->text
);
189 $this->assertSame( $user->getName(), $rev->getUser( RevisionRecord
::RAW
)->getName() );
191 $this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
192 $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
193 $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
194 $this->assertFalse( $updater->isNew(), 'isNew()' );
195 $this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
196 $this->assertInstanceOf( Revision
::class, $updater->getStatus()->value
['revision'] );
197 $this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
199 // TODO: Test null revision (with different user): new revision!
201 $rev = $updater->getNewRevision();
202 $revContent = $rev->getContent( SlotRecord
::MAIN
);
203 $this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
205 // were the WikiPage and Title objects updated?
206 $this->assertTrue( $page->exists(), 'WikiPage::exists()' );
207 $this->assertTrue( $title->exists(), 'Title::exists()' );
208 $this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
209 $this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
212 $page2 = WikiPage
::factory( $title );
213 $this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
214 $this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
215 $this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
218 $rc = $this->getRecentChangeFor( $rev->getId() );
219 $this->assertNotNull( $rc, 'RecentChange' );
222 $updater = $page->newPageUpdater( $user );
223 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'dolor sit amet' ) );
225 $summary = CommentStoreComment
::newUnsavedComment( 're-edit' );
226 $updater->saveRevision( $summary );
227 $this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
228 $this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
230 // check site stats - this asserts that derived data updates where run.
231 $stats = $this->db
->selectRow( 'site_stats', '*', '1=1' );
232 $this->assertNotNull( $stats, 'site_stats' );
233 $this->assertSame( $oldStats->ss_total_pages +
0, (int)$stats->ss_total_pages
);
234 $this->assertSame( $oldStats->ss_total_edits +
2, (int)$stats->ss_total_edits
);
238 * Creates a revision in the database.
240 * @param WikiPage $page
242 * @param null|string|Content $content
244 * @return RevisionRecord|null
246 private function createRevision( WikiPage
$page, $summary, $content = null ) {
247 $user = $this->getTestUser()->getUser();
248 $comment = CommentStoreComment
::newUnsavedComment( $summary );
250 if ( !$content instanceof Content
) {
251 $content = new TextContent( $content ??
$summary );
254 $updater = $page->newPageUpdater( $user );
255 $updater->setContent( SlotRecord
::MAIN
, $content );
256 $rev = $updater->saveRevision( $comment );
261 * @covers \MediaWiki\Storage\PageUpdater::grabParentRevision()
262 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
264 public function testCompareAndSwapFailure() {
265 $user = $this->getTestUser()->getUser();
267 $title = $this->getDummyTitle( __METHOD__
);
269 // start editing non-existing page
270 $page = WikiPage
::factory( $title );
271 $updater = $page->newPageUpdater( $user );
272 $updater->grabParentRevision();
274 // create page concurrently
275 $concurrentPage = WikiPage
::factory( $title );
276 $this->createRevision( $concurrentPage, __METHOD__
. '-one' );
278 // try creating the page - should trigger CAS failure.
279 $summary = CommentStoreComment
::newUnsavedComment( 'create?!' );
280 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem ipsum' ) );
281 $updater->saveRevision( $summary );
282 $status = $updater->getStatus();
284 $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
285 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
286 $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
287 $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-conflict' );
289 // start editing existing page
290 $page = WikiPage
::factory( $title );
291 $updater = $page->newPageUpdater( $user );
292 $updater->grabParentRevision();
294 // update page concurrently
295 $concurrentPage = WikiPage
::factory( $title );
296 $this->createRevision( $concurrentPage, __METHOD__
. '-two' );
298 // try creating the page - should trigger CAS failure.
299 $summary = CommentStoreComment
::newUnsavedComment( 'edit?!' );
300 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'dolor sit amet' ) );
301 $updater->saveRevision( $summary );
302 $status = $updater->getStatus();
304 $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
305 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
306 $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
307 $this->assertTrue( $status->hasMessage( 'edit-conflict' ), 'edit-conflict' );
311 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
313 public function testFailureOnEditFlags() {
314 $user = $this->getTestUser()->getUser();
316 $title = $this->getDummyTitle( __METHOD__
);
318 // start editing non-existing page
319 $page = WikiPage
::factory( $title );
320 $updater = $page->newPageUpdater( $user );
322 // update with EDIT_UPDATE flag should fail
323 $summary = CommentStoreComment
::newUnsavedComment( 'udpate?!' );
324 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem ipsum' ) );
325 $updater->saveRevision( $summary, EDIT_UPDATE
);
326 $status = $updater->getStatus();
328 $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
329 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
330 $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
331 $this->assertTrue( $status->hasMessage( 'edit-gone-missing' ), 'edit-gone-missing' );
334 $this->createRevision( $page, __METHOD__
);
336 // update with EDIT_NEW flag should fail
337 $summary = CommentStoreComment
::newUnsavedComment( 'create?!' );
338 $updater = $page->newPageUpdater( $user );
339 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'dolor sit amet' ) );
340 $updater->saveRevision( $summary, EDIT_NEW
);
341 $status = $updater->getStatus();
343 $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
344 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
345 $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
346 $this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-already-exists' );
350 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
352 public function testFailureOnBadContentModel() {
353 $user = $this->getTestUser()->getUser();
354 $title = $this->getDummyTitle( __METHOD__
);
356 // start editing non-existing page
357 $page = WikiPage
::factory( $title );
358 $updater = $page->newPageUpdater( $user );
360 // plain text content should fail in aux slot (the main slot doesn't care)
361 $updater->setContent( 'main', new TextContent( 'Main Content' ) );
362 $updater->setContent( 'aux', new TextContent( 'Aux Content' ) );
364 $summary = CommentStoreComment
::newUnsavedComment( 'udpate?!' );
365 $updater->saveRevision( $summary, EDIT_UPDATE
);
366 $status = $updater->getStatus();
368 $this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
369 $this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
370 $this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
372 $status->hasMessage( 'content-not-allowed-here' ),
373 'content-not-allowed-here'
377 public function provideSetRcPatrolStatus( $patrolled ) {
378 yield
[ RecentChange
::PRC_UNPATROLLED
];
379 yield
[ RecentChange
::PRC_AUTOPATROLLED
];
383 * @dataProvider provideSetRcPatrolStatus
384 * @covers \MediaWiki\Storage\PageUpdater::setRcPatrolStatus()
386 public function testSetRcPatrolStatus( $patrolled ) {
387 $revisionStore = MediaWikiServices
::getInstance()->getRevisionStore();
389 $user = $this->getTestUser()->getUser();
391 $title = $this->getDummyTitle( __METHOD__
);
393 $page = WikiPage
::factory( $title );
394 $updater = $page->newPageUpdater( $user );
396 $summary = CommentStoreComment
::newUnsavedComment( 'Lorem ipsum ' . $patrolled );
397 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem ipsum ' . $patrolled ) );
398 $updater->setRcPatrolStatus( $patrolled );
399 $rev = $updater->saveRevision( $summary );
401 $rc = $revisionStore->getRecentChange( $rev );
402 $this->assertEquals( $patrolled, $rc->getAttribute( 'rc_patrolled' ) );
406 * @covers \MediaWiki\Storage\PageUpdater::inheritSlot()
407 * @covers \MediaWiki\Storage\PageUpdater::setContent()
409 public function testInheritSlot() {
410 $user = $this->getTestUser()->getUser();
411 $title = $this->getDummyTitle( __METHOD__
);
412 $page = WikiPage
::factory( $title );
414 $updater = $page->newPageUpdater( $user );
415 $summary = CommentStoreComment
::newUnsavedComment( 'one' );
416 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem ipsum' ) );
417 $rev1 = $updater->saveRevision( $summary, EDIT_NEW
);
419 $updater = $page->newPageUpdater( $user );
420 $summary = CommentStoreComment
::newUnsavedComment( 'two' );
421 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Foo Bar' ) );
422 $rev2 = $updater->saveRevision( $summary, EDIT_UPDATE
);
424 $updater = $page->newPageUpdater( $user );
425 $summary = CommentStoreComment
::newUnsavedComment( 'three' );
426 $updater->inheritSlot( $rev1->getSlot( SlotRecord
::MAIN
) );
427 $rev3 = $updater->saveRevision( $summary, EDIT_UPDATE
);
429 $this->assertNotSame( $rev1->getId(), $rev3->getId() );
430 $this->assertNotSame( $rev2->getId(), $rev3->getId() );
432 $main1 = $rev1->getSlot( SlotRecord
::MAIN
);
433 $main3 = $rev3->getSlot( SlotRecord
::MAIN
);
435 $this->assertNotSame( $main1->getRevision(), $main3->getRevision() );
436 $this->assertSame( $main1->getAddress(), $main3->getAddress() );
437 $this->assertTrue( $main1->getContent()->equals( $main3->getContent() ) );
440 // TODO: MCR: test adding multiple slots, inheriting parent slots, and removing slots.
442 public function testSetUseAutomaticEditSummaries() {
443 $this->setContentLang( 'qqx' );
444 $user = $this->getTestUser()->getUser();
446 $title = $this->getDummyTitle( __METHOD__
);
447 $page = WikiPage
::factory( $title );
449 $updater = $page->newPageUpdater( $user );
450 $updater->setUseAutomaticEditSummaries( true );
451 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem Ipsum' ) );
453 // empty comment triggers auto-summary
454 $summary = CommentStoreComment
::newUnsavedComment( '' );
455 $updater->saveRevision( $summary, EDIT_AUTOSUMMARY
);
457 $rev = $updater->getNewRevision();
458 $comment = $rev->getComment( RevisionRecord
::RAW
);
459 $this->assertSame( '(autosumm-new: Lorem Ipsum)', $comment->text
, 'comment text' );
461 // check that this also works when blanking the page
462 $updater = $page->newPageUpdater( $user );
463 $updater->setUseAutomaticEditSummaries( true );
464 $updater->setContent( SlotRecord
::MAIN
, new TextContent( '' ) );
466 $summary = CommentStoreComment
::newUnsavedComment( '' );
467 $updater->saveRevision( $summary, EDIT_AUTOSUMMARY
);
469 $rev = $updater->getNewRevision();
470 $comment = $rev->getComment( RevisionRecord
::RAW
);
471 $this->assertSame( '(autosumm-blank)', $comment->text
, 'comment text' );
473 // check that we can also disable edit-summaries
474 $title2 = $this->getDummyTitle( __METHOD__
. '/2' );
475 $page2 = WikiPage
::factory( $title2 );
477 $updater = $page2->newPageUpdater( $user );
478 $updater->setUseAutomaticEditSummaries( false );
479 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem Ipsum' ) );
481 $summary = CommentStoreComment
::newUnsavedComment( '' );
482 $updater->saveRevision( $summary, EDIT_AUTOSUMMARY
);
484 $rev = $updater->getNewRevision();
485 $comment = $rev->getComment( RevisionRecord
::RAW
);
486 $this->assertSame( '', $comment->text
, 'comment text should still be lank' );
488 // check that we don't do auto.summaries without the EDIT_AUTOSUMMARY flag
489 $updater = $page2->newPageUpdater( $user );
490 $updater->setUseAutomaticEditSummaries( true );
491 $updater->setContent( SlotRecord
::MAIN
, new TextContent( '' ) );
493 $summary = CommentStoreComment
::newUnsavedComment( '' );
494 $updater->saveRevision( $summary, 0 );
496 $rev = $updater->getNewRevision();
497 $comment = $rev->getComment( RevisionRecord
::RAW
);
498 $this->assertSame( '', $comment->text
, 'comment text' );
501 public function provideSetUsePageCreationLog() {
502 yield
[ true, [ [ 'create', 'create' ] ] ];
507 * @dataProvider provideSetUsePageCreationLog
510 public function testSetUsePageCreationLog( $use, $expected ) {
511 $user = $this->getTestUser()->getUser();
512 $title = $this->getDummyTitle( __METHOD__
. ( $use ?
'_logged' : '_unlogged' ) );
513 $page = WikiPage
::factory( $title );
515 $updater = $page->newPageUpdater( $user );
516 $updater->setUsePageCreationLog( $use );
517 $summary = CommentStoreComment
::newUnsavedComment( 'cmt' );
518 $updater->setContent( SlotRecord
::MAIN
, new TextContent( 'Lorem Ipsum' ) );
519 $updater->saveRevision( $summary, EDIT_NEW
);
521 $rev = $updater->getNewRevision();
524 [ 'log_type', 'log_action' ],
525 [ 'log_page' => $rev->getPageId() ],
530 public function provideMagicWords() {
532 'Test {{PAGEID}} Test',
533 function ( RevisionRecord
$rev ) {
534 return $rev->getPageId();
538 yield
'REVISIONID' => [
539 'Test {{REVISIONID}} Test',
540 function ( RevisionRecord
$rev ) {
541 return $rev->getId();
545 yield
'REVISIONUSER' => [
546 'Test {{REVISIONUSER}} Test',
547 function ( RevisionRecord
$rev ) {
548 return $rev->getUser()->getName();
552 yield
'REVISIONTIMESTAMP' => [
553 'Test {{REVISIONTIMESTAMP}} Test',
554 function ( RevisionRecord
$rev ) {
555 return $rev->getTimestamp();
559 yield
'subst:REVISIONUSER' => [
560 'Test {{subst:REVISIONUSER}} Test',
561 function ( RevisionRecord
$rev ) {
562 return $rev->getUser()->getName();
567 yield
'subst:PAGENAME' => [
568 'Test {{subst:PAGENAME}} Test',
569 function ( RevisionRecord
$rev ) {
570 return 'PageUpdaterTest::testMagicWords';
577 * @covers \MediaWiki\Storage\PageUpdater::saveRevision()
579 * Integration test for PageUpdater, DerivedPageDataUpdater, RevisionRenderer
580 * and RenderedRevision, that ensures that magic words depending on revision meta-data
581 * are handled correctly. Note that each magic word needs to be tested separately,
582 * to assert correct behavior for each "vary" flag in the ParserOutput.
584 * @dataProvider provideMagicWords
586 public function testMagicWords( $wikitext, $callback, $subst = false ) {
587 $user = User
::newFromName( 'A user for ' . __METHOD__
);
588 $user->addToDatabase();
590 $title = $this->getDummyTitle( __METHOD__
. '-' . $this->getName() );
591 $this->insertPage( $title );
593 $page = WikiPage
::factory( $title );
594 $updater = $page->newPageUpdater( $user );
596 $updater->setContent( SlotRecord
::MAIN
, new \
WikitextContent( $wikitext ) );
598 $summary = CommentStoreComment
::newUnsavedComment( 'Just a test' );
599 $rev = $updater->saveRevision( $summary, EDIT_UPDATE
);
602 $this->fail( $updater->getStatus()->getWikiText() );
605 $expected = strval( $callback( $rev ) );
607 $output = $page->getParserOutput( ParserOptions
::newCanonical( 'canonical' ) );
608 $html = $output->getText();
609 $text = $rev->getContent( SlotRecord
::MAIN
)->serialize();
612 $this->assertContains( $expected, $text, 'In Wikitext' );
615 $this->assertContains( $expected, $html, 'In HTML' );