1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\MediaWiki\Specials\Admin; |
4
|
|
|
|
5
|
|
|
use SMW\Tests\TestEnvironment; |
6
|
|
|
use SMW\MediaWiki\Specials\Admin\IdTaskHandler; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SMW\MediaWiki\Specials\Admin\IdTaskHandler |
10
|
|
|
* @group semantic-mediawiki |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 2.5 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class IdTaskHandlerTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $testEnvironment; |
20
|
|
|
private $store; |
21
|
|
|
private $connection; |
22
|
|
|
private $htmlFormRenderer; |
23
|
|
|
private $outputFormatter; |
24
|
|
|
|
25
|
|
|
protected function setUp() { |
26
|
|
|
parent::setUp(); |
27
|
|
|
|
28
|
|
|
$this->testEnvironment = new TestEnvironment(); |
29
|
|
|
|
30
|
|
|
$this->connection = $this->getMockBuilder( '\SMW\MediaWiki\Database' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMock(); |
33
|
|
|
|
34
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMockForAbstractClass(); |
37
|
|
|
|
38
|
|
|
$this->store->expects( $this->any() ) |
39
|
|
|
->method( 'getConnection' ) |
40
|
|
|
->will( $this->returnValue( $this->connection ) ); |
41
|
|
|
|
42
|
|
|
$this->htmlFormRenderer = $this->getMockBuilder( '\SMW\MediaWiki\Renderer\HtmlFormRenderer' ) |
43
|
|
|
->disableOriginalConstructor() |
44
|
|
|
->getMock(); |
45
|
|
|
|
46
|
|
|
$this->outputFormatter = $this->getMockBuilder( '\SMW\MediaWiki\Specials\Admin\OutputFormatter' ) |
47
|
|
|
->disableOriginalConstructor() |
48
|
|
|
->getMock(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function tearDown() { |
52
|
|
|
$this->testEnvironment->tearDown(); |
53
|
|
|
parent::tearDown(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
public function testCanConstruct() { |
57
|
|
|
|
58
|
|
|
$this->assertInstanceOf( |
59
|
|
|
'\SMW\MediaWiki\Specials\Admin\IdTaskHandler', |
60
|
|
|
new IdTaskHandler( $this->store, $this->htmlFormRenderer, $this->outputFormatter ) |
61
|
|
|
); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testGetHml() { |
65
|
|
|
|
66
|
|
|
$instance = new IdTaskHandler( |
67
|
|
|
$this->store, |
68
|
|
|
$this->htmlFormRenderer, |
69
|
|
|
$this->outputFormatter |
70
|
|
|
); |
71
|
|
|
|
72
|
|
|
$this->assertInternalType( |
73
|
|
|
'string', |
74
|
|
|
$instance->getHtml() |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testPerformAction() { |
79
|
|
|
|
80
|
|
|
$methods = array( |
81
|
|
|
'setName', |
82
|
|
|
'setMethod', |
83
|
|
|
'addHiddenField', |
84
|
|
|
'addHeader', |
85
|
|
|
'addParagraph', |
86
|
|
|
'addInputField', |
87
|
|
|
'addSubmitButton', |
88
|
|
|
'addNonBreakingSpace', |
89
|
|
|
'addCheckbox' |
90
|
|
|
); |
91
|
|
|
|
92
|
|
|
foreach ( $methods as $method ) { |
93
|
|
|
$this->htmlFormRenderer->expects( $this->any() ) |
94
|
|
|
->method( $method ) |
95
|
|
|
->will( $this->returnSelf() ); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$this->htmlFormRenderer->expects( $this->atLeastOnce() ) |
99
|
|
|
->method( 'getForm' ); |
100
|
|
|
|
101
|
|
|
$instance = new IdTaskHandler( |
102
|
|
|
$this->store, |
103
|
|
|
$this->htmlFormRenderer, |
104
|
|
|
$this->outputFormatter |
105
|
|
|
); |
106
|
|
|
|
107
|
|
|
$webRequest = $this->getMockBuilder( '\WebRequest' ) |
108
|
|
|
->disableOriginalConstructor() |
109
|
|
|
->getMock(); |
110
|
|
|
|
111
|
|
|
$instance->handleRequest( $webRequest ); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testPerformActionWithId() { |
115
|
|
|
|
116
|
|
|
$manualEntryLogger = $this->getMockBuilder( '\SMW\MediaWiki\ManualEntryLogger' ) |
117
|
|
|
->disableOriginalConstructor() |
118
|
|
|
->getMock(); |
119
|
|
|
|
120
|
|
|
$manualEntryLogger->expects( $this->once() ) |
121
|
|
|
->method( 'log' ); |
122
|
|
|
|
123
|
|
|
$this->testEnvironment->registerObject( 'ManualEntryLogger', $manualEntryLogger ); |
124
|
|
|
|
125
|
|
|
$entityIdDisposerJob = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\EntityIdDisposerJob' ) |
126
|
|
|
->disableOriginalConstructor() |
127
|
|
|
->getMock(); |
128
|
|
|
|
129
|
|
|
$jobFactory = $this->getMockBuilder( '\SMW\MediaWiki\Jobs\JobFactory' ) |
130
|
|
|
->disableOriginalConstructor() |
131
|
|
|
->getMock(); |
132
|
|
|
|
133
|
|
|
$jobFactory->expects( $this->atLeastOnce() ) |
134
|
|
|
->method( 'newEntityIdDisposerJob' ) |
135
|
|
|
->will( $this->returnValue( $entityIdDisposerJob ) ); |
136
|
|
|
|
137
|
|
|
$this->testEnvironment->registerObject( 'JobFactory', $jobFactory ); |
138
|
|
|
|
139
|
|
|
$methods = array( |
140
|
|
|
'setName', |
141
|
|
|
'setMethod', |
142
|
|
|
'addHiddenField', |
143
|
|
|
'addHeader', |
144
|
|
|
'addParagraph', |
145
|
|
|
'addInputField', |
146
|
|
|
'addSubmitButton', |
147
|
|
|
'addNonBreakingSpace', |
148
|
|
|
'addCheckbox' |
149
|
|
|
); |
150
|
|
|
|
151
|
|
|
foreach ( $methods as $method ) { |
152
|
|
|
$this->htmlFormRenderer->expects( $this->any() ) |
153
|
|
|
->method( $method ) |
154
|
|
|
->will( $this->returnSelf() ); |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
$this->htmlFormRenderer->expects( $this->atLeastOnce() ) |
158
|
|
|
->method( 'getForm' ); |
159
|
|
|
|
160
|
|
|
$user = $this->getMockBuilder( '\User' ) |
161
|
|
|
->disableOriginalConstructor() |
162
|
|
|
->getMock(); |
163
|
|
|
|
164
|
|
|
$webRequest = $this->getMockBuilder( '\WebRequest' ) |
165
|
|
|
->disableOriginalConstructor() |
166
|
|
|
->getMock(); |
167
|
|
|
|
168
|
|
|
$webRequest->expects( $this->at( 0 ) ) |
169
|
|
|
->method( 'getText' ) |
170
|
|
|
->with( $this->equalTo( 'id' ) ) |
171
|
|
|
->will( $this->returnValue( 42 ) ); |
172
|
|
|
|
173
|
|
|
$webRequest->expects( $this->at( 1 ) ) |
174
|
|
|
->method( 'getText' ) |
175
|
|
|
->with( $this->equalTo( 'dispose' ) ) |
176
|
|
|
->will( $this->returnValue( 'yes' ) ); |
177
|
|
|
|
178
|
|
|
$webRequest->expects( $this->at( 2 ) ) |
179
|
|
|
->method( 'getText' ) |
180
|
|
|
->with( $this->equalTo( 'action' ) ) |
181
|
|
|
->will( $this->returnValue( 'idlookup' ) ); |
182
|
|
|
|
183
|
|
|
$instance = new IdTaskHandler( |
184
|
|
|
$this->store, |
185
|
|
|
$this->htmlFormRenderer, |
186
|
|
|
$this->outputFormatter |
187
|
|
|
); |
188
|
|
|
|
189
|
|
|
$instance->setEnabledFeatures( SMW_ADM_DISPOSAL ); |
190
|
|
|
$instance->setUser( $user ); |
191
|
|
|
|
192
|
|
|
$instance->handleRequest( $webRequest ); |
193
|
|
|
} |
194
|
|
|
|
195
|
|
|
} |
196
|
|
|
|