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