|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the FabienCrassat\CurriculumVitaeBundle Symfony bundle. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Fabien Crassat <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace FabienCrassat\CurriculumVitaeBundle\Tests\Entity; |
|
13
|
|
|
|
|
14
|
|
|
use FabienCrassat\CurriculumVitaeBundle\Entity\Xml2arrayFunctions; |
|
15
|
|
|
|
|
16
|
|
|
class Xml2arrayFunctionsTest extends \PHPUnit_Framework_TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $XML; |
|
|
|
|
|
|
19
|
|
|
private $Xml2arrayFunctions; |
|
20
|
|
|
private $CV; |
|
|
|
|
|
|
21
|
|
|
|
|
22
|
|
|
public function testXml2arrayEmpty() { |
|
23
|
|
|
$string = <<<XML |
|
24
|
|
|
<?xml version='1.0'?> |
|
25
|
|
|
<document> |
|
26
|
|
|
</document> |
|
27
|
|
|
XML; |
|
28
|
|
|
$expected = array(); |
|
29
|
|
|
|
|
30
|
|
|
$this->assertXml2Array($expected, $string, $string); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public function testXml2arrayWithBadLanguage() { |
|
34
|
|
|
$string = <<<XML |
|
35
|
|
|
<?xml version='1.0'?> |
|
36
|
|
|
<document> |
|
37
|
|
|
<node lang='unknown'>something we don't want</node> |
|
38
|
|
|
</document> |
|
39
|
|
|
XML; |
|
40
|
|
|
$expected = array(); |
|
41
|
|
|
|
|
42
|
|
|
$this->assertXml2Array($expected, $string, $string); |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
public function testXml2arraySimple() { |
|
46
|
|
|
$string = <<<XML |
|
47
|
|
|
<?xml version='1.0'?> |
|
48
|
|
|
<document> |
|
49
|
|
|
<title>Forty What?</title> |
|
50
|
|
|
<from>Joe</from> |
|
51
|
|
|
<to>Jane</to> |
|
52
|
|
|
<body> |
|
53
|
|
|
I know that's the answer -- but what's the question? |
|
54
|
|
|
</body> |
|
55
|
|
|
</document> |
|
56
|
|
|
XML; |
|
57
|
|
|
$expected = array( |
|
58
|
|
|
'title' => "Forty What?", |
|
59
|
|
|
'from' => "Joe", |
|
60
|
|
|
'to' => "Jane", |
|
61
|
|
|
'body' => "I know that's the answer -- but what's the question?" |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
$this->assertXml2Array($expected, $string, $string); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testXml2arrayWithAttribute() { |
|
68
|
|
|
$string = <<<XML |
|
69
|
|
|
<?xml version='1.0'?> |
|
70
|
|
|
<document> |
|
71
|
|
|
<attr attributekey="attributevalue">We don't care of this value!!!</attr> |
|
72
|
|
|
<value>value</value> |
|
73
|
|
|
</document> |
|
74
|
|
|
XML; |
|
75
|
|
|
$expected = array( |
|
76
|
|
|
'attr' => array( |
|
77
|
|
|
'attributekey' => "attributevalue"), |
|
78
|
|
|
'value' => "value" |
|
79
|
|
|
); |
|
80
|
|
|
|
|
81
|
|
|
$this->assertXml2Array($expected, $string, $string); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
public function testXml2arrayWithCrossRefDepth1() { |
|
85
|
|
|
$CV = <<<XML |
|
86
|
|
|
<?xml version='1.0'?> |
|
87
|
|
|
<document> |
|
88
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
89
|
|
|
<societies> |
|
90
|
|
|
<society ref="OneSociety"> |
|
91
|
|
|
<name>OneSociety</name> |
|
92
|
|
|
<address>An address</address> |
|
93
|
|
|
<siteurl>http://www.google.com</siteurl> |
|
94
|
|
|
</society> |
|
95
|
|
|
</societies> |
|
96
|
|
|
</document> |
|
97
|
|
|
XML; |
|
98
|
|
|
$string = <<<XML |
|
99
|
|
|
<?xml version='1.0'?> |
|
100
|
|
|
<document> |
|
101
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
102
|
|
|
</document> |
|
103
|
|
|
XML; |
|
104
|
|
|
$expected = array('society' => array( |
|
105
|
|
|
'name' => "OneSociety", |
|
106
|
|
|
'address' => "An address", |
|
107
|
|
|
'siteurl' => "http://www.google.com", |
|
108
|
|
|
'society' => array('ref' => "OneSociety") |
|
109
|
|
|
)); |
|
110
|
|
|
|
|
111
|
|
|
$this->assertXml2Array($expected, $CV, $string); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testXml2arrayWithCrossRefDepth2() { |
|
115
|
|
|
$CV = <<<XML |
|
116
|
|
|
<?xml version='1.0'?> |
|
117
|
|
|
<document> |
|
118
|
|
|
<job crossref="experience[@id='OneExperience']"></job> |
|
119
|
|
|
<experience id="OneExperience"> |
|
120
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
121
|
|
|
<job>My first job</job> |
|
122
|
|
|
</experience> |
|
123
|
|
|
<societies> |
|
124
|
|
|
<society ref="OneSociety"> |
|
125
|
|
|
<name>OneSociety</name> |
|
126
|
|
|
<address>An address</address> |
|
127
|
|
|
<siteurl>http://www.google.com</siteurl> |
|
128
|
|
|
</society> |
|
129
|
|
|
</societies> |
|
130
|
|
|
</document> |
|
131
|
|
|
XML; |
|
132
|
|
|
$string = <<<XML |
|
133
|
|
|
<?xml version='1.0'?> |
|
134
|
|
|
<document> |
|
135
|
|
|
<job crossref="experience[@id='OneExperience']"></job> |
|
136
|
|
|
</document> |
|
137
|
|
|
XML; |
|
138
|
|
|
$expected = array('job' => array( |
|
139
|
|
|
'society' => array( |
|
140
|
|
|
'name' => "OneSociety", |
|
141
|
|
|
'address' => "An address", |
|
142
|
|
|
'siteurl' => "http://www.google.com", |
|
143
|
|
|
'society' => array('ref' => "OneSociety")), |
|
144
|
|
|
'job' => "My first job" |
|
145
|
|
|
)); |
|
146
|
|
|
|
|
147
|
|
|
$this->assertXml2Array($expected, $CV, $string); |
|
148
|
|
|
|
|
149
|
|
|
$string = <<<XML |
|
150
|
|
|
<?xml version='1.0'?> |
|
151
|
|
|
<document> |
|
152
|
|
|
<experience id="OneExperience"> |
|
153
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
154
|
|
|
<job>My first job</job> |
|
155
|
|
|
</experience> |
|
156
|
|
|
</document> |
|
157
|
|
|
XML; |
|
158
|
|
|
$expected = array('OneExperience' => array( |
|
159
|
|
|
'society' => array( |
|
160
|
|
|
'name' => "OneSociety", |
|
161
|
|
|
'address' => "An address", |
|
162
|
|
|
'siteurl' => "http://www.google.com", |
|
163
|
|
|
'society' => array('ref' => "OneSociety")), |
|
164
|
|
|
'job' => "My first job" |
|
165
|
|
|
)); |
|
166
|
|
|
|
|
167
|
|
|
$this->assertXml2Array($expected, $CV, $string); |
|
168
|
|
|
|
|
169
|
|
|
$string = <<<XML |
|
170
|
|
|
<?xml version='1.0'?> |
|
171
|
|
|
<document> |
|
172
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
173
|
|
|
</document> |
|
174
|
|
|
XML; |
|
175
|
|
|
$expected = array('society' => array( |
|
176
|
|
|
'name' => "OneSociety", |
|
177
|
|
|
'address' => "An address", |
|
178
|
|
|
'siteurl' => "http://www.google.com", |
|
179
|
|
|
'society' => array('ref' => "OneSociety")) |
|
180
|
|
|
); |
|
181
|
|
|
|
|
182
|
|
|
$this->assertXml2Array($expected, $CV, $string); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
public function testXml2arrayWithCrossRef() { |
|
186
|
|
|
$CV = <<<XML |
|
187
|
|
|
<?xml version='1.0'?> |
|
188
|
|
|
<document> |
|
189
|
|
|
<job crossref="experience[@id='OneExperience']"></job> |
|
190
|
|
|
<experience id="OneExperience"> |
|
191
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
192
|
|
|
<job>My first job</job> |
|
193
|
|
|
</experience> |
|
194
|
|
|
<societies> |
|
195
|
|
|
<society ref="OneSociety"> |
|
196
|
|
|
<name>OneSociety</name> |
|
197
|
|
|
<address>An address</address> |
|
198
|
|
|
<siteurl>http://www.google.com</siteurl> |
|
199
|
|
|
</society> |
|
200
|
|
|
</societies> |
|
201
|
|
|
</document> |
|
202
|
|
|
XML; |
|
203
|
|
|
$string = <<<XML |
|
204
|
|
|
<?xml version='1.0'?> |
|
205
|
|
|
<document> |
|
206
|
|
|
<job crossref="experience[@id='OneExperience']"></job> |
|
207
|
|
|
</document> |
|
208
|
|
|
XML; |
|
209
|
|
|
$expected = array('job' => array( |
|
210
|
|
|
'society' => array( |
|
211
|
|
|
'name' => "OneSociety", |
|
212
|
|
|
'address' => "An address", |
|
213
|
|
|
'siteurl' => "http://www.google.com", |
|
214
|
|
|
'society' => array('ref' => "OneSociety")), |
|
215
|
|
|
'job' => "My first job" |
|
216
|
|
|
)); |
|
217
|
|
|
|
|
218
|
|
|
$this->assertXml2Array($expected, $CV, $string); |
|
219
|
|
|
} |
|
220
|
|
|
|
|
221
|
|
|
public function testXml2arrayWithCVCrossRef() { |
|
222
|
|
|
$CV = <<<XML |
|
223
|
|
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> |
|
224
|
|
|
<root> |
|
225
|
|
|
<langs> |
|
226
|
|
|
<lang id="en">English</lang> |
|
227
|
|
|
<lang id="fr">Français</lang> |
|
228
|
|
|
</langs> |
|
229
|
|
|
<curriculumVitae> |
|
230
|
|
|
<lookingFor> |
|
231
|
|
|
<experience crossref="curriculumVitae/experiences/items/experience[@id='SecondJob']"></experience> |
|
232
|
|
|
<presentation lang="en">A good presentation.</presentation> |
|
233
|
|
|
<presentation lang="fr">Une bonne présentation.</presentation> |
|
234
|
|
|
</lookingFor> |
|
235
|
|
|
<experiences anchor="experiences"> |
|
236
|
|
|
<anchorTitle lang="en">Experiences</anchorTitle> |
|
237
|
|
|
<anchorTitle lang="fr">Expériences Professionnelles</anchorTitle> |
|
238
|
|
|
<items> |
|
239
|
|
|
<experience id="SecondJob"> |
|
240
|
|
|
<date lang="en">Apr 2011 - Present</date> |
|
241
|
|
|
<date lang="fr">Avr. 2011 - Aujourd'hui</date> |
|
242
|
|
|
<job lang="en">Second Job</job> |
|
243
|
|
|
<job lang="fr">Deuxième Job</job> |
|
244
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
245
|
|
|
<missions lang="en"> |
|
246
|
|
|
<item>A item.</item> |
|
247
|
|
|
</missions> |
|
248
|
|
|
<missions lang="fr"> |
|
249
|
|
|
<item>Un item.</item> |
|
250
|
|
|
</missions> |
|
251
|
|
|
</experience> |
|
252
|
|
|
<experience id="FirstJob"> |
|
253
|
|
|
<date lang="en">Nov 2009 - Apr 2011</date> |
|
254
|
|
|
<date lang="fr">Nov. 2009 - Avr. 2011</date> |
|
255
|
|
|
<job lang="en">First Job</job> |
|
256
|
|
|
<job lang="fr">Premier Job</job> |
|
257
|
|
|
<society crossref="societies/society[@ref='OneSociety']"></society> |
|
258
|
|
|
<missions lang="en"> |
|
259
|
|
|
<item>A item.</item> |
|
260
|
|
|
</missions> |
|
261
|
|
|
<missions lang="fr"> |
|
262
|
|
|
<item>Un item.</item> |
|
263
|
|
|
</missions> |
|
264
|
|
|
</experience> |
|
265
|
|
|
</items> |
|
266
|
|
|
</experiences> |
|
267
|
|
|
</curriculumVitae> |
|
268
|
|
|
<societies> |
|
269
|
|
|
<society ref="OneSociety"> |
|
270
|
|
|
<name>OneSociety</name> |
|
271
|
|
|
<address>address</address> |
|
272
|
|
|
<siteurl>http://www.google.com</siteurl> |
|
273
|
|
|
</society> |
|
274
|
|
|
</societies> |
|
275
|
|
|
</root> |
|
276
|
|
|
XML; |
|
277
|
|
|
$expected = array( |
|
278
|
|
|
'langs' => array( |
|
279
|
|
|
'en' => "English", |
|
280
|
|
|
'fr' => "Français"), |
|
281
|
|
|
'curriculumVitae' => array( |
|
282
|
|
|
'lookingFor' => array( |
|
283
|
|
|
'experience' => array( |
|
284
|
|
|
'job' => "Second Job", |
|
285
|
|
|
'date' => "Apr 2011 - Present", |
|
286
|
|
|
'society' => array( |
|
287
|
|
|
'name' => "OneSociety", |
|
288
|
|
|
'address' => "address", |
|
289
|
|
|
'siteurl' => "http://www.google.com", |
|
290
|
|
|
'society' => array('ref' => "OneSociety")), |
|
291
|
|
|
'missions' => array( |
|
292
|
|
|
'item' => array("A item."))), |
|
293
|
|
|
'presentation' => "A good presentation."), |
|
294
|
|
|
'experiences' => array( |
|
295
|
|
|
'anchorTitle' => "Experiences", |
|
296
|
|
|
'items' => array( |
|
297
|
|
|
'SecondJob' => array( |
|
298
|
|
|
'job' => "Second Job", |
|
299
|
|
|
'date' => "Apr 2011 - Present", |
|
300
|
|
|
'society' => array( |
|
301
|
|
|
'name' => "OneSociety", |
|
302
|
|
|
'address' => "address", |
|
303
|
|
|
'siteurl' => "http://www.google.com", |
|
304
|
|
|
'society' => array('ref' => "OneSociety")), |
|
305
|
|
|
'missions' => array( |
|
306
|
|
|
'item' => array("A item."))), |
|
307
|
|
|
'FirstJob' => array( |
|
308
|
|
|
'job' => "First Job", |
|
309
|
|
|
'date' => "Nov 2009 - Apr 2011", |
|
310
|
|
|
'society' => array( |
|
311
|
|
|
'name' => "OneSociety", |
|
312
|
|
|
'address' => "address", |
|
313
|
|
|
'siteurl' => "http://www.google.com", |
|
314
|
|
|
'society' => array('ref' => "OneSociety")), |
|
315
|
|
|
'missions' => array( |
|
316
|
|
|
'item' => array("A item.")))), |
|
317
|
|
|
'anchor' => "experiences")), |
|
318
|
|
|
'societies' => array( |
|
319
|
|
|
'society' => array( |
|
320
|
|
|
'name' => "OneSociety", |
|
321
|
|
|
'address' => "address", |
|
322
|
|
|
'siteurl' => "http://www.google.com", |
|
323
|
|
|
'ref' => "OneSociety")) |
|
324
|
|
|
); |
|
325
|
|
|
|
|
326
|
|
|
$this->assertXml2Array($expected, $CV, $CV); |
|
327
|
|
|
} |
|
328
|
|
|
|
|
329
|
|
|
private function assertXml2Array($expected, $CV, $XML) { |
|
330
|
|
|
$this->Xml2arrayFunctions = new Xml2arrayFunctions(simplexml_load_string($CV)); |
|
331
|
|
|
$result = $this->Xml2arrayFunctions->xml2array(simplexml_load_string($XML)); |
|
332
|
|
|
|
|
333
|
|
|
$this->assertEquals($expected, $result); |
|
334
|
|
|
} |
|
335
|
|
|
} |
|
336
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.