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