wiki.techinc.nl/tests/phpunit/includes/Storage/PageUpdaterFactoryIntegrationTest.php
daniel cbfcf9e8a8 Introduced PreparedUpdate to replace PreparedEdit
PreparedUpdate represents an in-progress edit. It can be used to access
information about the edit from hooks that do to have access to the
PageUpdater. Ideally, the PreparedUpdate or PageUpdater would be passed
to the hook as a parameter. Handlers of legacy hooks may use
WikiPage::prepareUpdate() to access it.

Bug: T242249
Needed-By: I23324a31e06e7e6f28077085c0ade05db63e9a35
Change-Id: Id5ba40a21cc4547205adf2f3a1f725c3a69c24d8
2021-12-20 21:19:52 +01:00

46 lines
1.3 KiB
PHP

<?php
namespace MediaWiki\Tests\Storage;
use ContentHandler;
use MediaWiki\Revision\SlotRecord;
use MediaWikiIntegrationTestCase;
use TextContent;
/**
* @covers MediaWiki\Storage\PageUpdaterFactory
* @group Database
*/
class PageUpdaterFactoryIntegrationTest extends MediaWikiIntegrationTestCase {
/**
* @covers WikiPage::newPageUpdater
*/
public function testNewPageUpdater() {
$page = $this->getExistingTestPage();
$title = $page->getTitle();
$user = $this->getTestUser()->getUserIdentity();
/** @var TextContent $content */
$content = ContentHandler::makeContent(
"[[Lorem ipsum]] dolor sit amet, consetetur sadipscing elitr, sed diam "
. " nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.",
$title,
CONTENT_MODEL_WIKITEXT
);
$factory = $this->getServiceContainer()->getPageUpdaterFactory();
$updater = $factory->newPageUpdater( $page, $user );
$updater->setContent( SlotRecord::MAIN, $content );
$update = $updater->prepareUpdate();
/** @var TextContent $pstContent */
$pstContent = $update->getRawContent( SlotRecord::MAIN );
$this->assertSame( $content->getText(), $pstContent->getText() );
$pout = $update->getCanonicalParserOutput();
$this->assertStringContainsString( 'dolor sit amet', $pout->getText() );
}
}