Completed
Pull Request — master (#11)
by Fabien
05:31 queued 02:40
created

DefaultControllerTest::testDisplay()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
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 testSnappyPDFisNotPresent()
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 $ReadCVXml;
0 ignored issues
show
Coding Style introduced by
$ReadCVXml does not seem to conform to the naming convention (^[a-z][a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
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->ReadCVXml = new CurriculumVitae($pathToFile, $value);
90
91
            $cvXml = array(
92
                'identity'          => $this->ReadCVXml->getIdentity(),
93
                'followMe'          => $this->ReadCVXml->getFollowMe(),
94
                'lookingFor'        => $this->ReadCVXml->getLookingFor(),
95
                'experiences'       => $this->ReadCVXml->getExperiences(),
96
                'skills'            => $this->ReadCVXml->getSkills(),
97
                'educations'        => $this->ReadCVXml->getEducations(),
98
                'languageSkills'    => $this->ReadCVXml->getLanguageSkills(),
99
                'miscellaneous'     => $this->ReadCVXml->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->ReadCVXml = new CurriculumVitae($pathToFile, $value);
120
121
            $cvXml = array(
122
                'identity'          => $this->ReadCVXml->getIdentity(),
123
                'followMe'          => $this->ReadCVXml->getFollowMe(),
124
                'lookingFor'        => $this->ReadCVXml->getLookingFor(),
125
                'experiences'       => $this->ReadCVXml->getExperiences(),
126
                'skills'            => $this->ReadCVXml->getSkills(),
127
                'educations'        => $this->ReadCVXml->getEducations(),
128
                'languageSkills'    => $this->ReadCVXml->getLanguageSkills(),
129
                'miscellaneous'     => $this->ReadCVXml->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->ReadCVXml = new CurriculumVitae($pathToFile, $lang);
151
152
            $cvXml = array('followMe' => $this->ReadCVXml->getFollowMe());
153
154
            $testValue = $this->array_values_recursive($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')
0 ignored issues
show
Coding Style introduced by
function OutputHtmlXmlComparaison() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
169
    {
170
        $crawler = $this->client->request('GET', '/example/'.$lang);
171
172
        // Read the Curriculum Vitae
173
        $pathToFile      = __DIR__.'/../../Resources/data/example.xml';
174
        $this->ReadCVXml = new CurriculumVitae($pathToFile, $lang);
175
176
        $cvXml = array(
177
                'identity'          => $this->ReadCVXml->getIdentity(),
178
                'lookingFor'        => $this->ReadCVXml->getLookingFor(),
179
                'experiences'       => $this->ReadCVXml->getExperiences(),
180
                'skills'            => $this->ReadCVXml->getSkills(),
181
                'educations'        => $this->ReadCVXml->getEducations(),
182
                'languageSkills'    => $this->ReadCVXml->getLanguageSkills(),
183
                'miscellaneous'     => $this->ReadCVXml->getMiscellaneous()
184
        );
185
        // Remove all no visible elements
186
        switch ($lang) {
187
            case 'en':
188
                unset($cvXml['identity']['myself']['birthday']);
189
                break;
190
            default:
191
                // code...
192
                break;
193
        }
194
        unset($cvXml['identity']['myself']['picture']);
195
        unset($cvXml['identity']['address']['street']);
196
        unset($cvXml['identity']['address']['postalcode']);
197
        unset($cvXml['identity']['address']['googlemap']);
198
        unset($cvXml['identity']['contact']['mobile']);
199
        unset($cvXml['experiences']['FirstExperience']['society']['society']['ref']);
200
        unset($cvXml['experiences']['FirstExperience']['society']['siteurl']);
201
        unset($cvXml['experiences']['SecondExperience']['collapse']);
202
        unset($cvXml['experiences']['SecondExperience']['society']['society']['ref']);
203
        unset($cvXml['experiences']['SecondExperience']['society']['siteurl']);
204
        unset($cvXml['experiences']['ThirdExperience']['society']['society']['ref']);
205
        unset($cvXml['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
        $testValue = $this->array_values_recursive($cvXml);
237
        foreach ($testValue as $value) {
238
            $this->assertGreaterThan(0,
239
                $crawler->filter('html:contains("'.$value.'")')->count(),
240
                'The value '.$value.' is not diplay for language '.$lang
241
            );
242
        }
243
    }
244
245
    private function array_values_recursive($array)
0 ignored issues
show
Coding Style introduced by
function array_values_recursive() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
246
    {
247
        $return = array();
248
        foreach($array as $value) {
249
            $return = $this->array_values_merge($return, $value);
250
        }
251
        return $return;
252
    }
253
254
    private function array_values_merge($return, $value)
0 ignored issues
show
Coding Style introduced by
function array_values_merge() does not seem to conform to the naming convention (^(?:[a-z]|__)[a-zA-Z0-9]*$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
255
    {
256
        if(is_array($value)) {
257
            return array_merge($return, $this->array_values_recursive($value));
258
        }
259
260
        return array_merge($return, array($value));
261
    }
262
}
263