wiki.techinc.nl/tests/phpunit/unit/includes/Storage/PageUpdaterFactoryTest.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

91 lines
2.7 KiB
PHP

<?php
namespace MediaWiki\Tests\Unit\Storage;
use MediaWiki\Config\ServiceOptions;
use MediaWiki\Page\WikiPageFactory;
use MediaWiki\Storage\DerivedPageDataUpdater;
use MediaWiki\Storage\PageUpdater;
use MediaWiki\Storage\PageUpdaterFactory;
use MediaWiki\Tests\Unit\MockServiceDependenciesTrait;
use MediaWiki\User\UserIdentityValue;
use MediaWikiUnitTestCase;
use Wikimedia\Rdbms\LBFactory;
use Wikimedia\Rdbms\LoadBalancer;
use WikiPage;
/**
* @covers \MediaWiki\Storage\PageUpdaterFactory
*/
class PageUpdaterFactoryTest extends MediaWikiUnitTestCase {
use MockServiceDependenciesTrait;
private function getPageUpdaterFactory() {
$config = [
'ArticleCountMethod' => null,
'RCWatchCategoryMembership' => null,
'PageCreationLog' => null,
'UseAutomaticEditSummaries' => null,
'ManualRevertSearchRadius' => null,
'UseRCPatrol' => null,
];
$lb = $this->createNoOpMock( LoadBalancer::class );
$lbFactory = $this->createNoOpMock( LBFactory::class, [ 'getMainLB' ] );
$lbFactory->method( 'getMainLB' )->willReturn( $lb );
$wikiPageFactory = $this->createNoOpMock( WikiPageFactory::class, [ 'newFromTitle' ] );
$wikiPageFactory->method( 'newFromTitle' )->willReturnArgument( 0 );
return $this->newServiceInstance(
PageUpdaterFactory::class,
[
'loadbalancerFactory' => $lbFactory,
'wikiPageFactory' => $wikiPageFactory,
'options' => new ServiceOptions(
PageUpdaterFactory::CONSTRUCTOR_OPTIONS,
$config
),
'softwareTags' => [],
]
);
}
public function testNewDerivedPageDataUpdater() {
$page = $this->createNoOpMock( WikiPage::class );
$factory = $this->getPageUpdaterFactory();
$derivedPageDataUpdater = $factory->newDerivedPageDataUpdater( $page );
$this->assertInstanceOf( DerivedPageDataUpdater::class, $derivedPageDataUpdater );
}
public function testNewPageUpdater() {
$page = $this->createNoOpMock( WikiPage::class, [ 'canExist' ] );
$page->method( 'canExist' )->willReturn( true );
$user = new UserIdentityValue( 0, 'Dummy' );
$factory = $this->getPageUpdaterFactory();
$pageUpdater = $factory->newPageUpdater( $page, $user );
$this->assertInstanceOf( PageUpdater::class, $pageUpdater );
}
public function testNewPageUpdaterForDerivedPageDataUpdater() {
$page = $this->createNoOpMock( WikiPage::class, [ 'canExist' ] );
$page->method( 'canExist' )->willReturn( true );
$user = new UserIdentityValue( 0, 'Dummy' );
$factory = $this->getPageUpdaterFactory();
$derivedPageDataUpdater = $factory->newDerivedPageDataUpdater( $page );
$pageUpdater = $factory->newPageUpdaterForDerivedPageDataUpdater(
$page,
$user,
$derivedPageDataUpdater
);
$this->assertInstanceOf( PageUpdater::class, $pageUpdater );
}
}