2018-01-27 01:48:19 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace MediaWiki\Tests\Storage;
|
|
|
|
|
|
|
|
|
|
use CommentStoreComment;
|
|
|
|
|
use Content;
|
|
|
|
|
use MediaWiki\MediaWikiServices;
|
2018-10-15 10:37:39 +00:00
|
|
|
use MediaWiki\Revision\RenderedRevision;
|
2018-09-20 17:29:04 +00:00
|
|
|
use MediaWiki\Revision\RevisionRecord;
|
|
|
|
|
use MediaWiki\Revision\SlotRecord;
|
2018-01-27 01:48:19 +00:00
|
|
|
use MediaWikiTestCase;
|
2018-08-07 16:52:40 +00:00
|
|
|
use ParserOptions;
|
2018-01-27 01:48:19 +00:00
|
|
|
use RecentChange;
|
|
|
|
|
use Revision;
|
2018-10-15 10:37:39 +00:00
|
|
|
use Status;
|
2018-01-27 01:48:19 +00:00
|
|
|
use TextContent;
|
|
|
|
|
use Title;
|
2018-09-05 18:03:15 +00:00
|
|
|
use User;
|
2020-04-09 12:06:22 +00:00
|
|
|
use Wikimedia\AtEase\AtEase;
|
2018-01-27 01:48:19 +00:00
|
|
|
use WikiPage;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater
|
|
|
|
|
* @group Database
|
|
|
|
|
*/
|
|
|
|
|
class PageUpdaterTest extends MediaWikiTestCase {
|
2018-09-05 18:03:15 +00:00
|
|
|
|
2020-06-14 10:51:39 +00:00
|
|
|
protected function setUp() : void {
|
2018-11-19 11:39:56 +00:00
|
|
|
parent::setUp();
|
|
|
|
|
|
2020-04-09 12:06:22 +00:00
|
|
|
$slotRoleRegistry = MediaWikiServices::getInstance()->getSlotRoleRegistry();
|
|
|
|
|
|
|
|
|
|
if ( !$slotRoleRegistry->isDefinedRole( 'aux' ) ) {
|
|
|
|
|
$slotRoleRegistry->defineRoleWithModel(
|
|
|
|
|
'aux',
|
|
|
|
|
CONTENT_MODEL_WIKITEXT
|
|
|
|
|
);
|
|
|
|
|
}
|
2018-11-24 15:59:58 +00:00
|
|
|
|
|
|
|
|
$this->tablesUsed[] = 'logging';
|
|
|
|
|
$this->tablesUsed[] = 'recentchanges';
|
2018-11-19 11:39:56 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
private function getDummyTitle( $method ) {
|
|
|
|
|
return Title::newFromText( $method, $this->getDefaultWikitextNS() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $revId
|
|
|
|
|
*
|
|
|
|
|
* @return null|RecentChange
|
|
|
|
|
*/
|
|
|
|
|
private function getRecentChangeFor( $revId ) {
|
|
|
|
|
$qi = RecentChange::getQueryInfo();
|
|
|
|
|
$row = $this->db->selectRow(
|
|
|
|
|
$qi['tables'],
|
|
|
|
|
$qi['fields'],
|
|
|
|
|
[ 'rc_this_oldid' => $revId ],
|
|
|
|
|
__METHOD__,
|
|
|
|
|
[],
|
|
|
|
|
$qi['joins']
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return $row ? RecentChange::newFromRow( $row ) : null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: test setAjaxEditStash();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
* @covers \WikiPage::newPageUpdater()
|
|
|
|
|
*/
|
|
|
|
|
public function testCreatePage() {
|
2020-04-18 02:39:58 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::getRevision' );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
|
|
|
|
$oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
|
2018-06-19 14:09:01 +00:00
|
|
|
$this->assertFalse( $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( 0, $updater->getUndidRevisionId(), 'getUndidRevisionId' );
|
|
|
|
|
|
|
|
|
|
$updater->addTag( 'foo' );
|
|
|
|
|
$updater->addTags( [ 'bar', 'qux' ] );
|
|
|
|
|
|
|
|
|
|
$tags = $updater->getExplicitTags();
|
|
|
|
|
sort( $tags );
|
|
|
|
|
$this->assertSame( [ 'bar', 'foo', 'qux' ], $tags, 'getExplicitTags' );
|
|
|
|
|
|
|
|
|
|
// TODO: MCR: test additional slots
|
|
|
|
|
$content = new TextContent( 'Lorem Ipsum' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, $content );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$parent = $updater->grabParentRevision();
|
|
|
|
|
|
|
|
|
|
$this->assertNull( $parent, 'getParentRevision' );
|
|
|
|
|
$this->assertFalse( $updater->wasCommitted(), 'wasCommitted' );
|
2018-06-19 14:09:01 +00:00
|
|
|
|
|
|
|
|
// TODO: test that hasEditConflict() grabs the parent revision
|
|
|
|
|
$this->assertFalse( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
|
|
|
|
|
$this->assertTrue( $updater->hasEditConflict( 1 ), 'hasEditConflict' );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: test failure with EDIT_UPDATE
|
|
|
|
|
// TODO: test EDIT_MINOR, EDIT_BOT, etc
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
|
|
|
|
|
$this->assertNotNull( $rev );
|
|
|
|
|
$this->assertSame( 0, $rev->getParentId() );
|
|
|
|
|
$this->assertSame( $summary->text, $rev->getComment( RevisionRecord::RAW )->text );
|
|
|
|
|
$this->assertSame( $user->getName(), $rev->getUser( RevisionRecord::RAW )->getName() );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $updater->isNew(), 'isNew()' );
|
|
|
|
|
$this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
|
|
|
|
|
$this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertInstanceOf( Revision::class, $updater->getStatus()->value['revision'] );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
2018-09-24 21:10:08 +00:00
|
|
|
$revContent = $rev->getContent( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
|
|
|
|
|
|
|
|
|
|
// were the WikiPage and Title objects updated?
|
|
|
|
|
$this->assertTrue( $page->exists(), 'WikiPage::exists()' );
|
|
|
|
|
$this->assertTrue( $title->exists(), 'Title::exists()' );
|
|
|
|
|
$this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
|
|
|
|
|
$this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
|
|
|
|
|
|
|
|
|
|
// re-load
|
|
|
|
|
$page2 = WikiPage::factory( $title );
|
|
|
|
|
$this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
|
|
|
|
|
$this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
|
|
|
|
|
$this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
|
|
|
|
|
|
|
|
|
|
// Check RC entry
|
|
|
|
|
$rc = $this->getRecentChangeFor( $rev->getId() );
|
|
|
|
|
$this->assertNotNull( $rc, 'RecentChange' );
|
|
|
|
|
|
|
|
|
|
// check site stats - this asserts that derived data updates where run.
|
|
|
|
|
$stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
|
|
|
|
|
$this->assertSame( $oldStats->ss_total_pages + 1, (int)$stats->ss_total_pages );
|
|
|
|
|
$this->assertSame( $oldStats->ss_total_edits + 1, (int)$stats->ss_total_edits );
|
|
|
|
|
|
|
|
|
|
// re-edit with same content - should be a "null-edit"
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, $content );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'to to re-edit' );
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertNull( $rev, 'getNewRevision()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertTrue( $updater->isUnchanged(), 'isUnchanged' );
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertTrue( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( 'edit-no-change' ), 'edit-no-change' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
* @covers \WikiPage::newPageUpdater()
|
|
|
|
|
*/
|
|
|
|
|
public function testUpdatePage() {
|
2020-04-18 02:39:58 +00:00
|
|
|
$this->hideDeprecated( 'WikiPage::getRevision' );
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
$this->insertPage( $title );
|
|
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$parentId = $page->getLatest();
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
|
|
|
|
$oldStats = $this->db->selectRow( 'site_stats', '*', '1=1' );
|
|
|
|
|
|
2018-06-19 14:09:01 +00:00
|
|
|
$updater->setOriginalRevisionId( 7 );
|
|
|
|
|
$this->assertSame( 7, $updater->getOriginalRevisionId(), 'getOriginalRevisionId' );
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->hasEditConflict( $parentId ), 'hasEditConflict' );
|
|
|
|
|
$this->assertTrue( $updater->hasEditConflict( $parentId - 1 ), 'hasEditConflict' );
|
|
|
|
|
$this->assertTrue( $updater->hasEditConflict( 0 ), 'hasEditConflict' );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: MCR: test additional slots
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// TODO: test all flags for saveRevision()!
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
|
|
|
|
|
$this->assertNotNull( $rev );
|
|
|
|
|
$this->assertSame( $parentId, $rev->getParentId() );
|
|
|
|
|
$this->assertSame( $summary->text, $rev->getComment( RevisionRecord::RAW )->text );
|
|
|
|
|
$this->assertSame( $user->getName(), $rev->getUser( RevisionRecord::RAW )->getName() );
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $updater->wasCommitted(), 'wasCommitted()' );
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertFalse( $updater->isNew(), 'isNew()' );
|
|
|
|
|
$this->assertNotNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertInstanceOf( Revision::class, $updater->getStatus()->value['revision'] );
|
|
|
|
|
$this->assertFalse( $updater->isUnchanged(), 'isUnchanged()' );
|
|
|
|
|
|
|
|
|
|
// TODO: Test null revision (with different user): new revision!
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
2018-09-24 21:10:08 +00:00
|
|
|
$revContent = $rev->getContent( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( 'Lorem Ipsum', $revContent->serialize(), 'revision content' );
|
|
|
|
|
|
|
|
|
|
// were the WikiPage and Title objects updated?
|
|
|
|
|
$this->assertTrue( $page->exists(), 'WikiPage::exists()' );
|
|
|
|
|
$this->assertTrue( $title->exists(), 'Title::exists()' );
|
|
|
|
|
$this->assertSame( $rev->getId(), $page->getLatest(), 'WikiPage::getRevision()' );
|
|
|
|
|
$this->assertNotNull( $page->getRevision(), 'WikiPage::getRevision()' );
|
|
|
|
|
|
|
|
|
|
// re-load
|
|
|
|
|
$page2 = WikiPage::factory( $title );
|
|
|
|
|
$this->assertTrue( $page2->exists(), 'WikiPage::exists()' );
|
|
|
|
|
$this->assertSame( $rev->getId(), $page2->getLatest(), 'WikiPage::getRevision()' );
|
|
|
|
|
$this->assertNotNull( $page2->getRevision(), 'WikiPage::getRevision()' );
|
|
|
|
|
|
|
|
|
|
// Check RC entry
|
|
|
|
|
$rc = $this->getRecentChangeFor( $rev->getId() );
|
|
|
|
|
$this->assertNotNull( $rc, 'RecentChange' );
|
|
|
|
|
|
|
|
|
|
// re-edit
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 're-edit' );
|
|
|
|
|
$updater->saveRevision( $summary );
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertTrue( $updater->getStatus()->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
|
|
|
|
|
// check site stats - this asserts that derived data updates where run.
|
|
|
|
|
$stats = $this->db->selectRow( 'site_stats', '*', '1=1' );
|
2018-08-22 16:02:49 +00:00
|
|
|
$this->assertNotNull( $stats, 'site_stats' );
|
2018-01-27 01:48:19 +00:00
|
|
|
$this->assertSame( $oldStats->ss_total_pages + 0, (int)$stats->ss_total_pages );
|
|
|
|
|
$this->assertSame( $oldStats->ss_total_edits + 2, (int)$stats->ss_total_edits );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Creates a revision in the database.
|
|
|
|
|
*
|
|
|
|
|
* @param WikiPage $page
|
2019-01-30 20:24:06 +00:00
|
|
|
* @param string|Message|CommentStoreComment $summary
|
2018-01-27 01:48:19 +00:00
|
|
|
* @param null|string|Content $content
|
|
|
|
|
*
|
|
|
|
|
* @return RevisionRecord|null
|
|
|
|
|
*/
|
|
|
|
|
private function createRevision( WikiPage $page, $summary, $content = null ) {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$comment = CommentStoreComment::newUnsavedComment( $summary );
|
|
|
|
|
|
|
|
|
|
if ( !$content instanceof Content ) {
|
2018-06-20 05:26:57 +00:00
|
|
|
$content = new TextContent( $content ?? $summary );
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, $content );
|
2018-01-27 01:48:19 +00:00
|
|
|
$rev = $updater->saveRevision( $comment );
|
|
|
|
|
return $rev;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-15 10:37:39 +00:00
|
|
|
/**
|
|
|
|
|
* Verify that MultiContentSave hook is called by saveRevision() with correct parameters.
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testMultiContentSaveHook() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// TODO: MCR: test additional slots
|
|
|
|
|
$slots = [
|
|
|
|
|
SlotRecord::MAIN => new TextContent( 'Lorem Ipsum' )
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
// start editing non-existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
foreach ( $slots as $slot => $content ) {
|
|
|
|
|
$updater->setContent( $slot, $content );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
|
|
|
|
|
|
|
|
|
|
$expected = [
|
|
|
|
|
'user' => $user,
|
|
|
|
|
'title' => $title,
|
|
|
|
|
'slots' => $slots,
|
|
|
|
|
'summary' => $summary
|
|
|
|
|
];
|
|
|
|
|
$hookFired = false;
|
|
|
|
|
$this->setTemporaryHook( 'MultiContentSave',
|
|
|
|
|
function ( RenderedRevision $renderedRevision, User $user,
|
|
|
|
|
$summary, $flags, Status $hookStatus
|
|
|
|
|
) use ( &$hookFired, $expected ) {
|
|
|
|
|
$hookFired = true;
|
|
|
|
|
|
|
|
|
|
$this->assertSame( $expected['summary'], $summary );
|
|
|
|
|
$this->assertSame( EDIT_NEW, $flags );
|
|
|
|
|
|
|
|
|
|
$title = $renderedRevision->getRevision()->getPageAsLinkTarget();
|
|
|
|
|
$this->assertSame( $expected['title']->getFullText(), $title->getFullText() );
|
|
|
|
|
|
|
|
|
|
$slots = $renderedRevision->getRevision()->getSlots();
|
|
|
|
|
foreach ( $expected['slots'] as $slot => $content ) {
|
|
|
|
|
$this->assertSame( $content, $slots->getSlot( $slot )->getContent() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Don't abort this edit.
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
$this->assertTrue( $hookFired, "MultiContentSave hook wasn't called." );
|
|
|
|
|
$this->assertNotNull( $rev,
|
|
|
|
|
"MultiContentSave returned true, but revision wasn't created." );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Verify that MultiContentSave hook can abort saveRevision() by returning false.
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testMultiContentSaveHookAbort() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// start editing non-existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
|
|
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
|
|
|
|
|
|
|
|
|
|
$expectedError = 'aborted-by-test-hook';
|
|
|
|
|
$this->setTemporaryHook( 'MultiContentSave',
|
|
|
|
|
function ( RenderedRevision $renderedRevision, User $user,
|
|
|
|
|
$summary, $flags, Status $hookStatus
|
|
|
|
|
) use ( $expectedError ) {
|
|
|
|
|
$hookStatus->fatal( $expectedError );
|
|
|
|
|
|
|
|
|
|
// Returning false should disallow saveRevision() to continue saving this revision.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
$this->assertNull( $rev,
|
|
|
|
|
"MultiContentSave returned false, but revision was still created." );
|
|
|
|
|
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
$this->assertFalse( $status->isOK(),
|
|
|
|
|
"MultiContentSave returned false, but Status is not fatal." );
|
|
|
|
|
$this->assertSame( $expectedError, $status->getMessage()->getKey() );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::grabParentRevision()
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testCompareAndSwapFailure() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// start editing non-existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->grabParentRevision();
|
|
|
|
|
|
|
|
|
|
// create page concurrently
|
|
|
|
|
$concurrentPage = WikiPage::factory( $title );
|
|
|
|
|
$this->createRevision( $concurrentPage, __METHOD__ . '-one' );
|
|
|
|
|
|
|
|
|
|
// try creating the page - should trigger CAS failure.
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'create?!' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->saveRevision( $summary );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-conflict' );
|
|
|
|
|
|
|
|
|
|
// start editing existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->grabParentRevision();
|
|
|
|
|
|
|
|
|
|
// update page concurrently
|
|
|
|
|
$concurrentPage = WikiPage::factory( $title );
|
|
|
|
|
$this->createRevision( $concurrentPage, __METHOD__ . '-two' );
|
|
|
|
|
|
|
|
|
|
// try creating the page - should trigger CAS failure.
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'edit?!' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->saveRevision( $summary );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( 'edit-conflict' ), 'edit-conflict' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testFailureOnEditFlags() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// start editing non-existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
|
|
|
|
// update with EDIT_UPDATE flag should fail
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'udpate?!' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->saveRevision( $summary, EDIT_UPDATE );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( 'edit-gone-missing' ), 'edit-gone-missing' );
|
|
|
|
|
|
|
|
|
|
// create the page
|
|
|
|
|
$this->createRevision( $page, __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// update with EDIT_NEW flag should fail
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'create?!' );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'dolor sit amet' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->saveRevision( $summary, EDIT_NEW );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue( $status->hasMessage( 'edit-already-exists' ), 'edit-already-exists' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-19 11:39:56 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testFailureOnBadContentModel() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
// start editing non-existing page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
|
|
|
|
// plain text content should fail in aux slot (the main slot doesn't care)
|
|
|
|
|
$updater->setContent( 'main', new TextContent( 'Main Content' ) );
|
|
|
|
|
$updater->setContent( 'aux', new TextContent( 'Aux Content' ) );
|
|
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'udpate?!' );
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_UPDATE );
|
|
|
|
|
$status = $updater->getStatus();
|
|
|
|
|
|
|
|
|
|
$this->assertFalse( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
$this->assertNull( $updater->getNewRevision(), 'getNewRevision()' );
|
|
|
|
|
$this->assertFalse( $status->isOK(), 'getStatus()->isOK()' );
|
|
|
|
|
$this->assertTrue(
|
|
|
|
|
$status->hasMessage( 'content-not-allowed-here' ),
|
|
|
|
|
'content-not-allowed-here'
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
public function provideSetRcPatrolStatus( $patrolled ) {
|
|
|
|
|
yield [ RecentChange::PRC_UNPATROLLED ];
|
|
|
|
|
yield [ RecentChange::PRC_AUTOPATROLLED ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideSetRcPatrolStatus
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::setRcPatrolStatus()
|
|
|
|
|
*/
|
|
|
|
|
public function testSetRcPatrolStatus( $patrolled ) {
|
|
|
|
|
$revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
|
|
|
|
|
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Lorem ipsum ' . $patrolled );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum ' . $patrolled ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->setRcPatrolStatus( $patrolled );
|
|
|
|
|
$rev = $updater->saveRevision( $summary );
|
|
|
|
|
|
|
|
|
|
$rc = $revisionStore->getRecentChange( $rev );
|
|
|
|
|
$this->assertEquals( $patrolled, $rc->getAttribute( 'rc_patrolled' ) );
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-09 12:06:22 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::makeNewRevision()
|
|
|
|
|
*/
|
|
|
|
|
public function testStalePageID() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'testing...' );
|
|
|
|
|
|
|
|
|
|
// Create page
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->setContent( 'main', new TextContent( 'Content 1' ) );
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_NEW );
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
|
|
|
|
|
// Create a clone of $title and $page.
|
|
|
|
|
$title = Title::makeTitle( $title->getNamespace(), $title->getDBkey() );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
// start editing existing page using bad page ID
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->grabParentRevision();
|
|
|
|
|
|
|
|
|
|
$updater->setContent( 'main', new TextContent( 'Content 2' ) );
|
|
|
|
|
|
|
|
|
|
// Force the article ID to something invalid,
|
|
|
|
|
// to emulate confusion due to a page move.
|
|
|
|
|
$title->resetArticleID( 886655 );
|
|
|
|
|
|
|
|
|
|
AtEase::suppressWarnings();
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_UPDATE );
|
|
|
|
|
AtEase::restoreWarnings();
|
|
|
|
|
|
|
|
|
|
$this->assertTrue( $updater->wasSuccessful(), 'wasSuccessful()' );
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::inheritSlot()
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::setContent()
|
|
|
|
|
*/
|
|
|
|
|
public function testInheritSlot() {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'one' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$rev1 = $updater->saveRevision( $summary, EDIT_NEW );
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'two' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Foo Bar' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$rev2 = $updater->saveRevision( $summary, EDIT_UPDATE );
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'three' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->inheritSlot( $rev1->getSlot( SlotRecord::MAIN ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$rev3 = $updater->saveRevision( $summary, EDIT_UPDATE );
|
|
|
|
|
|
|
|
|
|
$this->assertNotSame( $rev1->getId(), $rev3->getId() );
|
|
|
|
|
$this->assertNotSame( $rev2->getId(), $rev3->getId() );
|
|
|
|
|
|
2018-09-24 21:10:08 +00:00
|
|
|
$main1 = $rev1->getSlot( SlotRecord::MAIN );
|
|
|
|
|
$main3 = $rev3->getSlot( SlotRecord::MAIN );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$this->assertNotSame( $main1->getRevision(), $main3->getRevision() );
|
|
|
|
|
$this->assertSame( $main1->getAddress(), $main3->getAddress() );
|
|
|
|
|
$this->assertTrue( $main1->getContent()->equals( $main3->getContent() ) );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: MCR: test adding multiple slots, inheriting parent slots, and removing slots.
|
|
|
|
|
|
|
|
|
|
public function testSetUseAutomaticEditSummaries() {
|
|
|
|
|
$this->setContentLang( 'qqx' );
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->setUseAutomaticEditSummaries( true );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
// empty comment triggers auto-summary
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( '' );
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
|
|
|
|
$comment = $rev->getComment( RevisionRecord::RAW );
|
|
|
|
|
$this->assertSame( '(autosumm-new: Lorem Ipsum)', $comment->text, 'comment text' );
|
|
|
|
|
|
|
|
|
|
// check that this also works when blanking the page
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->setUseAutomaticEditSummaries( true );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( '' );
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
|
|
|
|
$comment = $rev->getComment( RevisionRecord::RAW );
|
|
|
|
|
$this->assertSame( '(autosumm-blank)', $comment->text, 'comment text' );
|
|
|
|
|
|
|
|
|
|
// check that we can also disable edit-summaries
|
|
|
|
|
$title2 = $this->getDummyTitle( __METHOD__ . '/2' );
|
|
|
|
|
$page2 = WikiPage::factory( $title2 );
|
|
|
|
|
|
|
|
|
|
$updater = $page2->newPageUpdater( $user );
|
|
|
|
|
$updater->setUseAutomaticEditSummaries( false );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( '' );
|
|
|
|
|
$updater->saveRevision( $summary, EDIT_AUTOSUMMARY );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
|
|
|
|
$comment = $rev->getComment( RevisionRecord::RAW );
|
|
|
|
|
$this->assertSame( '', $comment->text, 'comment text should still be lank' );
|
|
|
|
|
|
|
|
|
|
// check that we don't do auto.summaries without the EDIT_AUTOSUMMARY flag
|
|
|
|
|
$updater = $page2->newPageUpdater( $user );
|
|
|
|
|
$updater->setUseAutomaticEditSummaries( true );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( '' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( '' );
|
|
|
|
|
$updater->saveRevision( $summary, 0 );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
|
|
|
|
$comment = $rev->getComment( RevisionRecord::RAW );
|
|
|
|
|
$this->assertSame( '', $comment->text, 'comment text' );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function provideSetUsePageCreationLog() {
|
|
|
|
|
yield [ true, [ [ 'create', 'create' ] ] ];
|
|
|
|
|
yield [ false, [] ];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @dataProvider provideSetUsePageCreationLog
|
|
|
|
|
* @param bool $use
|
|
|
|
|
*/
|
|
|
|
|
public function testSetUsePageCreationLog( $use, $expected ) {
|
|
|
|
|
$user = $this->getTestUser()->getUser();
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ . ( $use ? '_logged' : '_unlogged' ) );
|
|
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
$updater->setUsePageCreationLog( $use );
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'cmt' );
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new TextContent( 'Lorem Ipsum' ) );
|
2018-01-27 01:48:19 +00:00
|
|
|
$updater->saveRevision( $summary, EDIT_NEW );
|
|
|
|
|
|
|
|
|
|
$rev = $updater->getNewRevision();
|
|
|
|
|
$this->assertSelect(
|
|
|
|
|
'logging',
|
|
|
|
|
[ 'log_type', 'log_action' ],
|
|
|
|
|
[ 'log_page' => $rev->getPageId() ],
|
|
|
|
|
$expected
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
public function provideMagicWords() {
|
|
|
|
|
yield 'PAGEID' => [
|
|
|
|
|
'Test {{PAGEID}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return $rev->getPageId();
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'REVISIONID' => [
|
|
|
|
|
'Test {{REVISIONID}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return $rev->getId();
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'REVISIONUSER' => [
|
|
|
|
|
'Test {{REVISIONUSER}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return $rev->getUser()->getName();
|
|
|
|
|
}
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'REVISIONTIMESTAMP' => [
|
|
|
|
|
'Test {{REVISIONTIMESTAMP}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return $rev->getTimestamp();
|
|
|
|
|
}
|
|
|
|
|
];
|
2018-08-31 10:49:19 +00:00
|
|
|
|
|
|
|
|
yield 'subst:REVISIONUSER' => [
|
|
|
|
|
'Test {{subst:REVISIONUSER}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return $rev->getUser()->getName();
|
2018-09-05 18:03:15 +00:00
|
|
|
},
|
|
|
|
|
'subst'
|
2018-08-31 10:49:19 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
yield 'subst:PAGENAME' => [
|
|
|
|
|
'Test {{subst:PAGENAME}} Test',
|
|
|
|
|
function ( RevisionRecord $rev ) {
|
|
|
|
|
return 'PageUpdaterTest::testMagicWords';
|
2018-09-05 18:03:15 +00:00
|
|
|
},
|
|
|
|
|
'subst'
|
2018-08-31 10:49:19 +00:00
|
|
|
];
|
2018-08-07 16:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @covers \MediaWiki\Storage\PageUpdater::saveRevision()
|
|
|
|
|
*
|
|
|
|
|
* Integration test for PageUpdater, DerivedPageDataUpdater, RevisionRenderer
|
|
|
|
|
* and RenderedRevision, that ensures that magic words depending on revision meta-data
|
|
|
|
|
* are handled correctly. Note that each magic word needs to be tested separately,
|
|
|
|
|
* to assert correct behavior for each "vary" flag in the ParserOutput.
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider provideMagicWords
|
|
|
|
|
*/
|
2018-09-05 18:03:15 +00:00
|
|
|
public function testMagicWords( $wikitext, $callback, $subst = false ) {
|
|
|
|
|
$user = User::newFromName( 'A user for ' . __METHOD__ );
|
|
|
|
|
$user->addToDatabase();
|
2018-08-07 16:52:40 +00:00
|
|
|
|
|
|
|
|
$title = $this->getDummyTitle( __METHOD__ . '-' . $this->getName() );
|
2018-09-05 18:03:15 +00:00
|
|
|
$this->insertPage( $title );
|
|
|
|
|
|
2018-08-07 16:52:40 +00:00
|
|
|
$page = WikiPage::factory( $title );
|
|
|
|
|
$updater = $page->newPageUpdater( $user );
|
|
|
|
|
|
2018-09-24 21:10:08 +00:00
|
|
|
$updater->setContent( SlotRecord::MAIN, new \WikitextContent( $wikitext ) );
|
2018-08-07 16:52:40 +00:00
|
|
|
|
|
|
|
|
$summary = CommentStoreComment::newUnsavedComment( 'Just a test' );
|
2018-09-05 18:03:15 +00:00
|
|
|
$rev = $updater->saveRevision( $summary, EDIT_UPDATE );
|
2018-08-07 16:52:40 +00:00
|
|
|
|
|
|
|
|
if ( !$rev ) {
|
|
|
|
|
$this->fail( $updater->getStatus()->getWikiText() );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expected = strval( $callback( $rev ) );
|
|
|
|
|
|
2018-09-05 18:03:15 +00:00
|
|
|
$output = $page->getParserOutput( ParserOptions::newCanonical( 'canonical' ) );
|
|
|
|
|
$html = $output->getText();
|
2018-09-24 21:10:08 +00:00
|
|
|
$text = $rev->getContent( SlotRecord::MAIN )->serialize();
|
2018-08-07 16:52:40 +00:00
|
|
|
|
2018-09-05 18:03:15 +00:00
|
|
|
if ( $subst ) {
|
2019-12-14 12:45:35 +00:00
|
|
|
$this->assertStringContainsString( $expected, $text, 'In Wikitext' );
|
2018-09-05 18:03:15 +00:00
|
|
|
}
|
2018-08-07 16:52:40 +00:00
|
|
|
|
2019-12-14 12:45:35 +00:00
|
|
|
$this->assertStringContainsString( $expected, $html, 'In HTML' );
|
2018-08-07 16:52:40 +00:00
|
|
|
}
|
|
|
|
|
|
2018-01-27 01:48:19 +00:00
|
|
|
}
|