|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class LocalBusinessTest extends PHPUnit_Framework_TestCase |
|
|
|
|
|
|
4
|
|
|
{ |
|
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @dataProvider goodLocalBusiness |
|
7
|
|
|
*/ |
|
8
|
|
|
public function testDataFilteringWithValidDataAndDefaultOptions($data, $expectedData) |
|
9
|
|
|
{ |
|
10
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness($data); |
|
11
|
|
|
$this->assertEquals($expectedData, $localBusiness->asArray()); |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
public function goodLocalBusiness() |
|
15
|
|
|
{ |
|
16
|
|
|
return array( |
|
17
|
|
|
array( |
|
18
|
|
|
array(), |
|
19
|
|
|
array( |
|
20
|
|
|
'base' => 'http://linkeddata.center/botk/resource/', |
|
21
|
|
|
'lang' => 'it', |
|
22
|
|
|
'addressCountry' => 'IT', |
|
23
|
|
|
), |
|
24
|
|
|
), |
|
25
|
|
|
|
|
26
|
|
|
array( |
|
27
|
|
|
array( |
|
28
|
|
|
'base' => 'http://linkeddata.center/botk/resource#', |
|
29
|
|
|
'lang' => 'en', |
|
30
|
|
|
'addressCountry' => 'US', |
|
31
|
|
|
), |
|
32
|
|
|
array( |
|
33
|
|
|
'base' => 'http://linkeddata.center/botk/resource#', |
|
34
|
|
|
'lang' => 'en', |
|
35
|
|
|
'addressCountry' => 'US', |
|
36
|
|
|
), |
|
37
|
|
|
), |
|
38
|
|
|
|
|
39
|
|
|
array( |
|
40
|
|
|
array( |
|
41
|
|
|
'id' => '1234567890', |
|
42
|
|
|
'taxID' => 'fgn nrc 63S0 6F205 A', |
|
43
|
|
|
'vatID' => '01234567890', |
|
44
|
|
|
'legalName' => 'Test soc srl', |
|
45
|
|
|
'businessName' => 'Test soc srl', |
|
46
|
|
|
'businessType' => 'schema:MedicalOrganization', |
|
47
|
|
|
'addressCountry' => 'IT', |
|
48
|
|
|
'addressLocality' => 'LECCO', |
|
49
|
|
|
'addressRegion' => 'LC', |
|
50
|
|
|
'streetAddress' => 'Via F. Valsecchi,124', |
|
51
|
|
|
'postalCode' => '23900', |
|
52
|
|
|
'page' => 'http://linkeddata.center/', |
|
53
|
|
|
'telephone' => '+39 3356382949', |
|
54
|
|
|
'faxNumber' => '+39 3356382949', |
|
55
|
|
|
'email' => array('[email protected]'), |
|
56
|
|
|
'geoDescription' => array('Via F. Valsecchi,124-23900 Lecco (LC)'), |
|
57
|
|
|
'lat' => '1.12345', |
|
58
|
|
|
'long' => '2.123456', |
|
59
|
|
|
), |
|
60
|
|
|
array( |
|
61
|
|
|
'base' => 'http://linkeddata.center/botk/resource/', |
|
62
|
|
|
'lang' => 'it', |
|
63
|
|
|
'id' => '1234567890', |
|
64
|
|
|
'businessType' => array('schema:MedicalOrganization'), |
|
65
|
|
|
'taxID' => 'FGNNRC63S06F205A', |
|
66
|
|
|
'vatID' => '01234567890', |
|
67
|
|
|
'legalName' => 'TEST SOC SRL', |
|
68
|
|
|
'businessName' => array('Test soc srl'), |
|
69
|
|
|
'addressCountry' => 'IT', |
|
70
|
|
|
'addressLocality' => 'LECCO', |
|
71
|
|
|
'addressRegion' => 'LC', |
|
72
|
|
|
'streetAddress' => 'VIA F.VALSECCHI, 124', |
|
73
|
|
|
'postalCode' => '23900', |
|
74
|
|
|
'page' => array('http://linkeddata.center/'), |
|
75
|
|
|
'telephone' => '3356382949', |
|
76
|
|
|
'faxNumber' => '3356382949', |
|
77
|
|
|
'email' => array('[email protected]'), |
|
78
|
|
|
'geoDescription' => array('VIA F.VALSECCHI, 124 - 23900 LECCO (LC)'), |
|
79
|
|
|
'lat' => '1.12345', |
|
80
|
|
|
'long' => '2.123456', |
|
81
|
|
|
), |
|
82
|
|
|
), |
|
83
|
|
|
array( |
|
84
|
|
|
array( |
|
85
|
|
|
'id' => '1234567890', |
|
86
|
|
|
'addressCountry' => null, |
|
87
|
|
|
), |
|
88
|
|
|
array( |
|
89
|
|
|
'base' => 'http://linkeddata.center/botk/resource/', |
|
90
|
|
|
'lang' => 'it', |
|
91
|
|
|
'id' => '1234567890', |
|
92
|
|
|
'addressCountry' => 'IT', |
|
93
|
|
|
), |
|
94
|
|
|
), |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
public function testGetDefaultOptions() |
|
99
|
|
|
{ |
|
100
|
|
|
$expectedOptions = array ( |
|
101
|
|
|
'base' => array( |
|
102
|
|
|
'default' => 'http://linkeddata.center/botk/resource/', |
|
103
|
|
|
'filter' => FILTER_SANITIZE_URL, |
|
104
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
105
|
|
|
), |
|
106
|
|
|
'uri' => array( |
|
107
|
|
|
'filter' => FILTER_SANITIZE_URL, |
|
108
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
109
|
|
|
), |
|
110
|
|
|
'lang' => array( |
|
111
|
|
|
'default' => 'it', |
|
112
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
113
|
|
|
'options' => array('regexp'=>'/^[a-z]{2}$/'), |
|
114
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
115
|
|
|
), |
|
116
|
|
|
'id' => array( |
|
117
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
118
|
|
|
'options' => array('regexp'=>'/^\w+$/'), |
|
119
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
120
|
|
|
), |
|
121
|
|
|
'businessType' => array( |
|
122
|
|
|
// additional types as extension of schema:LocalBusiness |
|
123
|
|
|
'filter' => FILTER_DEFAULT, |
|
124
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
125
|
|
|
), |
|
126
|
|
|
'taxID' => array( |
|
127
|
|
|
'filter' => FILTER_CALLBACK, |
|
128
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_TOKEN', |
|
129
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
130
|
|
|
), |
|
131
|
|
|
'vatID' => array( // italian rules |
|
132
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
133
|
|
|
'options' => array('regexp'=>'/^[0-9]{11}$/'), |
|
134
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
135
|
|
|
), |
|
136
|
|
|
'legalName' => array( |
|
137
|
|
|
'filter' => FILTER_CALLBACK, |
|
138
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
139
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
140
|
|
|
), |
|
141
|
|
|
'businessName' => array( |
|
142
|
|
|
// a schema:alternateName for schema:PostalAddress |
|
143
|
|
|
'filter' => FILTER_DEFAULT, |
|
144
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
145
|
|
|
), |
|
146
|
|
|
'addressCountry' => array( |
|
147
|
|
|
'default' => 'IT', |
|
148
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
149
|
|
|
'options' => array('regexp'=>'/^[A-Z]{2}$/'), |
|
150
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
151
|
|
|
), |
|
152
|
|
|
'addressLocality' => array( |
|
153
|
|
|
'filter' => FILTER_CALLBACK, |
|
154
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
155
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
156
|
|
|
), |
|
157
|
|
|
'addressRegion' => array( |
|
158
|
|
|
'filter' => FILTER_CALLBACK, |
|
159
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
160
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
161
|
|
|
), |
|
162
|
|
|
'streetAddress' => array( |
|
163
|
|
|
'filter' => FILTER_CALLBACK, |
|
164
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
165
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
166
|
|
|
), |
|
167
|
|
|
'postalCode' => array( // italian rules |
|
168
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
169
|
|
|
'options' => array('regexp'=>'/^[0-9]{5}$/'), |
|
170
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
171
|
|
|
), |
|
172
|
|
|
'page' => array( |
|
173
|
|
|
'filter' => FILTER_SANITIZE_URL, |
|
174
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
175
|
|
|
), |
|
176
|
|
|
'telephone' => array( |
|
177
|
|
|
'filter' => FILTER_CALLBACK, |
|
178
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
179
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
180
|
|
|
), |
|
181
|
|
|
'faxNumber' => array( |
|
182
|
|
|
'filter' => FILTER_CALLBACK, |
|
183
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_TELEPHONE', |
|
184
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
185
|
|
|
), |
|
186
|
|
|
'email' => array( |
|
187
|
|
|
'filter' => FILTER_CALLBACK, |
|
188
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_EMAIL', |
|
189
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
190
|
|
|
), |
|
191
|
|
|
'geoDescription' => array( |
|
192
|
|
|
// a schema:alternateName for schema:GeoCoordinates |
|
193
|
|
|
'filter' => FILTER_CALLBACK, |
|
194
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_ADDRESS', |
|
195
|
|
|
'flags' => FILTER_FORCE_ARRAY, |
|
196
|
|
|
), |
|
197
|
|
|
'lat' => array( |
|
198
|
|
|
'filter' => FILTER_CALLBACK, |
|
199
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
200
|
|
|
), |
|
201
|
|
|
'long' => array( |
|
202
|
|
|
'filter' => FILTER_CALLBACK, |
|
203
|
|
|
'options' => '\BOTK\Filters::FILTER_SANITIZE_LAT_LONG', |
|
204
|
|
|
), |
|
205
|
|
|
); |
|
206
|
|
|
|
|
207
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness(array()); |
|
208
|
|
|
$this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
209
|
|
|
} |
|
210
|
|
|
|
|
211
|
|
|
|
|
212
|
|
|
|
|
213
|
|
|
public function testChangeDefaultOptions() |
|
214
|
|
|
{ |
|
215
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness(array(), array ( |
|
216
|
|
|
'lang' => array('default' => 'en'), |
|
217
|
|
|
'vatID' => array('options' => array('regexp'=>'/^IT[0-9]{11}$/')), |
|
218
|
|
|
)); |
|
219
|
|
|
$options = $localBusiness->getOptions(); |
|
220
|
|
|
$this->assertEquals( |
|
221
|
|
|
array( |
|
222
|
|
|
'default' => 'en', |
|
223
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
224
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
225
|
|
|
'options' => array('regexp'=>'/^[a-z]{2}$/') |
|
226
|
|
|
), |
|
227
|
|
|
$options['lang'] |
|
228
|
|
|
); |
|
229
|
|
|
$this->assertEquals( |
|
230
|
|
|
array( |
|
231
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
232
|
|
|
'flags' => FILTER_REQUIRE_SCALAR, |
|
233
|
|
|
'options' => array('regexp'=>'/^IT[0-9]{11}$/') |
|
234
|
|
|
), |
|
235
|
|
|
$options['vatID'] |
|
236
|
|
|
); |
|
237
|
|
|
} |
|
238
|
|
|
|
|
239
|
|
|
|
|
240
|
|
|
/** |
|
241
|
|
|
* @dataProvider goodRdf |
|
242
|
|
|
*/ |
|
243
|
|
|
public function testRdfGeneration($data, $rdf, $tripleCount) |
|
244
|
|
|
{ |
|
245
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness($data); |
|
246
|
|
|
$this->assertEquals($rdf, $localBusiness->asTurtle()); |
|
247
|
|
|
$this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
248
|
|
|
} |
|
249
|
|
|
|
|
250
|
|
|
public function goodRdf() |
|
251
|
|
|
{ |
|
252
|
|
|
return array( |
|
253
|
|
|
array( |
|
254
|
|
|
array(), |
|
255
|
|
|
'', |
|
256
|
|
|
0, |
|
257
|
|
|
), |
|
258
|
|
|
array( |
|
259
|
|
|
array( |
|
260
|
|
|
'base' => 'urn:', |
|
261
|
|
|
'id' => 'abc', |
|
262
|
|
|
'vatID' => '01234567890', |
|
263
|
|
|
'legalName' => 'Calenda chiodi snc', |
|
264
|
|
|
), |
|
265
|
|
|
'<urn:abc> a schema:Organization;dct:identifier "abc";schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
266
|
|
|
4, |
|
267
|
|
|
), |
|
268
|
|
|
|
|
269
|
|
|
array( |
|
270
|
|
|
array( |
|
271
|
|
|
'uri' => 'urn:abc', |
|
272
|
|
|
'vatID' => '01234567890', |
|
273
|
|
|
'legalName' => 'Calenda chiodi snc', |
|
274
|
|
|
), |
|
275
|
|
|
'<urn:abc> a schema:Organization;schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
276
|
|
|
3, |
|
277
|
|
|
), |
|
278
|
|
|
|
|
279
|
|
|
array( |
|
280
|
|
|
array( |
|
281
|
|
|
'uri' => 'urn:abc', |
|
282
|
|
|
'lat' => '43.23456', |
|
283
|
|
|
'long' => '35.23444', |
|
284
|
|
|
), |
|
285
|
|
|
'<urn:abc> a schema:Organization;schema:location <urn:abc_place>; . <geo:43.234560,35.234440> a schema:GeoCoordinates;wgs:lat 43.234560 ;wgs:long 35.234440 ; . <urn:abc_place> a schema:LocalBusiness;schema:geo <geo:43.234560,35.234440>; . ', |
|
286
|
|
|
7, |
|
287
|
|
|
), |
|
288
|
|
|
); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
|
|
292
|
|
|
/** |
|
293
|
|
|
* @dataProvider structuredAdresses |
|
294
|
|
|
*/ |
|
295
|
|
|
public function testBuildNormalizedAddress($data, $expectedData) |
|
296
|
|
|
{ |
|
297
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness($data); |
|
298
|
|
|
$this->assertEquals($expectedData, $localBusiness->buildNormalizedAddress($data)); |
|
|
|
|
|
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
|
|
302
|
|
|
public function structuredAdresses() |
|
303
|
|
|
{ |
|
304
|
|
|
return array( |
|
305
|
|
|
array( |
|
306
|
|
|
array( |
|
307
|
|
|
'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
308
|
|
|
'addressLocality' => 'Lecco', |
|
309
|
|
|
'addressRegion' => 'LC', |
|
310
|
|
|
'addressCountry' => 'IT', |
|
311
|
|
|
'postalCode' => '23900', |
|
312
|
|
|
), |
|
313
|
|
|
'LUNGOLARIO LUIGI CADORNA, 1, 23900 LECCO (LC) - IT' |
|
314
|
|
|
), |
|
315
|
|
|
array( |
|
316
|
|
|
array( |
|
317
|
|
|
'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
318
|
|
|
'addressLocality' => 'Lecco', |
|
319
|
|
|
'addressCountry' => 'IT', |
|
320
|
|
|
), |
|
321
|
|
|
'LUNGOLARIO LUIGI CADORNA, 1, LECCO - IT' |
|
322
|
|
|
), |
|
323
|
|
|
array( |
|
324
|
|
|
array( |
|
325
|
|
|
'streetAddress' => 'Lungolario Luigi Cadorna, 1', |
|
326
|
|
|
'addressCountry' => 'IT', |
|
327
|
|
|
'postalCode' => '23900', |
|
328
|
|
|
), |
|
329
|
|
|
'LUNGOLARIO LUIGI CADORNA, 1, 23900 - IT' |
|
330
|
|
|
), |
|
331
|
|
|
array( |
|
332
|
|
|
array( |
|
333
|
|
|
'addressCountry' => 'IT', |
|
334
|
|
|
'postalCode' => '23900', |
|
335
|
|
|
), |
|
336
|
|
|
false |
|
337
|
|
|
), |
|
338
|
|
|
); |
|
339
|
|
|
} |
|
340
|
|
|
|
|
341
|
|
|
|
|
342
|
|
|
/** |
|
343
|
|
|
* @expectedException \BOTK\Exceptions\DataModelException |
|
344
|
|
|
* @dataProvider badLocalBusiness |
|
345
|
|
|
* |
|
346
|
|
|
*/ |
|
347
|
|
|
public function testBadLocalBusiness($data) |
|
348
|
|
|
{ |
|
349
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness($data); |
|
|
|
|
|
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
public function badLocalBusiness() |
|
353
|
|
|
{ |
|
354
|
|
|
return array( |
|
355
|
|
|
array(array('lang' => 'IT')), |
|
356
|
|
|
array(array('id' => 'invalid id')), |
|
357
|
|
|
array(array('vatID' => '012345678901')), //too long |
|
358
|
|
|
array(array('addressCountry' => 'italy')), //too long |
|
359
|
|
|
array(array('addressCountry' => 'it')), //lowercase |
|
360
|
|
|
array(array('postalCode' => '234992')), //toolong |
|
361
|
|
|
array(array('email' => 'ENRICO')), |
|
362
|
|
|
array(array('lat' => '90.12345')), //invalid lat |
|
363
|
|
|
array(array('lat' => '-90.12345')), //invalid lat |
|
364
|
|
|
|
|
365
|
|
|
); |
|
366
|
|
|
} |
|
367
|
|
|
} |
|
368
|
|
|
|
|
369
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.