1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SMW\Tests\PropertyAnnotators; |
4
|
|
|
|
5
|
|
|
use SMW\DIProperty; |
6
|
|
|
use SMW\DIWikiPage; |
7
|
|
|
use SMW\Localizer; |
8
|
|
|
use SMW\PropertyAnnotators\NullPropertyAnnotator; |
9
|
|
|
use SMW\PropertyAnnotators\PredefinedPropertyAnnotator; |
10
|
|
|
use SMW\Tests\Utils\Mock\MockTitle; |
11
|
|
|
use SMW\Tests\Utils\UtilityFactory; |
12
|
|
|
use Title; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @covers \SMW\PropertyAnnotators\PredefinedPropertyAnnotator |
16
|
|
|
* @group semantic-mediawiki |
17
|
|
|
* |
18
|
|
|
* @license GNU GPL v2+ |
19
|
|
|
* @since 1.9 |
20
|
|
|
* |
21
|
|
|
* @author mwjames |
22
|
|
|
*/ |
23
|
|
|
class PredefinedPropertyAnnotatorTest extends \PHPUnit_Framework_TestCase { |
24
|
|
|
|
25
|
|
|
private $semanticDataFactory; |
26
|
|
|
private $semanticDataValidator; |
27
|
|
|
|
28
|
|
|
protected function setUp() { |
29
|
|
|
parent::setUp(); |
30
|
|
|
|
31
|
|
|
$this->semanticDataFactory = UtilityFactory::getInstance()->newSemanticDataFactory(); |
32
|
|
|
$this->semanticDataValidator = UtilityFactory::getInstance()->newValidatorFactory()->newSemanticDataValidator(); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testCanConstruct() { |
36
|
|
|
|
37
|
|
|
$semanticData = $this->getMockBuilder( '\SMW\SemanticData' ) |
38
|
|
|
->disableOriginalConstructor() |
39
|
|
|
->getMock(); |
40
|
|
|
|
41
|
|
|
$pageInfo = $this->getMockBuilder( '\SMW\PageInfo' ) |
42
|
|
|
->disableOriginalConstructor() |
43
|
|
|
->getMock(); |
44
|
|
|
|
45
|
|
|
$instance = new PredefinedPropertyAnnotator( |
46
|
|
|
new NullPropertyAnnotator( $semanticData ), |
47
|
|
|
$pageInfo |
48
|
|
|
); |
49
|
|
|
|
50
|
|
|
$this->assertInstanceOf( |
51
|
|
|
'\SMW\PropertyAnnotators\PredefinedPropertyAnnotator', |
52
|
|
|
$instance |
53
|
|
|
); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @dataProvider specialPropertiesDataProvider |
58
|
|
|
*/ |
59
|
|
|
public function testAddSpecialProperties( array $parameters, array $expected ) { |
60
|
|
|
|
61
|
|
|
$semanticData = $this->semanticDataFactory |
62
|
|
|
->setSubject( $parameters['subject'] ) |
63
|
|
|
->newEmptySemanticData(); |
64
|
|
|
|
65
|
|
|
$pageInfo = $this->getMockBuilder( '\SMW\PageInfo' ) |
66
|
|
|
->disableOriginalConstructor() |
67
|
|
|
->getMock(); |
68
|
|
|
|
69
|
|
|
foreach ( $parameters['pageInfo'] as $method => $returnValue ) { |
70
|
|
|
$pageInfo->expects( $this->any() ) |
71
|
|
|
->method( $method ) |
72
|
|
|
->will( $this->returnValue( $returnValue ) ); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$instance = new PredefinedPropertyAnnotator( |
76
|
|
|
new NullPropertyAnnotator( $semanticData ), |
77
|
|
|
$pageInfo |
78
|
|
|
); |
79
|
|
|
|
80
|
|
|
$instance->setPredefinedPropertyList( |
81
|
|
|
$parameters['settings']['smwgPageSpecialProperties'] |
82
|
|
|
); |
83
|
|
|
|
84
|
|
|
$instance->addAnnotation(); |
85
|
|
|
|
86
|
|
|
$this->semanticDataValidator->assertThatPropertiesAreSet( |
87
|
|
|
$expected, |
88
|
|
|
$instance->getSemanticData() |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function specialPropertiesDataProvider() { |
93
|
|
|
|
94
|
|
|
$provider = array(); |
95
|
|
|
|
96
|
|
|
#0 Unknown |
97
|
|
|
$provider[] = array( |
98
|
|
|
array( |
99
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'UNKNOWN' ) ), |
100
|
|
|
'settings' => array( |
101
|
|
|
'smwgPageSpecialProperties' => array( 'Lala', '_Lula', '-Lila', '' ) |
102
|
|
|
), |
103
|
|
|
'pageInfo' => array(), |
104
|
|
|
), |
105
|
|
|
array( |
106
|
|
|
'propertyCount' => 0, |
107
|
|
|
) |
108
|
|
|
); |
109
|
|
|
|
110
|
|
|
#1 TYPE_MODIFICATION_DATE |
111
|
|
|
$provider[] = array( |
112
|
|
|
array( |
113
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'withModificationDate' ) ), |
114
|
|
|
'settings' => array( |
115
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MODIFICATION_DATE ) |
116
|
|
|
), |
117
|
|
|
'pageInfo' => array( 'getModificationDate' => 1272508903 ) |
118
|
|
|
), |
119
|
|
|
array( |
120
|
|
|
'propertyCount' => 1, |
121
|
|
|
'propertyKeys' => '_MDAT', |
122
|
|
|
'propertyValues' => array( '2010-04-29T02:41:43' ), |
123
|
|
|
) |
124
|
|
|
); |
125
|
|
|
|
126
|
|
|
#2 TYPE_CREATION_DATE |
127
|
|
|
$provider[] = array( |
128
|
|
|
array( |
129
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'withCreationDate' ) ), |
130
|
|
|
'settings' => array( |
131
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_CREATION_DATE ) |
132
|
|
|
), |
133
|
|
|
'pageInfo' => array( 'getCreationDate' => 1272508903 ) |
134
|
|
|
), |
135
|
|
|
array( |
136
|
|
|
'propertyCount' => 1, |
137
|
|
|
'propertyKeys' => '_CDAT', |
138
|
|
|
'propertyValues' => array( '2010-04-29T02:41:43' ), |
139
|
|
|
) |
140
|
|
|
); |
141
|
|
|
|
142
|
|
|
#3 TYPE_NEW_PAGE |
143
|
|
|
$provider[] = array( |
144
|
|
|
array( |
145
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'NEW_PAGE_isNew' ) ), |
146
|
|
|
'settings' => array( |
147
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_NEW_PAGE ) |
148
|
|
|
), |
149
|
|
|
'pageInfo' => array( 'isNewPage' => true ) |
150
|
|
|
), |
151
|
|
|
array( |
152
|
|
|
'propertyCount' => 1, |
153
|
|
|
'propertyKeys' => '_NEWP', |
154
|
|
|
'propertyValues' => array( true ), |
155
|
|
|
) |
156
|
|
|
); |
157
|
|
|
|
158
|
|
|
#4 |
159
|
|
|
$provider[] = array( |
160
|
|
|
array( |
161
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'NEW_PAGE_isNotNew' ) ), |
162
|
|
|
'settings' => array( |
163
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_NEW_PAGE ) |
164
|
|
|
), |
165
|
|
|
'pageInfo' => array( 'isNewPage' => false ) |
166
|
|
|
), |
167
|
|
|
array( |
168
|
|
|
'propertyCount' => 1, |
169
|
|
|
'propertyKeys' => '_NEWP', |
170
|
|
|
'propertyValues' => array( false ), |
171
|
|
|
) |
172
|
|
|
); |
173
|
|
|
|
174
|
|
|
#5 TYPE_LAST_EDITOR |
175
|
|
|
$userPage = MockTitle::buildMock( 'Lula' ); |
176
|
|
|
$userNS = Localizer::getInstance()->getNamespaceTextById( NS_USER ); |
177
|
|
|
|
178
|
|
|
$userPage->expects( $this->any() ) |
179
|
|
|
->method( 'getNamespace' ) |
180
|
|
|
->will( $this->returnValue( NS_USER ) ); |
181
|
|
|
|
182
|
|
|
$provider[] = array( |
183
|
|
|
array( |
184
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'withLastEditor' ) ), |
185
|
|
|
'settings' => array( |
186
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_LAST_EDITOR ) |
187
|
|
|
), |
188
|
|
|
'pageInfo' => array( 'getLastEditor' => $userPage ) |
189
|
|
|
), |
190
|
|
|
array( |
191
|
|
|
'propertyCount' => 1, |
192
|
|
|
'propertyKeys' => '_LEDT', |
193
|
|
|
'propertyValues' => array( ":$userNS:Lula" ), |
194
|
|
|
) |
195
|
|
|
); |
196
|
|
|
|
197
|
|
|
#6 Combined entries |
198
|
|
|
$userPage = MockTitle::buildMock( 'Lula' ); |
199
|
|
|
$userNS = Localizer::getInstance()->getNamespaceTextById( NS_USER ); |
200
|
|
|
|
201
|
|
|
$userPage->expects( $this->any() ) |
202
|
|
|
->method( 'getNamespace' ) |
203
|
|
|
->will( $this->returnValue( NS_USER ) ); |
204
|
|
|
|
205
|
|
|
$provider[] = array( |
206
|
|
|
array( |
207
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'withCombinedEntries' ) ), |
208
|
|
|
'settings' => array( |
209
|
|
|
'smwgPageSpecialProperties' => array( '_MDAT', '_LEDT' ) |
210
|
|
|
), |
211
|
|
|
'pageInfo' => array( |
212
|
|
|
'getModificationDate' => 1272508903, |
213
|
|
|
'getLastEditor' => $userPage |
214
|
|
|
) |
215
|
|
|
), |
216
|
|
|
array( |
217
|
|
|
'propertyCount' => 2, |
218
|
|
|
'propertyKeys' => array( '_MDAT', '_LEDT' ), |
219
|
|
|
'propertyValues' => array( '2010-04-29T02:41:43', ":$userNS:Lula" ), |
220
|
|
|
) |
221
|
|
|
); |
222
|
|
|
|
223
|
|
|
#7 TYPE_MEDIA |
224
|
|
|
$provider[] = array( |
225
|
|
|
array( |
226
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'MimePropertyForFilePage' ) ), |
227
|
|
|
'settings' => array( |
228
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MEDIA ) |
229
|
|
|
), |
230
|
|
|
'pageInfo' => array( |
231
|
|
|
'isFilePage' => true, |
232
|
|
|
'getMediaType' => 'FooMedia' |
233
|
|
|
) |
234
|
|
|
), |
235
|
|
|
array( |
236
|
|
|
'propertyCount' => 1, |
237
|
|
|
'propertyKeys' => '_MEDIA', |
238
|
|
|
'propertyValues' => array( 'FooMedia' ), |
239
|
|
|
) |
240
|
|
|
); |
241
|
|
|
|
242
|
|
|
#8 |
243
|
|
|
$provider[] = array( |
244
|
|
|
array( |
245
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'MediaPropertyForNonFilePage' ) ), |
246
|
|
|
'settings' => array( |
247
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MEDIA ) |
248
|
|
|
), |
249
|
|
|
'pageInfo' => array( |
250
|
|
|
'isFilePage' => false, |
251
|
|
|
'getMediaType' => 'FooMedia' |
252
|
|
|
) |
253
|
|
|
), |
254
|
|
|
array( |
255
|
|
|
'propertyCount' => 0 |
256
|
|
|
) |
257
|
|
|
); |
258
|
|
|
|
259
|
|
|
#9 TYPE_MIME |
260
|
|
|
$provider[] = array( |
261
|
|
|
array( |
262
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'MimePropertyForFilePage' ) ), |
263
|
|
|
'settings' => array( |
264
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MIME ) |
265
|
|
|
), |
266
|
|
|
'pageInfo' => array( |
267
|
|
|
'isFilePage' => true, |
268
|
|
|
'getMimeType' => 'FooMime' |
269
|
|
|
) |
270
|
|
|
), |
271
|
|
|
array( |
272
|
|
|
'propertyCount' => 1, |
273
|
|
|
'propertyKeys' => '_MIME', |
274
|
|
|
'propertyValues' => array( 'FooMime' ), |
275
|
|
|
) |
276
|
|
|
); |
277
|
|
|
|
278
|
|
|
#10 |
279
|
|
|
$provider[] = array( |
280
|
|
|
array( |
281
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'MimePropertyForNonFilePage' ) ), |
282
|
|
|
'settings' => array( |
283
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MIME ) |
284
|
|
|
), |
285
|
|
|
'pageInfo' => array( |
286
|
|
|
'isFilePage' => false, |
287
|
|
|
'getMimeType' => 'FooMime' |
288
|
|
|
) |
289
|
|
|
), |
290
|
|
|
array( |
291
|
|
|
'propertyCount' => 0 |
292
|
|
|
) |
293
|
|
|
); |
294
|
|
|
|
295
|
|
|
#11 Empty TYPE_MIME |
296
|
|
|
$provider[] = array( |
297
|
|
|
array( |
298
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'EmptyMimePropertyFilePage' ) ), |
299
|
|
|
'settings' => array( |
300
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MIME ) |
301
|
|
|
), |
302
|
|
|
'pageInfo' => array( |
303
|
|
|
'isFilePage' => true, |
304
|
|
|
'getMimeType' => '' |
305
|
|
|
) |
306
|
|
|
), |
307
|
|
|
array( |
308
|
|
|
'propertyCount' => 0 |
309
|
|
|
) |
310
|
|
|
); |
311
|
|
|
|
312
|
|
|
#12 Empty TYPE_MEDIA |
313
|
|
|
$provider[] = array( |
314
|
|
|
array( |
315
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'EmptyMediaPropertyFilePage' ) ), |
316
|
|
|
'settings' => array( |
317
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MEDIA ) |
318
|
|
|
), |
319
|
|
|
'pageInfo' => array( |
320
|
|
|
'isFilePage' => true, |
321
|
|
|
'getMediaType' => '' |
322
|
|
|
) |
323
|
|
|
), |
324
|
|
|
array( |
325
|
|
|
'propertyCount' => 0 |
326
|
|
|
) |
327
|
|
|
); |
328
|
|
|
|
329
|
|
|
#13 Null TYPE_MIME |
330
|
|
|
$provider[] = array( |
331
|
|
|
array( |
332
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'NullMimePropertyFilePage' ) ), |
333
|
|
|
'settings' => array( |
334
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MIME ) |
335
|
|
|
), |
336
|
|
|
'pageInfo' => array( |
337
|
|
|
'isFilePage' => true, |
338
|
|
|
'getMimeType' => null |
339
|
|
|
) |
340
|
|
|
), |
341
|
|
|
array( |
342
|
|
|
'propertyCount' => 0 |
343
|
|
|
) |
344
|
|
|
); |
345
|
|
|
|
346
|
|
|
#14 Null TYPE_MEDIA |
347
|
|
|
$provider[] = array( |
348
|
|
|
array( |
349
|
|
|
'subject' => DIWikiPage::newFromTitle( Title::newFromText( 'NullMediaPropertyFilePage' ) ), |
350
|
|
|
'settings' => array( |
351
|
|
|
'smwgPageSpecialProperties' => array( DIProperty::TYPE_MEDIA ) |
352
|
|
|
), |
353
|
|
|
'pageInfo' => array( |
354
|
|
|
'isFilePage' => true, |
355
|
|
|
'getMimeType' => null |
356
|
|
|
) |
357
|
|
|
), |
358
|
|
|
array( |
359
|
|
|
'propertyCount' => 0 |
360
|
|
|
) |
361
|
|
|
); |
362
|
|
|
|
363
|
|
|
return $provider; |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
} |
367
|
|
|
|