TaxonomysControllerTest.php 33.7 KB
Newer Older
1
<?php
2
3

namespace App\Test\TestCase\Controller\Api\V1;
4
5
6
7
8
9

use App\Controller\TaxonomysController;

/**
 * App\Controller\TaxonomysController Test Case
 */
10
class TaxonomysControllerTest extends ApiIntegrationTestCase
11
12
13
14
15
16
17
18
19
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'app.taxonomys',
20
        'app.taxonomys_softwares',
21
22
23
24
25
26
27
28
29
30
31
        'app.softwares',
        'app.licenses',
        'app.licence_types',
        'app.relationships_softwares_users',
        'app.users',
        'app.user_types',
        'app.reviews',
        'app.relationships',
        'app.relationship_types',
        'app.relationships_softwares',
        'app.relationships_users',
32
33
34
35
36
   //     'app.usedsoftwares',
   //     'app.backedsoftwares',
   //     'app.createdsoftwares',
   //     'app.contributionssoftwares',
   //     'app.providerforsoftwares',
37
38
39
40
        'app.screenshots',
        'app.softwares_statistics',
        'app.tags',
        'app.softwares_tags',
41
42
43
44
45
46
47
    //    'app.userssoftwares',
    //    'app.backerssoftwares',
    //    'app.creatorssoftwares',
    //    'app.contributorssoftwares',
    //    'app.providerssoftwares',
    //    'app.workswellsoftwares',
    //    'app.alternativeto'
48
49
    ];

50

51
52
53
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Public actions /////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
54

55
56
57
58

// Mapping method
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

59
    /**
60
     * Mapping method : main unit tests
61
     *
62
63
64
65
66
     *      URL: /fr/cartographie
     *           /en/mapping/
     *
     * @todo WIP
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
67
     *
68
     * @group public
69
     * @group taxonomy
70
71
     * @group taxonomy_public
     * @group taxonomy_method_mapping
72
73
74
75
     * @return void
     */
    public function testMapping()
    {
76
77
78
79
        $url = '/fr/cartographie/';
        $title = "<title>Cartographie des logiciels métiers pour les collectivités</title>";

        // Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
80
        $this->setAdminSessionOfPersonType();
81
82
83
84
85
86
87
88
        $r = $this->checkUrlOk($url, ['html']);
        $html = $r['html']['data'];
        $this->assertContains('<html lang="fr">', $html);
        $this->assertContains("$title", $html);

        // Connected user --> to be deleted when development is complete.
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized($url, ['html']);
89

90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
        // Anonymous user --> to be deleted when development is complete.
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin($url, ['html'], 'fr');
    }

    /**
     * Mapping method
     * Check that redirects work when the URL is slightly different
     * - slash missing at the end of the URL
     * - the language prefix is missing at the beginning of the URL
     * - the user has changed the language prefix in the URL
     *
     *      URL: /fr/cartographie
     *           /en/mapping/
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mapping
     * @return void
     */
    public function testMappingCheckRedirects()
    {
116
        // Admin user
117
        // --> to be replaced by an anonymous user and a logged-in user when development is complete.
118
        $this->setAdminSessionOfPersonType();
119

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
        // French user:
        $expectedUrl = '/fr/cartographie/';
        $testeddUrl = '/fr/cartographie'; // slash missing at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/fr/mapping/'; // the user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        // English user
        $expectedUrl = '/en/mapping/';
        $testeddUrl = '/en/mapping'; // slash missing at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/en/cartographie/'; // the user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        //  English user: language prefix is missing at the beginning of URL
        $expectedUrl = '/en/mapping/';
        $this->get("/en/"); // force user language to english
        $testeddUrl = '/mapping/'; //  the language prefix is missing at the beginning of URLs
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/cartographie/';
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        //  French user: language prefix is missing at the beginning of URL
        $expectedUrl = '/fr/cartographie/';
        $this->get("/fr/"); // force user language to french
        $testeddUrl = '/mapping'; //  the language prefix is missing at the beginning of URLs
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/cartographie'; //  the language prefix is missing at the beginning of URLs
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
    }

    /**
     * Mapping method with URL prefix /api/v1/
     * - HTML format redirects to the official URL
     * - JSON format returns a 404 "not found" error.
     *
     *      URL: /api/v1/taxonomys/mapping
     *      URL: /api/v1/taxonomys/mapping.json
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mapping
     * @return void
     */
    public function testMappingCheckApiPrefixInUrl()
    {
        $url = '/api/v1/taxonomys/mapping';

        // Admin user ---> to be replaced by an anonymous and/or connected user when development is complete.
173
        $this->setAdminSessionOfPersonType();
174
175

        // JSON format
176
177
        $this->checkUrlNotFound($url, ['json']);

178
179
180
181
182
183
        // HTML format
        $expectedUrl = '/fr/cartographie/';
        $this->get("/fr/"); // force user language to french
        $this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);

        // Connected user --> to be deleted when development is complete.
184
185
186
187
        $this->setConnectedUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlNotAuthorized($url, ['html']);

188
        // Anonymous user --> to be deleted when development is complete.
189
190
191
192
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
    }
193
194


195
196
197
// MappingPrimaryLevel method
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

198
    /**
199
200
201
202
     * MappingPrimaryLevel method : main unit tests
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>
     *           /en/mapping/<slugPrimaryLevel>
203
     *
204
205
206
     *      ex:  /en/mapping/business     /fr/cartographie/metiers
     *           /en/mapping/activities   /fr/cartographie/activites
     *           /en/mapping/generics     /fr/cartographie/generiques
207
     *
208
209
210
211
     * @todo WIP
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group public
212
     * @group taxonomy
213
214
     * @group taxonomy_public
     * @group taxonomy_method_mappingPrimaryLevel
215
     * @return void
216
     */
217
    public function testPrimaryLevel()
218
    {
219
220
221
222
        $url = '/fr/cartographie/metiers/';
        $htmlTitle = "<title>Métiers";

        // Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
223
        $this->setAdminSessionOfPersonType();
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
        $r = $this->checkUrlOk($url, ['html']);
        $html = $r['html']['data'];
        $this->assertContains('<html lang="fr">', $html);
        $this->assertContains("$htmlTitle", $html);

        // Connected user --> to be deleted when development is complete.
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized($url, ['html']);

        // Anonymous user --> to be deleted when development is complete.
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin($url, ['html'], 'fr');
    }

    /**
     * MappingPrimaryLevel method
     * Check that redirects work when the URL is slightly different
     * - slash missing at the end of the URL
     * - the language prefix is missing at the beginning of the URL
     * - the user has changed the language prefix in the URL ----> redirect to '/en/mapping/' or '/fr/cartographie/'
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>
     *           /en/mapping/<slugPrimaryLevel>
     *
     *      ex:  /en/mapping/business     /fr/cartographie/metiers
     *           /en/mapping/activities   /fr/cartographie/activites
     *           /en/mapping/generics     /fr/cartographie/generiques
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingPrimaryLevel
     * @return void
     */
    public function testPrimaryLevelCheckRedirects()
    {
        // Admin user
        // --> to be replaced by an anonymous user and a logged-in user when development is complete.
265
        $this->setAdminSessionOfPersonType();
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290

        // French user:
        $expectedUrl = '/fr/cartographie/metiers/';
        $testeddUrl = '/fr/cartographie/metiers'; // slash missing at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/en/cartographie/metiers/'; // the user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, '/en/mapping/', ['html'], 301);

        //  French user: language prefix is missing at the beginning of URL
        $this->get("/fr/"); // force user language to french
        $testeddUrl = '/cartographie/metiers/'; //  the language prefix is missing at the beginning of URLs
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        // English user
        $expectedUrl = '/en/mapping/business/';
        $testeddUrl = '/en/mapping/business'; // slash missing at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/fr/mapping/business/'; // the user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, '/fr/cartographie/', ['html'], 301);

        //  English user: language prefix is missing at the beginning of URL
        $this->get("/en/"); // force user language to english
        $testeddUrl = '/mapping/business/'; //  the language prefix is missing at the beginning of URLs
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
    }
291

292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317


    /**
     * MappingPrimaryLevel method
     *
     * Check that if the first level requested does not exist,
     * a redirection is made to '/en/mapping/' or '/fr/cartographie/'
     *
     *      URL: /fr/cartographie/<slugPrimaryLevelNotFound>
     *           /en/mapping/<slugPrimaryLevelNotFound>
     *
     *      ex:  /en/mapping/business     /fr/cartographie/metiers
     *           /en/mapping/activities   /fr/cartographie/activites
     *           /en/mapping/generics     /fr/cartographie/generiques
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingPrimaryLevel
     * @return void
     */
    public function testPrimaryLevelNotFound()
    {
318
        // Admin user
319
        // --> to be replaced by an anonymous user and a logged-in user when development is complete.
320
        $this->setAdminSessionOfPersonType();
321

322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
        // French user:
        $expectedUrl = '/fr/cartographie/';
        $testeddUrl = '/fr/cartographie/PremierNiveauInconnu';
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        // English user
        $expectedUrl = '/en/mapping/';
        $testeddUrl = '/en/mapping/notFoundPrimaryLevel';
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
    }

    /**
     * MappingPrimaryLevel method with URL prefix /api/v1/
     * - HTML format redirects to the official URL
     * - JSON format returns a 404 "not found" error.
     *
     *      URL: /api/v1/taxonomys/mappingPrimaryLevel/<id>       ---> redirect to /en/mapping/ or /fr/cartographie/
     *      URL: /api/v1/taxonomys/mappingPrimaryLevel/<id>.json  ---> disable: 404 not found
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group taxonomy
     * @group taxonomy_notAllowed
     * @group taxonomy_method_mappingPrimaryLevel
     * @return void
     */
    public function testPrimaryLevelCheckApiPrefixInUrl()
    {
        $url = '/api/v1/taxonomys/mappingPrimaryLevel/1';

        // Admin user ---> to be replaced by an anonymous and/or connected user when development is complete.
353
        $this->setAdminSessionOfPersonType();
354
355

        // JSON format
356
357
        $this->checkUrlNotFound($url, ['json']);

358
359
360
361
362
363
        // HTML format
        $expectedUrl = '/fr/cartographie/';
        $this->get("/fr/"); // force user language to french
        $this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);

        // Connected user --> to be deleted when development is complete.
364
365
366
367
        $this->setConnectedUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlNotAuthorized($url, ['html']);

368
        // Anonymous user --> to be deleted when development is complete.
369
370
371
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
372
373
374
    }


375
376
377
// MappingTaxon method
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

378
    /**
379
     * Test mappingTaxon method : a taxon has a software with users (one or more)
380
     *
381
382
     *      URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *           /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
383
     *
384
385
386
387
388
389
390
     *      ex:  /fr/cartographie/metiers/sante-social/14      /en/mapping/business/healthcare-social/14
     *           /fr/cartographie/generiques/bureautique/20    /en/mapping/generics/office-automation/20
     *
     * @todo WIP
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group public
391
     * @group taxonomy
392
393
     * @group taxonomy_public
     * @group taxonomy_method_mappingTaxon
394
     * @return void
395
     */
396
    public function testMappingTaxonShouldHaveSoftwareWithUsers()
397
    {
398
399
400
401
        $idTaxon = 3;
        $idSoftware = 1;
        $url = "/fr/cartographie/metiers/urbanisme-espace-public-environnement/$idTaxon";
        $htmlTitle = "<title>Urbanisme / Espace public / Environnement";
402

403
        // Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
404
        $this->setAdminSessionOfPersonType();
405
        $r = $this->checkUrlOk($url, ['html']);
406
407
        $html = $r['html']['data'];
        $this->assertContains('<html lang="fr">', $html);
408
409
410
411
412
        $this->assertContains($htmlTitle, $html);
        $this->assertContains("id=\"sofwareListForTaxon$idTaxon\"", $html);
        $this->assertContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
        $this->assertContains("id=\"item-software$idSoftware-forTaxon$idTaxon\"", $html);
        $this->assertContains("id=\"link-software$idSoftware-forTaxon$idTaxon\"", $html);
413
414
415
416
417
418
419

        // Connected user
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized($url, ['html']);

        // Anonymous user
        $this->setAnonymousUserSession();
420
421
422
423
        $this->checkUrlRedirectToLogin($url, ['html'], 'fr');
    }


424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
    /**
     * Test mappingTaxon method : a taxon has a software without user (preselected software)
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *           /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *
     *      ex:  /fr/cartographie/metiers/sante-social/14      /en/mapping/business/healthcare-social/14
     *           /fr/cartographie/generiques/bureautique/20    /en/mapping/generics/office-automation/20
     *
     * @todo WIP
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingTaxon
     * @return void
     */
    public function testMappingTaxonShouldHaveSoftwareWithoutUsers()
    {
        $idTaxon = 6;
        $idSoftware = 4;
        $url = "/fr/cartographie/generiques/design/$idTaxon";
        $htmlTitle = "<title>Design";

        // Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
        $this->setAdminSessionOfPersonType();
        $r = $this->checkUrlOk($url, ['html']);
        $html = $r['html']['data'];
        $this->assertContains('<html lang="fr">', $html);
        $this->assertContains($htmlTitle, $html);
        $this->assertContains("id=\"sofwareListForTaxon$idTaxon\"", $html);
        $this->assertContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
        $this->assertContains("id=\"item-software$idSoftware-forTaxon$idTaxon\"", $html);
        $this->assertNotContains("id=\"link-software$idSoftware-forTaxon$idTaxon\"", $html);
    }


    /**
     * Test mappingTaxon method : a taxon has no software
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *           /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *
     *      ex:  /fr/cartographie/metiers/sante-social/14      /en/mapping/business/healthcare-social/14
     *           /fr/cartographie/generiques/bureautique/20    /en/mapping/generics/office-automation/20
     *
     * @todo WIP
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingTaxon
     * @return void
     */
    public function testMappingTaxonShouldNotHaveSoftware()
    {
        $idTaxon = 4;
        $url = "/fr/cartographie/generiques/bureautique/$idTaxon";
        $htmlTitle = "<title>Bureautique";

        // Admin user --> to be replaced by an anonymous user and a logged-in user when development is complete.
        $this->setAdminSessionOfPersonType();
        $r = $this->checkUrlOk($url, ['html']);
        $html = $r['html']['data'];
        $this->assertContains('<html lang="fr">', $html);
        $this->assertContains($htmlTitle, $html);
        $this->assertNotContains("id=\"sofwareListForTaxon$idTaxon\"", $html);
        $this->assertNotContains("class=\"item-softwareForTaxon$idTaxon\"", $html);
    }

496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
    /**
     * MappingTaxon method
     *
     * Check that redirects work when the URL is slightly different
     * - extra slash at the end of the URL
     * - the language prefix is missing at the beginning of the URL
     * - the user has changed the language prefix in the URL
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *           /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId>
     *
     *      ex:  /fr/cartographie/metiers/sante-social/14      /en/mapping/business/healthcare-social/14
     *           /fr/cartographie/generiques/bureautique/20    /en/mapping/generics/office-automation/20
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingTaxon
     * @return void
     */
    public function testMappingTaxonCheckRedirects()
    {
        // Admin user
        // --> to be replaced by an anonymous user and a logged-in user when development is complete.
523
        $this->setAdminSessionOfPersonType();
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576

        // French user:
        $expectedUrl = '/fr/cartographie/generiques/bureautique/4';
        $testeddUrl = '/fr/cartographie/generiques/bureautique/4/'; // extra slash at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/fr/mapping/generics/office-automation/4'; // the user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        //  French user: language prefix is missing at the beginning of URL
        $this->get("/fr/"); // force user language to french
        $testeddUrl = '/cartographie/generiques/bureautique/4'; // language prefix is missing at the beginning of URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        // English user
        $expectedUrl = '/en/mapping/generics/office-automation/4';
        $testeddUrl = '/en/mapping/generics/office-automation/4/'; // extra slash at the end of the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
        $testeddUrl = '/en/cartographie/generiques/bureautique/4'; // user has changed the language prefix in the URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        //  English user: language prefix is missing at the beginning of URL
        $this->get("/en/"); // force user language to english
        $testeddUrl = '/mapping/generics/office-automation/4'; //  language prefix is missing at the beginning of URL
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
    }



    /**
     * MappingTaxon method
     *
     * Check that if the requested taxon does not exist,
     * a redirection is made to '/en/mapping/' or '/fr/cartographie/'
     *
     *      URL: /fr/cartographie/<slugPrimaryLevel>/<slugTaxon>/<taxonId_notFound>
     *           /en/mapping/<slugPrimaryLevel>/<slugTaxon>/<taxonId_notFound>
     *
     *      ex:  /fr/cartographie/metiers/sante-social/14      /en/mapping/business/healthcare-social/14
     *           /fr/cartographie/generiques/bureautique/20    /en/mapping/generics/office-automation/20
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group seo
     * @group public
     * @group taxonomy
     * @group taxonomy_public
     * @group taxonomy_method_mappingTaxon
     * @return void
     */
    public function testMappingTaxonNotFound()
    {
        // Admin user
        // --> to be replaced by an anonymous user and a logged-in user when development is complete.
577
        $this->setAdminSessionOfPersonType();
578
579
580
581
582
583
584
585
586
587

        // French user:
        $expectedUrl = '/fr/cartographie/';
        $testeddUrl = '/fr/cartographie/metiers/notFoundTaxon/825';
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);

        // English user
        $expectedUrl = '/en/mapping/';
        $testeddUrl = '/en/mapping/metiers/notFoundTaxon/825';
        $this->checkUrlRedirectToAnotherUrl($testeddUrl, $expectedUrl, ['html'], 301);
588
589
    }

590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
    /**
     * MappingTaxon method with URL prefix /api/v1/
     * - HTML format redirects to the official URL
     * - JSON format returns a 404 "not found" error.
     *
     *      URL: /api/v1/taxonomys/mappingTaxon/<id>       ---> redirect to /en/mapping/ or /fr/cartographie/
     *      URL: /api/v1/taxonomys/mappingTaxon/<id>.json  ---> disable: 404 not found
     *
     * @todo admin user to be replaced by an anonymous and/or connected user when development is complete.
     *
     * @group taxonomy
     * @group taxonomy_notAllowed
     * @group taxonomy_method_mappingTaxon
     * @return void
     */
    public function testMappingTaxonCheckApiPrefixInUrl()
    {
        $url = '/api/v1/taxonomys/mappingTaxon/4';

        // Admin user ---> to be replaced by an anonymous and/or connected user when development is complete.
610
        $this->setAdminSessionOfPersonType();
611
612
613

        // JSON format
        $this->checkUrlNotFound($url, ['json']);
614

615
616
617
618
        // HTML format
        $expectedUrl = '/fr/cartographie/';
        $this->get("/fr/"); // force user language to french
        $this->checkUrlRedirectToAnotherUrl($url, $expectedUrl, ['html'], 301);
619

620
621
622
623
624
625
626
627
628
629
        // Connected user --> to be deleted when development is complete.
        $this->setConnectedUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlNotAuthorized($url, ['html']);

        // Anonymous user --> to be deleted when development is complete.
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
    }
630
631
632
633
634
635
636
637
638

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//// Admin actions ---> self-generated by CakePHP  //////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////


    // Admin user
    /////////////////////////////////////////////////////////////////////////////////////////

639
640
641
642
643
644
645
646
    /**
     * Test index method for admin user ---> allowed
     *
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
647
648
649
     * @group taxonomy_admin
     * @group taxonomy_method_index
     *
650
651
     * @return void
     */
652
    public function testIndexForAdminUser()
653
    {
654
        $this->setAdminSessionOfPersonType();
655
        $this->checkUrlOk('/api/v1/taxonomys');
656
657
658
659
660
    }

    /**
     * Test view method
     *
661
662
663
664
665
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
666
667
     * @group taxonomy_admin
     * @group taxonomy_method_view
668
669
     * @return void
     */
670
    public function testViewForAdminUser()
671
    {
672
        $this->setAdminSessionOfPersonType();
673
        $this->checkUrlOk('/api/v1/taxonomys/view/1');
674
675
676
677
678
    }

    /**
     * Test add method
     *
679
680
681
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
682
     * @todo Not implemented yet.
683
684
     * @group admin
     * @group taxonomy
685
686
     * @group taxonomy_admin
     * @group taxonomy_method_add
687
688
     * @return void
     */
689
    public function testAddForAdminUser()
690
    {
691
        $this->setAdminSessionOfPersonType();
692
        $this->checkUrlOk('/api/v1/taxonomys/add');
693

694
695
696
697
698
699
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test edit method
     *
700
701
702
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
703
     * @todo  not implemented yet.
704
705
     * @group admin
     * @group taxonomy
706
707
     * @group taxonomy_admin
     * @group taxonomy_method_edit
708
709
     * @return void
     */
710
    public function testEditForAdminUser()
711
    {
712
        $this->setAdminSessionOfPersonType();
713
        $this->checkUrlOk('/api/v1/taxonomys/edit/1');
714

715
716
717
718
719
720
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test delete method
     *
721
722
723
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
724
     * @todo  not implemented yet.
725
726
     * @group admin
     * @group taxonomy
727
728
     * @group taxonomy_admin
     * @group taxonomy_method_delete
729
730
731
732
     * @return void
     */
    public function testDeleteForAdminUser()
    {
733
        $this->setAdminSessionOfPersonType();
734

735
736
737
738
739
740
741
742
743
744
745
746
747
        $this->markTestIncomplete('Not implemented yet.');
    }


    // Connected user
    /////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Test index method for connected user ---> not authorized
     *
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
748
     * @group security
749
     * @group user
750
     * @group admin
751
     * @group taxonomy
752
753
     * @group taxonomy_admin
     * @group taxonomy_method_index
754
755
756
757
     * @return void
     */
    public function testFailIndexForConnectedUser()
    {
758
759
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys');
760
761
762
763
764
765
766
767
    }

    /**
     * Test view method for connected user ---> not authorized
     *
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
768
     * @group security
769
     * @group user
770
     * @group admin
771
     * @group taxonomy
772
773
     * @group taxonomy_admin
     * @group taxonomy_method_view
774
775
776
777
     * @return void
     */
    public function testFailViewForConnectedUser()
    {
778
779
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/view/1');
780
781
782
783
784
    }

    /**
     * Test add method for connected user
     * GET ---> not authorized
785
     * POST ---> @todo  not implemented yet
786
787
788
789
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
790
     * @group security
791
     * @group user
792
     * @group admin
793
     * @group taxonomy
794
795
     * @group taxonomy_admin
     * @group taxonomy_method_add
796
797
798
799
     * @return void
     */
    public function testFailAddForConnectedUser()
    {
800
801
802
803
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/add');

        $this->markTestIncomplete('Not implemented yet.');
804
805
806
807
808
    }

    /**
     * Test edit method for connected user
     * GET ---> not authorized
809
     * POST ---> @todo  not implemented yet
810
     *
811
     * @group security
812
     * @group user
813
     * @group admin
814
     * @group taxonomy
815
816
     * @group taxonomy_admin
     * @group taxonomy_method_edit
817
818
819
820
     * @return void
     */
    public function testFailEditForConnectedUser()
    {
821
822
823
824
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/edit/1');

        $this->markTestIncomplete('Not implemented yet.');
825
826
827
828
829
    }

    /**
     * Test delete method for connected user
     *
830
     * @todo    not implemented yet
831
832
     *
     * @group security
833
     * @group user
834
     * @group admin
835
     * @group taxonomy
836
837
     * @group taxonomy_admin
     * @group taxonomy_method_delete
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
     * @return void
     */
    public function testFailDeleteForConnectedUser()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }


    // Anonymous user
    /////////////////////////////////////////////////////////////////////////////////////////

    /**
     * Test index method for anonymous user ---> redirect to login form
     *
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
855
     * @group security
856
     * @group anonymous
857
     * @group admin
858
     * @group taxonomy
859
860
     * @group taxonomy_admin
     * @group taxonomy_method_index
861
862
863
864
     * @return void
     */
    public function testFailIndexForAnonymousUser()
    {
865
866
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys');
867
868
869
870
871
872
873
874
    }

    /**
     * Test view method for anonymous user ---> redirect to login form
     *
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
875
     * @group security
876
     * @group anonymous
877
     * @group admin
878
     * @group taxonomy
879
880
     * @group taxonomy_admin
     * @group taxonomy_method_view
881
882
883
884
     * @return void
     */
    public function testFailViewForAnonymousUser()
    {
885
886
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/view/1');
887
888
889
890
891
    }

    /**
     * Test add method for anonymous user
     * GET ---> redirect to login form
892
     * POST ---> @todo  not implemented yet
893
894
895
896
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
897
     * @group security
898
     * @group anonymous
899
     * @group admin
900
     * @group taxonomy
901
902
     * @group taxonomy_admin
     * @group taxonomy_method_add
903
904
905
906
     * @return void
     */
    public function testFailAddForAnonymousUser()
    {
907
908
909
910
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/add');

        $this->markTestIncomplete('Not implemented yet.');
911
912
913
914
915
    }

    /**
     * Test edit method for anonymous user
     * GET ---> redirect to login form
916
     * POST ---> @todo  not implemented yet
917
     *
918
     * @group security
919
     * @group anonymous
920
     * @group admin
921
     * @group taxonomy
922
923
     * @group taxonomy_admin
     * @group taxonomy_method_edit
924
925
926
927
     * @return void
     */
    public function testFailEditForAnonymousUser()
    {
928
929
930
931
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/edit/1');

        $this->markTestIncomplete('Not implemented yet.');
932
933
934
935
    }

    /**
     * Test delete method for anonymous user
936
937
     *
     * @todo  not implemented yet
938
     *
939
     * @group security
940
     * @group anonymous
941
     * @group admin
942
     * @group taxonomy
943
944
     * @group taxonomy_admin
     * @group taxonomy_method_delete
945
946
     * @return void
     */
947
    public function testFailDeleteForAnonymousUser()
948
949
950
951
    {
        $this->markTestIncomplete('Not implemented yet.');
    }
}