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