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\Controller; |
13
|
|
|
|
14
|
|
|
use FabienCrassat\CurriculumVitaeBundle\Entity\CurriculumVitae; |
15
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
16
|
|
|
use Symfony\Component\Serializer\Serializer; |
17
|
|
|
use Symfony\Component\Serializer\Encoder\XmlEncoder; |
18
|
|
|
use Symfony\Component\Serializer\Normalizer\GetSetMethodNormalizer; |
19
|
|
|
|
20
|
|
|
class DefaultControllerTest extends WebTestCase |
21
|
|
|
{ |
22
|
|
|
public function testIndex() |
23
|
|
|
{ |
24
|
|
|
$client = static::createClient(); |
25
|
|
|
$client->request('GET', '/'); |
26
|
|
|
$this->assertEquals(301, $client->getResponse()->getStatusCode()); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testDisplay() |
30
|
|
|
{ |
31
|
|
|
$client = static::createClient(); |
32
|
|
|
$crawler = $client->request('GET', '/example'); |
33
|
|
|
$this->assertGreaterThan(0, $crawler->filter('html:contains("First Name Last Name")')->count()); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @expectedException(Symfony\Component\HttpKernel\Exception\NotFoundHttpException) |
38
|
|
|
*/ |
39
|
|
|
public function testIfAnExportPDFServiceIsNotPresent() |
40
|
|
|
{ |
41
|
|
|
$client = static::createClient(); |
42
|
|
|
$client->request('GET', '/example/en/pdf'); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @expectedException(Symfony\Component\HttpKernel\Exception\NotFoundHttpException) |
47
|
|
|
*/ |
48
|
|
|
public function testCVDoesNotExistIndex() |
49
|
|
|
{ |
50
|
|
|
$client = static::createClient(); |
51
|
|
|
$client->request('GET', '/nofile'); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @expectedException(Symfony\Component\HttpKernel\Exception\NotFoundHttpException) |
56
|
|
|
*/ |
57
|
|
|
public function testBadLanguage() |
58
|
|
|
{ |
59
|
|
|
$client = static::createClient(); |
60
|
|
|
$client->request('GET', '/example/XX'); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
private $curriculumVitae; |
64
|
|
|
private $client; |
65
|
|
|
|
66
|
|
|
public function testOutputHtmlXmlComparaison() |
67
|
|
|
{ |
68
|
|
|
$this->client = static::createClient(); |
69
|
|
|
|
70
|
|
|
$langs = array('en', 'fr'); |
71
|
|
|
foreach ($langs as $value) { |
72
|
|
|
$this->outputHtmlXmlComparaison($value); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testOutputJSONXmlComparaison() |
77
|
|
|
{ |
78
|
|
|
$this->client = static::createClient(); |
79
|
|
|
|
80
|
|
|
$langs = array('en', 'fr'); |
81
|
|
|
foreach ($langs as $value) { |
82
|
|
|
$this->client->request('GET', '/example/'.$value.'.json'); |
83
|
|
|
|
84
|
|
|
$response = $this->client->getResponse(); |
85
|
|
|
$data = json_decode($response->getContent(), TRUE); |
86
|
|
|
|
87
|
|
|
// Read the Curriculum Vitae |
88
|
|
|
$pathToFile = __DIR__.'/../../Resources/data/example.xml'; |
89
|
|
|
$this->curriculumVitae = new CurriculumVitae($pathToFile, $value); |
90
|
|
|
|
91
|
|
|
$cvXml = array( |
92
|
|
|
'identity' => $this->curriculumVitae->getIdentity(), |
93
|
|
|
'followMe' => $this->curriculumVitae->getFollowMe(), |
94
|
|
|
'lookingFor' => $this->curriculumVitae->getLookingFor(), |
95
|
|
|
'experiences' => $this->curriculumVitae->getExperiences(), |
96
|
|
|
'skills' => $this->curriculumVitae->getSkills(), |
97
|
|
|
'educations' => $this->curriculumVitae->getEducations(), |
98
|
|
|
'languageSkills' => $this->curriculumVitae->getLanguageSkills(), |
99
|
|
|
'miscellaneous' => $this->curriculumVitae->getMiscellaneous() |
100
|
|
|
); |
101
|
|
|
|
102
|
|
|
$this->assertSame($cvXml, $data); |
103
|
|
|
} |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
public function testOutputXmlXmlComparaison() |
107
|
|
|
{ |
108
|
|
|
$this->client = static::createClient(); |
109
|
|
|
|
110
|
|
|
$langs = array('en', 'fr'); |
111
|
|
|
foreach ($langs as $value) { |
112
|
|
|
$this->client->request('GET', '/example/'.$value.'.xml'); |
113
|
|
|
$response = $this->client->getResponse(); |
114
|
|
|
$response->headers->set('Content-Type', 'application/xml'); |
115
|
|
|
$data = $response->getContent(); |
116
|
|
|
|
117
|
|
|
// Read the Curriculum Vitae |
118
|
|
|
$pathToFile = __DIR__.'/../../Resources/data/example.xml'; |
119
|
|
|
$this->curriculumVitae = new CurriculumVitae($pathToFile, $value); |
120
|
|
|
|
121
|
|
|
$cvXml = array( |
122
|
|
|
'identity' => $this->curriculumVitae->getIdentity(), |
123
|
|
|
'followMe' => $this->curriculumVitae->getFollowMe(), |
124
|
|
|
'lookingFor' => $this->curriculumVitae->getLookingFor(), |
125
|
|
|
'experiences' => $this->curriculumVitae->getExperiences(), |
126
|
|
|
'skills' => $this->curriculumVitae->getSkills(), |
127
|
|
|
'educations' => $this->curriculumVitae->getEducations(), |
128
|
|
|
'languageSkills' => $this->curriculumVitae->getLanguageSkills(), |
129
|
|
|
'miscellaneous' => $this->curriculumVitae->getMiscellaneous() |
130
|
|
|
); |
131
|
|
|
//initialisation du serializer |
132
|
|
|
$encoders = array(new XmlEncoder('CurriculumVitae')); |
133
|
|
|
$normalizers = array(new GetSetMethodNormalizer()); |
134
|
|
|
$serializer = new Serializer($normalizers, $encoders); |
135
|
|
|
|
136
|
|
|
$this->assertSame($serializer->serialize($cvXml, 'xml'), $data); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
public function testOutputFollowMeLink() |
141
|
|
|
{ |
142
|
|
|
$this->client = static::createClient(); |
143
|
|
|
|
144
|
|
|
$langs = array('en', 'fr'); |
145
|
|
|
foreach ($langs as $lang) { |
146
|
|
|
$crawler = $this->client->request('GET', '/example/'.$lang); |
147
|
|
|
|
148
|
|
|
// Read the Curriculum Vitae |
149
|
|
|
$pathToFile = __DIR__.'/../../Resources/data/example.xml'; |
150
|
|
|
$this->curriculumVitae = new CurriculumVitae($pathToFile, $lang); |
151
|
|
|
|
152
|
|
|
$cvXml = array('followMe' => $this->curriculumVitae->getFollowMe()); |
153
|
|
|
|
154
|
|
|
$testValue = $this->arrayValuesRecursive($cvXml); |
155
|
|
|
foreach ($testValue as $value) { |
156
|
|
|
$alt = $crawler->filter('img[alt="'.$value.'"]')->count(); |
157
|
|
|
$alt += $crawler->filter('img[title="'.$value.'"]')->count(); |
158
|
|
|
$alt += $crawler->filter('img[src="/'.$value.'"]')->count(); |
159
|
|
|
$alt += $crawler->filter('a[href="'.$value.'"]')->count(); |
160
|
|
|
|
161
|
|
|
$this->assertGreaterThan(0, $alt, |
162
|
|
|
'The value '.$value.' is not diplay for language '.$lang |
163
|
|
|
); |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
private function outputHtmlXmlComparaison($lang = 'en') |
169
|
|
|
{ |
170
|
|
|
$crawler = $this->client->request('GET', '/example/'.$lang); |
171
|
|
|
|
172
|
|
|
// Read the Curriculum Vitae |
173
|
|
|
$pathToFile = __DIR__.'/../../Resources/data/example.xml'; |
174
|
|
|
$this->curriculumVitae = new CurriculumVitae($pathToFile, $lang); |
175
|
|
|
|
176
|
|
|
$cvXml = array( |
177
|
|
|
'identity' => $this->curriculumVitae->getIdentity(), |
178
|
|
|
'lookingFor' => $this->curriculumVitae->getLookingFor(), |
179
|
|
|
'experiences' => $this->curriculumVitae->getExperiences(), |
180
|
|
|
'skills' => $this->curriculumVitae->getSkills(), |
181
|
|
|
'educations' => $this->curriculumVitae->getEducations(), |
182
|
|
|
'languageSkills' => $this->curriculumVitae->getLanguageSkills(), |
183
|
|
|
'miscellaneous' => $this->curriculumVitae->getMiscellaneous() |
184
|
|
|
); |
185
|
|
|
// Remove all no visible elements |
186
|
|
|
$cvXml = $this->removeNoVisibleElementDependingOnLanguages($lang, $cvXml); |
187
|
|
|
$cvXml = $this->removeNoVisibleElementForAllLanguages($cvXml); |
188
|
|
|
|
189
|
|
|
$testValue = $this->arrayValuesRecursive($cvXml); |
190
|
|
|
foreach ($testValue as $value) { |
191
|
|
|
$this->assertGreaterThan(0, |
192
|
|
|
$crawler->filter('html:contains("'.$value.'")')->count(), |
193
|
|
|
'The value '.$value.' is not diplay for language '.$lang |
194
|
|
|
); |
195
|
|
|
} |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
/** |
199
|
|
|
* @param string $lang |
200
|
|
|
* @param array $cvXml |
201
|
|
|
* |
202
|
|
|
* @return array |
203
|
|
|
*/ |
204
|
|
|
private function removeNoVisibleElementDependingOnLanguages($lang, $cvXml) |
205
|
|
|
{ |
206
|
|
|
switch ($lang) { |
207
|
|
|
case 'en': |
208
|
|
|
unset($cvXml['identity']['myself']['birthday']); |
209
|
|
|
break; |
210
|
|
|
default: |
211
|
|
|
// code... |
212
|
|
|
break; |
213
|
|
|
} |
214
|
|
|
return $cvXml; |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
/** |
218
|
|
|
* @param array $cvXml |
219
|
|
|
* |
220
|
|
|
* @return array |
221
|
|
|
*/ |
222
|
|
|
private function removeNoVisibleElementForAllLanguages($cvXml) |
223
|
|
|
{ |
224
|
|
|
unset($cvXml['identity']['myself']['picture']); |
225
|
|
|
unset($cvXml['identity']['address']['street']); |
226
|
|
|
unset($cvXml['identity']['address']['postalcode']); |
227
|
|
|
unset($cvXml['identity']['address']['googlemap']); |
228
|
|
|
unset($cvXml['identity']['contact']['mobile']); |
229
|
|
|
unset($cvXml['experiences']['FirstExperience']['society']['society']['ref']); |
230
|
|
|
unset($cvXml['experiences']['FirstExperience']['society']['siteurl']); |
231
|
|
|
unset($cvXml['experiences']['SecondExperience']['collapse']); |
232
|
|
|
unset($cvXml['experiences']['SecondExperience']['society']['society']['ref']); |
233
|
|
|
unset($cvXml['experiences']['SecondExperience']['society']['siteurl']); |
234
|
|
|
unset($cvXml['experiences']['ThirdExperience']['society']['society']['ref']); |
235
|
|
|
unset($cvXml['experiences']['FourthExperience']['collapse']); |
236
|
|
|
unset($cvXml['skills']['Functional']['lines']['success']['percentage']); |
237
|
|
|
unset($cvXml['skills']['Functional']['lines']['success']['class']); |
238
|
|
|
unset($cvXml['skills']['Functional']['lines']['success']['striped']); |
239
|
|
|
unset($cvXml['skills']['Functional']['lines']['otherSucess']['percentage']); |
240
|
|
|
unset($cvXml['skills']['Functional']['lines']['otherSucess']['class']); |
241
|
|
|
unset($cvXml['skills']['Functional']['lines']['info']['percentage']); |
242
|
|
|
unset($cvXml['skills']['Functional']['lines']['info']['class']); |
243
|
|
|
unset($cvXml['skills']['Functional']['lines']['info']['striped']); |
244
|
|
|
unset($cvXml['skills']['Functional']['lines']['warning']['percentage']); |
245
|
|
|
unset($cvXml['skills']['Functional']['lines']['warning']['class']); |
246
|
|
|
unset($cvXml['skills']['Functional']['lines']['danger']['percentage']); |
247
|
|
|
unset($cvXml['skills']['Functional']['lines']['danger']['class']); |
248
|
|
|
unset($cvXml['skills']['Functional']['lines']['noClass']['percentage']); |
249
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['success']['percentage']); |
250
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['success']['class']); |
251
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['success']['striped']); |
252
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['info']['percentage']); |
253
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['info']['class']); |
254
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['info']['striped']); |
255
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['warning']['percentage']); |
256
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['warning']['class']); |
257
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['warning']['striped']); |
258
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['danger']['percentage']); |
259
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['danger']['class']); |
260
|
|
|
unset($cvXml['skills']['OtherSkill']['lines']['danger']['striped']); |
261
|
|
|
unset($cvXml['educations']['HighSchool']['collapse']); |
262
|
|
|
unset($cvXml['educations']['FirstSchool']['collapse']); |
263
|
|
|
unset($cvXml['languageSkills']['French']['icon']); |
264
|
|
|
unset($cvXml['languageSkills']['English']['icon']); |
265
|
|
|
|
266
|
|
|
return $cvXml; |
267
|
|
|
} |
268
|
|
|
|
269
|
|
|
private function arrayValuesRecursive($array) |
270
|
|
|
{ |
271
|
|
|
$return = array(); |
272
|
|
|
foreach($array as $value) { |
273
|
|
|
$return = $this->arrayValuesMerge($return, $value); |
274
|
|
|
} |
275
|
|
|
return $return; |
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
private function arrayValuesMerge($return, $value) |
279
|
|
|
{ |
280
|
|
|
if(is_array($value)) { |
281
|
|
|
return array_merge($return, $this->arrayValuesRecursive($value)); |
282
|
|
|
} |
283
|
|
|
|
284
|
|
|
return array_merge($return, array($value)); |
285
|
|
|
} |
286
|
|
|
} |
287
|
|
|
|