|
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
|
|
|
'alternateName' => 'Test soc srl', |
|
46
|
|
|
'addressCountry' => 'IT', |
|
47
|
|
|
'addressLocality' => 'LECCO', |
|
48
|
|
|
'addressRegion' => 'LC', |
|
49
|
|
|
'streetAddress' => 'Via F. Valsecchi,124', |
|
50
|
|
|
'postalCode' => '23900', |
|
51
|
|
|
'page' => 'http://linkeddata.center/', |
|
52
|
|
|
'telephone' => '+39 3356382949', |
|
53
|
|
|
'faxNumber' => '0341 255188 ', |
|
54
|
|
|
'email' => '[email protected]', |
|
55
|
|
|
'geoDescription' => 'Via F. Valsecchi,124-23900 Lecco (LC)', |
|
56
|
|
|
'lat' => '1.12345', |
|
57
|
|
|
'long' => '2.123456', |
|
58
|
|
|
), |
|
59
|
|
|
array( |
|
60
|
|
|
'base' => 'http://linkeddata.center/botk/resource/', |
|
61
|
|
|
'lang' => 'it', |
|
62
|
|
|
'id' => '1234567890', |
|
63
|
|
|
'taxID' => 'FGNNRC63S06F205A', |
|
64
|
|
|
'vatID' => '01234567890', |
|
65
|
|
|
'legalName' => 'TEST SOC SRL', |
|
66
|
|
|
'alternateName' => 'Test soc srl', |
|
67
|
|
|
'addressCountry' => 'IT', |
|
68
|
|
|
'addressLocality' => 'LECCO', |
|
69
|
|
|
'addressRegion' => 'LC', |
|
70
|
|
|
'streetAddress' => 'VIA F.VALSECCHI, 124', |
|
71
|
|
|
'postalCode' => '23900', |
|
72
|
|
|
'page' => 'http://linkeddata.center/', |
|
73
|
|
|
'telephone' => '3356382949', |
|
74
|
|
|
'faxNumber' => '0341255188', |
|
75
|
|
|
'email' => '[email protected]', |
|
76
|
|
|
'geoDescription' => 'VIA F.VALSECCHI, 124 - 23900 LECCO (LC)', |
|
77
|
|
|
'lat' => '1.12345', |
|
78
|
|
|
'long' => '2.123456', |
|
79
|
|
|
), |
|
80
|
|
|
), |
|
81
|
|
|
array( |
|
82
|
|
|
array( |
|
83
|
|
|
'id' => '1234567890', |
|
84
|
|
|
'taxID' => '', |
|
85
|
|
|
'vatID' => '', |
|
86
|
|
|
'legalName' => null, |
|
87
|
|
|
'alternateName' => '', |
|
88
|
|
|
'addressCountry' => null, |
|
89
|
|
|
), |
|
90
|
|
|
array( |
|
91
|
|
|
'base' => 'http://linkeddata.center/botk/resource/', |
|
92
|
|
|
'lang' => 'it', |
|
93
|
|
|
'id' => '1234567890', |
|
94
|
|
|
'addressCountry' => 'IT', |
|
95
|
|
|
), |
|
96
|
|
|
), |
|
97
|
|
|
); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
public function testGetDefaultOptions() |
|
101
|
|
|
{ |
|
102
|
|
|
$options = array ( |
|
103
|
|
|
'base' => array(), |
|
104
|
|
|
'lang' => array( |
|
105
|
|
|
'default' => 'en', |
|
106
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
107
|
|
|
'options' => array('regexp'=>'/^[a-z]{2}$/') |
|
108
|
|
|
), |
|
109
|
|
|
); |
|
110
|
|
|
|
|
111
|
|
|
$expectedOptions =array ( |
|
112
|
|
|
'base' => array(), |
|
113
|
|
|
'uri' => array( |
|
114
|
|
|
'filter' => FILTER_SANITIZE_URL, |
|
115
|
|
|
), |
|
116
|
|
|
'lang' => array( |
|
117
|
|
|
'default' => 'en', |
|
118
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
119
|
|
|
'options' => array('regexp'=>'/^[a-z]{2}$/') |
|
120
|
|
|
), |
|
121
|
|
|
'id' => array( |
|
122
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
123
|
|
|
'options' => array('regexp'=>'/^[\w]+$/') |
|
124
|
|
|
), |
|
125
|
|
|
'taxID' => array( |
|
126
|
|
|
'filter' => FILTER_CALLBACK, |
|
127
|
|
|
'options' => '\BOTK\Filters::normalizeToken' |
|
128
|
|
|
), |
|
129
|
|
|
'vatID' => array( // italian rules |
|
130
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
131
|
|
|
'options' => array('regexp'=>'/^[0-9]{11}$/') |
|
132
|
|
|
), |
|
133
|
|
|
'legalName' => array( |
|
134
|
|
|
'filter' => FILTER_CALLBACK, |
|
135
|
|
|
'options' => '\BOTK\Filters::normalizeAddress' |
|
136
|
|
|
), |
|
137
|
|
|
'alternateName' => array(), |
|
138
|
|
|
'addressCountry' => array( |
|
139
|
|
|
'default' => 'IT', |
|
140
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
141
|
|
|
'options' => array('regexp'=>'/^[A-Z]{2}$/') |
|
142
|
|
|
), |
|
143
|
|
|
'addressLocality' => array( |
|
144
|
|
|
'filter' => FILTER_CALLBACK, |
|
145
|
|
|
'options' => '\BOTK\Filters::normalizeAddress' |
|
146
|
|
|
), |
|
147
|
|
|
'addressRegion' => array( |
|
148
|
|
|
'filter' => FILTER_CALLBACK, |
|
149
|
|
|
'options' => '\BOTK\Filters::normalizeAddress' |
|
150
|
|
|
), |
|
151
|
|
|
'streetAddress' => array( |
|
152
|
|
|
'filter' => FILTER_CALLBACK, |
|
153
|
|
|
'options' => '\BOTK\Filters::normalizeAddress' |
|
154
|
|
|
), |
|
155
|
|
|
'postalCode' => array( // italian rules |
|
156
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
157
|
|
|
'options' => array('regexp'=>'/^[0-9]{5}$/') |
|
158
|
|
|
), |
|
159
|
|
|
'page' => array( |
|
160
|
|
|
'filter' => FILTER_SANITIZE_URL |
|
161
|
|
|
), |
|
162
|
|
|
'telephone' => array( |
|
163
|
|
|
'filter' => FILTER_CALLBACK, |
|
164
|
|
|
'options' => '\BOTK\Filters::normalizeItTelephone' |
|
165
|
|
|
), |
|
166
|
|
|
'faxNumber' => array( |
|
167
|
|
|
'filter' => FILTER_CALLBACK, |
|
168
|
|
|
'options' => '\BOTK\Filters::normalizeItTelephone' |
|
169
|
|
|
), |
|
170
|
|
|
'email' => array( |
|
171
|
|
|
'filter' => FILTER_CALLBACK, |
|
172
|
|
|
'options' => '\BOTK\Filters::normalizeEmail' |
|
173
|
|
|
), |
|
174
|
|
|
'geoDescription' => array( |
|
175
|
|
|
'filter' => FILTER_CALLBACK, |
|
176
|
|
|
'options' => '\BOTK\Filters::normalizeAddress' |
|
177
|
|
|
), |
|
178
|
|
|
'lat' => array( // http://www.regexlib.com/REDetails.aspx?regexp_id=2728 |
|
179
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
180
|
|
|
'options' => array('regexp'=>'/^-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
|
181
|
|
|
), |
|
182
|
|
|
'long' => array( // http://stackoverflow.com/questions/3518504/regular-expression-for-matching-latitude-longitude-coordinates |
|
183
|
|
|
'filter' => FILTER_VALIDATE_REGEXP, |
|
184
|
|
|
'options' => array('regexp'=>'/-?([1-8]?[0-9]\.{1}\d{1,6}$|90\.{1}0{1,6}$)/') |
|
185
|
|
|
), |
|
186
|
|
|
); |
|
187
|
|
|
|
|
188
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness(array(),$options); |
|
189
|
|
|
$this->assertEquals($expectedOptions, $localBusiness->getOptions()); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
|
|
193
|
|
|
/** |
|
194
|
|
|
* @dataProvider goodRdf |
|
195
|
|
|
*/ |
|
196
|
|
|
public function testRdfGeneration($data, $rdf, $tripleCount) |
|
197
|
|
|
{ |
|
198
|
|
|
$localBusiness = new BOTK\Model\LocalBusiness($data); |
|
199
|
|
|
$this->assertEquals($rdf, (string) $localBusiness); |
|
200
|
|
|
$this->assertEquals($localBusiness->asTurtle(), (string) $localBusiness, "equivalence with __tostring"); |
|
201
|
|
|
$this->assertEquals($tripleCount, $localBusiness->getTripleCount()); |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
public function goodRdf() |
|
205
|
|
|
{ |
|
206
|
|
|
return array( |
|
207
|
|
|
array( |
|
208
|
|
|
array(), |
|
209
|
|
|
'', |
|
210
|
|
|
0, |
|
211
|
|
|
), |
|
212
|
|
|
array( |
|
213
|
|
|
array( |
|
214
|
|
|
'base' => 'urn:', |
|
215
|
|
|
'id' => 'abc', |
|
216
|
|
|
'vatID' => '01234567890', |
|
217
|
|
|
'legalName' => 'Calenda chiodi snc', |
|
218
|
|
|
), |
|
219
|
|
|
'<urn:abc> a schema:Organization;dct:identifier "abc";schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
220
|
|
|
4, |
|
221
|
|
|
), |
|
222
|
|
|
|
|
223
|
|
|
array( |
|
224
|
|
|
array( |
|
225
|
|
|
'uri' => 'urn:abc', |
|
226
|
|
|
'vatID' => '01234567890', |
|
227
|
|
|
'legalName' => 'Calenda chiodi snc', |
|
228
|
|
|
), |
|
229
|
|
|
'<urn:abc> a schema:Organization;schema:vatID "01234567890"@it;schema:legalName """CALENDA CHIODI SNC"""@it; . ', |
|
230
|
|
|
3, |
|
231
|
|
|
), |
|
232
|
|
|
|
|
233
|
|
|
array( |
|
234
|
|
|
array( |
|
235
|
|
|
'uri' => 'urn:abc', |
|
236
|
|
|
'lat' => '43.23456', |
|
237
|
|
|
'long' => '35.23444', |
|
238
|
|
|
), |
|
239
|
|
|
'<urn:abc> a schema:Organization;schema:location <urn:abc_place>; . <geo:43.23456,35.23444> a schema:GeoCoordinates;wgs:lat 43.23456 ;wgs:long 35.23444 ; . <urn:abc_place> a schema:LocalBusiness;schema:geo <geo:43.23456,35.23444>; . ', |
|
240
|
|
|
7, |
|
241
|
|
|
), |
|
242
|
|
|
); |
|
243
|
|
|
} |
|
244
|
|
|
} |
|
245
|
|
|
|
|
246
|
|
|
|
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.