| 1 |
<?php |
| 2 |
|
| 3 |
namespace MediaWiki\Tests\Unit\Page; |
| 4 |
|
| 5 |
use MediaWiki\Config\HashConfig; |
| 6 |
use MediaWiki\Content\ContentModelChange; |
| 7 |
use MediaWiki\MainConfigNames; |
| 8 |
use MediaWiki\Page\DeletePage; |
| 9 |
use MediaWiki\Page\MergeHistory; |
| 10 |
use MediaWiki\Page\MovePage; |
| 11 |
use MediaWiki\Page\PageCommandFactory; |
| 12 |
use MediaWiki\Page\PageIdentity; |
| 13 |
use MediaWiki\Page\PageIdentityValue; |
| 14 |
use MediaWiki\Page\ProperPageIdentity; |
| 15 |
use MediaWiki\Page\RollbackPage; |
| 16 |
use MediaWiki\Page\UndeletePage; |
| 17 |
use MediaWiki\Permissions\Authority; |
| 18 |
use MediaWiki\Tests\Unit\MockServiceDependenciesTrait; |
| 19 |
use MediaWiki\Title\Title; |
| 20 |
use MediaWiki\User\UserIdentity; |
| 21 |
use MediaWikiUnitTestCase; |
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
class PageCommandFactoryTest extends MediaWikiUnitTestCase { |
| 28 |
use MockServiceDependenciesTrait; |
| 29 |
|
| 30 |
private function getFactory(): PageCommandFactory { |
| 31 |
|
| 32 |
$config = new HashConfig( [ |
| 33 |
|
| 34 |
MainConfigNames::UseRCPatrol => true, |
| 35 |
MainConfigNames::DisableAnonTalk => false, |
| 36 |
|
| 37 |
|
| 38 |
MainConfigNames::CategoryCollation => 'uppercase', |
| 39 |
MainConfigNames::MaximumMovedPages => 100, |
| 40 |
|
| 41 |
|
| 42 |
MainConfigNames::DeleteRevisionsBatchSize => 10, |
| 43 |
MainConfigNames::DeleteRevisionsLimit => 10, |
| 44 |
] ); |
| 45 |
|
| 46 |
|
| 47 |
return $this->newServiceInstance( |
| 48 |
PageCommandFactory::class, |
| 49 |
[ |
| 50 |
'config' => $config, |
| 51 |
] |
| 52 |
); |
| 53 |
} |
| 54 |
|
| 55 |
public function testContentModelChange() { |
| 56 |
$contentModelChange = $this->getFactory()->newContentModelChange( |
| 57 |
$this->createMock( Authority::class ), |
| 58 |
$this->createMock( PageIdentity::class ), |
| 59 |
CONTENT_MODEL_TEXT |
| 60 |
); |
| 61 |
$this->assertInstanceOf( |
| 62 |
ContentModelChange::class, |
| 63 |
$contentModelChange, |
| 64 |
'Creating ContentModelChange works' |
| 65 |
); |
| 66 |
} |
| 67 |
|
| 68 |
public function testDeletePage() { |
| 69 |
$page = $this->createMock( ProperPageIdentity::class ); |
| 70 |
$page->method( 'canExist' )->willReturn( true ); |
| 71 |
$this->assertInstanceOf( |
| 72 |
DeletePage::class, |
| 73 |
$this->getFactory()->newDeletePage( $page, $this->createMock( Authority::class ) ) |
| 74 |
); |
| 75 |
} |
| 76 |
|
| 77 |
public function testMergeHistory() { |
| 78 |
$mergeHistory = $this->getFactory()->newMergeHistory( |
| 79 |
PageIdentityValue::localIdentity( 1, NS_MAIN, 'Source' ), |
| 80 |
PageIdentityValue::localIdentity( 2, NS_MAIN, 'Dest' ), |
| 81 |
null |
| 82 |
); |
| 83 |
$this->assertInstanceOf( |
| 84 |
MergeHistory::class, |
| 85 |
$mergeHistory, |
| 86 |
'Creating MergeHistory works' |
| 87 |
); |
| 88 |
} |
| 89 |
|
| 90 |
public function testMovePage() { |
| 91 |
$movePage = $this->getFactory()->newMovePage( |
| 92 |
$this->createNoOpMock( Title::class ), |
| 93 |
$this->createNoOpMock( Title::class ) |
| 94 |
); |
| 95 |
$this->assertInstanceOf( |
| 96 |
MovePage::class, |
| 97 |
$movePage, |
| 98 |
'Creating MovePage works' |
| 99 |
); |
| 100 |
} |
| 101 |
|
| 102 |
public function testRollbackPage() { |
| 103 |
$rollbackPage = $this->getFactory()->newRollbackPage( |
| 104 |
$this->createMock( PageIdentity::class ), |
| 105 |
$this->createMock( Authority::class ), |
| 106 |
$this->createMock( UserIdentity::class ) |
| 107 |
); |
| 108 |
$this->assertInstanceOf( |
| 109 |
RollbackPage::class, |
| 110 |
$rollbackPage, |
| 111 |
'Creating RollbackPage works' |
| 112 |
); |
| 113 |
} |
| 114 |
|
| 115 |
public function testUndeletePage() { |
| 116 |
$undeletePage = $this->getFactory()->newUndeletePage( |
| 117 |
$this->createMock( ProperPageIdentity::class ), |
| 118 |
$this->createMock( Authority::class ) |
| 119 |
); |
| 120 |
$this->assertInstanceOf( UndeletePage::class, $undeletePage ); |
| 121 |
} |
| 122 |
} |