1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SIL\Tests; |
4
|
|
|
|
5
|
|
|
use SIL\HookRegistry; |
6
|
|
|
use Title; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @covers \SIL\HookRegistry |
10
|
|
|
* @group semantic-interlanguage-links |
11
|
|
|
* |
12
|
|
|
* @license GNU GPL v2+ |
13
|
|
|
* @since 1.0 |
14
|
|
|
* |
15
|
|
|
* @author mwjames |
16
|
|
|
*/ |
17
|
|
|
class HookRegistryTest extends \PHPUnit_Framework_TestCase { |
18
|
|
|
|
19
|
|
|
private $cache; |
20
|
|
|
private $store; |
21
|
|
|
private $cacheKeyProvider; |
22
|
|
|
|
23
|
|
|
protected function setUp() { |
24
|
|
|
parent::setUp(); |
25
|
|
|
|
26
|
|
|
$this->store = $this->getMockBuilder( '\SMW\Store' ) |
27
|
|
|
->disableOriginalConstructor() |
28
|
|
|
->getMockForAbstractClass(); |
29
|
|
|
|
30
|
|
|
$this->cache = $this->getMockBuilder( '\Onoi\Cache\Cache' ) |
31
|
|
|
->disableOriginalConstructor() |
32
|
|
|
->getMockForAbstractClass(); |
33
|
|
|
|
34
|
|
|
$this->cacheKeyProvider = $this->getMockBuilder( '\SIL\CacheKeyProvider' ) |
35
|
|
|
->disableOriginalConstructor() |
36
|
|
|
->getMockForAbstractClass(); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testCanConstruct() { |
40
|
|
|
|
41
|
|
|
$this->assertInstanceOf( |
42
|
|
|
'\SIL\HookRegistry', |
43
|
|
|
new HookRegistry( $this->store, $this->cache, $this->cacheKeyProvider ) |
44
|
|
|
); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testRegister() { |
48
|
|
|
|
49
|
|
|
$title = Title::newFromText( __METHOD__ ); |
50
|
|
|
|
51
|
|
|
$parserOutput = $this->getMockBuilder( '\ParserOutput' ) |
52
|
|
|
->disableOriginalConstructor() |
53
|
|
|
->getMock(); |
54
|
|
|
|
55
|
|
|
$parser = $this->getMockBuilder( '\Parser' ) |
56
|
|
|
->disableOriginalConstructor() |
57
|
|
|
->getMock(); |
58
|
|
|
|
59
|
|
|
$parser->expects( $this->any() ) |
60
|
|
|
->method( 'getTitle' ) |
61
|
|
|
->will( $this->returnValue( $title ) ); |
62
|
|
|
|
63
|
|
|
$parser->expects( $this->any() ) |
64
|
|
|
->method( 'getOutput' ) |
65
|
|
|
->will( $this->returnValue( $parserOutput ) ); |
66
|
|
|
|
67
|
|
|
$instance = new HookRegistry( $this->store, $this->cache, $this->cacheKeyProvider ); |
68
|
|
|
$instance->register(); |
69
|
|
|
|
70
|
|
|
$this->doTestParserFirstCallInit( $instance, $parser ); |
71
|
|
|
$this->doTestNewRevisionFromEditComplete( $instance ); |
72
|
|
|
$this->doTestSkinTemplateGetLanguageLink( $instance ); |
73
|
|
|
$this->doTestPageContentLanguage( $instance ); |
74
|
|
|
$this->doTestArticleFromTitle( $instance ); |
75
|
|
|
$this->doTestArticlePurge( $instance ); |
76
|
|
|
$this->doTestParserAfterTidy( $instance, $parser ); |
77
|
|
|
|
78
|
|
|
$this->doTestInitProperties( $instance ); |
79
|
|
|
$this->doTestSQLStoreBeforeDeleteSubjectCompletes( $instance ); |
80
|
|
|
$this->doTestSQLStoreBeforeChangeTitleComplete( $instance ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
public function testOnBeforeConfigCompletion() { |
84
|
|
|
|
85
|
|
|
$config = [ |
86
|
|
|
'smwgFulltextSearchPropertyExemptionList' => [] |
87
|
|
|
]; |
88
|
|
|
|
89
|
|
|
$propertyExemptionList = [ |
90
|
|
|
'__sil_iwl_lang', |
91
|
|
|
'__sil_ill_lang' |
92
|
|
|
]; |
93
|
|
|
|
94
|
|
|
HookRegistry::onBeforeConfigCompletion( $config ); |
95
|
|
|
|
96
|
|
|
$this->assertEquals( |
97
|
|
|
[ |
98
|
|
|
'smwgFulltextSearchPropertyExemptionList' => $propertyExemptionList, |
99
|
|
|
], |
100
|
|
|
$config |
101
|
|
|
); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
public function doTestParserFirstCallInit( $instance, $parser ) { |
105
|
|
|
|
106
|
|
|
$handler = 'ParserFirstCallInit'; |
107
|
|
|
|
108
|
|
|
$this->assertTrue( |
109
|
|
|
$instance->isRegistered( $handler ) |
110
|
|
|
); |
111
|
|
|
|
112
|
|
|
$this->assertThatHookIsExcutable( |
113
|
|
|
$instance->getHandlerFor( $handler ), |
114
|
|
|
[ &$parser ] |
115
|
|
|
); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function doTestNewRevisionFromEditComplete( $instance ) { |
119
|
|
|
|
120
|
|
|
$handler = 'NewRevisionFromEditComplete'; |
121
|
|
|
|
122
|
|
|
$title = Title::newFromText( __METHOD__ ); |
123
|
|
|
|
124
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
125
|
|
|
->disableOriginalConstructor() |
126
|
|
|
->getMock(); |
127
|
|
|
|
128
|
|
|
$wikipage->expects( $this->any() ) |
129
|
|
|
->method( 'getTitle' ) |
130
|
|
|
->will( $this->returnValue( $title ) ); |
131
|
|
|
|
132
|
|
|
$this->assertTrue( |
133
|
|
|
$instance->isRegistered( $handler ) |
134
|
|
|
); |
135
|
|
|
|
136
|
|
|
$this->assertThatHookIsExcutable( |
137
|
|
|
$instance->getHandlerFor( $handler ), |
138
|
|
|
[ $wikipage ] |
139
|
|
|
); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public function doTestArticlePurge( $instance ) { |
143
|
|
|
|
144
|
|
|
$handler = 'ArticlePurge'; |
145
|
|
|
|
146
|
|
|
$title = Title::newFromText( __METHOD__ ); |
147
|
|
|
|
148
|
|
|
$wikipage = $this->getMockBuilder( '\WikiPage' ) |
149
|
|
|
->disableOriginalConstructor() |
150
|
|
|
->getMock(); |
151
|
|
|
|
152
|
|
|
$wikipage->expects( $this->any() ) |
153
|
|
|
->method( 'getTitle' ) |
154
|
|
|
->will( $this->returnValue( $title ) ); |
155
|
|
|
|
156
|
|
|
$this->assertTrue( |
157
|
|
|
$instance->isRegistered( $handler ) |
158
|
|
|
); |
159
|
|
|
|
160
|
|
|
$this->assertThatHookIsExcutable( |
161
|
|
|
$instance->getHandlerFor( $handler ), |
162
|
|
|
[ &$wikipage ] |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function doTestSkinTemplateGetLanguageLink( $instance ) { |
167
|
|
|
|
168
|
|
|
$handler = 'SkinTemplateGetLanguageLink'; |
169
|
|
|
|
170
|
|
|
$title = Title::newFromText( __METHOD__ ); |
171
|
|
|
$languageLink = []; |
172
|
|
|
|
173
|
|
|
$this->assertTrue( |
174
|
|
|
$instance->isRegistered( $handler ) |
175
|
|
|
); |
176
|
|
|
|
177
|
|
|
$this->assertThatHookIsExcutable( |
178
|
|
|
$instance->getHandlerFor( $handler ), |
179
|
|
|
[ &$languageLink, $title, $title ] |
180
|
|
|
); |
181
|
|
|
} |
182
|
|
|
|
183
|
|
|
public function doTestPageContentLanguage( $instance ) { |
184
|
|
|
|
185
|
|
|
$handler = 'PageContentLanguage'; |
186
|
|
|
$pageLang = ''; |
187
|
|
|
|
188
|
|
|
$title = Title::newFromText( __METHOD__ ); |
189
|
|
|
|
190
|
|
|
$this->assertTrue( |
191
|
|
|
$instance->isRegistered( $handler ) |
192
|
|
|
); |
193
|
|
|
|
194
|
|
|
$this->assertThatHookIsExcutable( |
195
|
|
|
$instance->getHandlerFor( $handler ), |
196
|
|
|
[ $title, &$pageLang ] |
197
|
|
|
); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function doTestArticleFromTitle( $instance ) { |
201
|
|
|
|
202
|
|
|
$handler = 'ArticleFromTitle'; |
203
|
|
|
|
204
|
|
|
$title = Title::newFromText( __METHOD__ ); |
205
|
|
|
$page = ''; |
206
|
|
|
|
207
|
|
|
$this->assertTrue( |
208
|
|
|
$instance->isRegistered( $handler ) |
209
|
|
|
); |
210
|
|
|
|
211
|
|
|
$this->assertThatHookIsExcutable( |
212
|
|
|
$instance->getHandlerFor( $handler ), |
213
|
|
|
[ $title, &$page ] |
214
|
|
|
); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
public function doTestParserAfterTidy( $instance, $parser ) { |
218
|
|
|
|
219
|
|
|
$handler = 'ParserAfterTidy'; |
220
|
|
|
$text = ''; |
221
|
|
|
|
222
|
|
|
$this->assertTrue( |
223
|
|
|
$instance->isRegistered( $handler ) |
224
|
|
|
); |
225
|
|
|
|
226
|
|
|
$this->assertThatHookIsExcutable( |
227
|
|
|
$instance->getHandlerFor( $handler ), |
228
|
|
|
[ &$parser, &$text ] |
229
|
|
|
); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
public function doTestInitProperties( $instance ) { |
233
|
|
|
|
234
|
|
|
$handler = 'SMW::Property::initProperties'; |
235
|
|
|
|
236
|
|
|
$propertyRegistry = $this->getMockBuilder( '\SMW\PropertyRegistry' ) |
237
|
|
|
->disableOriginalConstructor() |
238
|
|
|
->getMock(); |
239
|
|
|
|
240
|
|
|
$this->assertTrue( |
241
|
|
|
$instance->isRegistered( $handler ) |
242
|
|
|
); |
243
|
|
|
|
244
|
|
|
$this->assertThatHookIsExcutable( |
245
|
|
|
$instance->getHandlerFor( $handler ), |
246
|
|
|
[ $propertyRegistry ] |
247
|
|
|
); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function doTestSQLStoreBeforeDeleteSubjectCompletes( $instance ) { |
251
|
|
|
|
252
|
|
|
$handler = 'SMW::SQLStore::BeforeDeleteSubjectComplete'; |
253
|
|
|
$title = Title::newFromText( __METHOD__ ); |
254
|
|
|
|
255
|
|
|
$this->assertTrue( |
256
|
|
|
$instance->isRegistered( $handler ) |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
$this->assertThatHookIsExcutable( |
260
|
|
|
$instance->getHandlerFor( $handler ), |
261
|
|
|
[ $this->store, $title ] |
262
|
|
|
); |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function doTestSQLStoreBeforeChangeTitleComplete( $instance ) { |
266
|
|
|
|
267
|
|
|
$handler = 'SMW::SQLStore::BeforeChangeTitleComplete'; |
268
|
|
|
$title = Title::newFromText( __METHOD__ ); |
269
|
|
|
|
270
|
|
|
$this->assertTrue( |
271
|
|
|
$instance->isRegistered( $handler ) |
272
|
|
|
); |
273
|
|
|
|
274
|
|
|
$this->assertThatHookIsExcutable( |
275
|
|
|
$instance->getHandlerFor( $handler ), |
276
|
|
|
[ $this->store, $title, $title, 0, 0 ] |
277
|
|
|
); |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
private function assertThatHookIsExcutable( \Closure $handler, $arguments ) { |
281
|
|
|
$this->assertInternalType( |
282
|
|
|
'boolean', |
283
|
|
|
call_user_func_array( $handler, $arguments ) |
284
|
|
|
); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
} |
288
|
|
|
|