TaxonomysControllerTest.php 11.4 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
59
60
61
62
63
64
65
    /**
     * Test mapping method
     *
     *      URL: /api/v1/taxonomys/mapping
     *
     * @group taxonomy
     * @return void
     */
    public function testMapping()
    {
        $url = '/api/v1/taxonomys/mapping';
66

67
68
        // Admin user
        $this->setAdminSession();
69

70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
        // @todo refactor
        $this->checkUrlNotFound($url, ['json']);
        $r = $this->checkUrlOk($url, ['html']);
        $headers = $r['html']['data'];
        $html = $r['html']['data']; // @todo check content or TF ?
        $this->assertContains("mapping", $html);

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

        // Anonymous user
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
    }
87
88
89


    /**
90
91
92
93
94
95
96
     * Test mappingPrimaryLevel method
     *
     *      URL: /api/v1/taxonomys/mappingPrimaryLevel/<id>
     *
     * @todo refactor
     * @group taxonomy
     * @return void
97
     */
98
    public function testMappingPrimaryLevel()
99
    {
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
        $url = '/api/v1/taxonomys/mappingPrimaryLevel/1';

        // Admin user
        $this->setAdminSession();

        // @todo refactor
        $this->checkUrlNotFound($url, ['json']);
        $r = $this->checkUrlOk($url, ['html']);
        $headers = $r['html']['data'];
        $html = $r['html']['data']; // @todo check content or TF ?
        $this->assertContains("mappingPrimaryLevel", $html);

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

        // Anonymous user
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
121
122
123
    }


124
    /**
125
126
127
     * Test mappingTaxon method
     *
     *      URL: /api/v1/taxonomys/mappingTaxon/<id>
128
     *
129
130
131
     * @todo refactor
     * @group taxonomy
     * @return void
132
     */
133
    public function testMappingTaxon()
134
    {
135
136
137
        $url = '/api/v1/taxonomys/mappingTaxon/1';

        // Admin user
138
        $this->setAdminSession();
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155

        // @todo refactor
        $this->checkUrlNotFound($url, ['json']);
        $r = $this->checkUrlOk($url, ['html']);
        $headers = $r['html']['data'];
        $html = $r['html']['data']; // @todo check content or TF ?
        $this->assertContains("mappingTaxon", $html);

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

        // Anonymous user
        $this->setAnonymousUserSession();
        $this->checkUrlNotFound($url, ['json']);
        $this->checkUrlRedirectToLogin($url, ['html']);
156
157
158
    }


159
160
161
162
163
164
165
166
167
168


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


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

169
170
171
172
173
174
175
176
    /**
     * Test index method for admin user ---> allowed
     *
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
177
178
     * @return void
     */
179
    public function testIndexForAdminUser()
180
    {
181
182
        $this->setAdminSession();
        $result = $this->checkUrlOk('/api/v1/taxonomys');
183
184
        $json = $result['json'];
        $html = $result['html'];
185
186
187
188
189
    }

    /**
     * Test view method
     *
190
191
192
193
194
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
195
196
     * @return void
     */
197
    public function testViewForAdminUser()
198
    {
199
200
        $this->setAdminSession();
        $result = $this->checkUrlOk('/api/v1/taxonomys/view/1');
201
202
203
204
205
    }

    /**
     * Test add method
     *
206
207
208
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
209
     * @todo Not implemented yet.
210
211
     * @group admin
     * @group taxonomy
212
213
     * @return void
     */
214
    public function testAddForAdminUser()
215
    {
216
        $this->setAdminSession();
217
218
        $result = $this->checkUrlOk('/api/v1/taxonomys/add');

219
220
221
222
223
224
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test edit method
     *
225
226
227
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
228
     * @todo  not implemented yet.
229
230
     * @group admin
     * @group taxonomy
231
232
     * @return void
     */
233
    public function testEditForAdminUser()
234
    {
235
        $this->setAdminSession();
236
237
        $result = $this->checkUrlOk('/api/v1/taxonomys/edit/1');

238
239
240
241
242
243
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test delete method
     *
244
245
246
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
247
     * @todo  not implemented yet.
248
249
250
251
252
253
254
     * @group admin
     * @group taxonomy
     * @return void
     */
    public function testDeleteForAdminUser()
    {
        $this->setAdminSession();
255

256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
        $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
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailIndexForConnectedUser()
    {
275
276
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys');
277
278
279
280
281
282
283
284
285
286
287
288
289
290
    }

    /**
     * Test view method for connected user ---> not authorized
     *
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailViewForConnectedUser()
    {
291
292
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/view/1');
293
294
295
296
297
    }

    /**
     * Test add method for connected user
     * GET ---> not authorized
298
     * POST ---> @todo  not implemented yet
299
300
301
302
303
304
305
306
307
308
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailAddForConnectedUser()
    {
309
310
311
312
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/add');

        $this->markTestIncomplete('Not implemented yet.');
313
314
315
316
317
    }

    /**
     * Test edit method for connected user
     * GET ---> not authorized
318
     * POST ---> @todo  not implemented yet
319
320
321
322
323
324
325
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailEditForConnectedUser()
    {
326
327
328
329
        $this->setConnectedUserSession();
        $this->checkUrlNotAuthorized('/api/v1/taxonomys/edit/1');

        $this->markTestIncomplete('Not implemented yet.');
330
331
332
333
334
    }

    /**
     * Test delete method for connected user
     *
335
     * @todo    not implemented yet
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
     * @group user
     * @group taxonomy
     * @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
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailIndexForAnonymousUser()
    {
361
362
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys');
363
364
365
366
367
368
369
370
371
372
373
374
375
376
    }

    /**
     * Test view method for anonymous user ---> redirect to login form
     *
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailViewForAnonymousUser()
    {
377
378
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/view/1');
379
380
381
382
383
    }

    /**
     * Test add method for anonymous user
     * GET ---> redirect to login form
384
     * POST ---> @todo  not implemented yet
385
386
387
388
389
390
391
392
393
394
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailAddForAnonymousUser()
    {
395
396
397
398
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/add');

        $this->markTestIncomplete('Not implemented yet.');
399
400
401
402
403
    }

    /**
     * Test edit method for anonymous user
     * GET ---> redirect to login form
404
     * POST ---> @todo  not implemented yet
405
406
407
408
409
410
411
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailEditForAnonymousUser()
    {
412
413
414
415
        $this->setAnonymousUserSession();
        $this->checkUrlRedirectToLogin('/api/v1/taxonomys/edit/1');

        $this->markTestIncomplete('Not implemented yet.');
416
417
418
419
    }

    /**
     * Test delete method for anonymous user
420
421
     *
     * @todo  not implemented yet
422
423
424
     *
     * @group anonymous
     * @group taxonomy
425
426
     * @return void
     */
427
    public function testFailDeleteForAnonymousUser()
428
429
430
431
    {
        $this->markTestIncomplete('Not implemented yet.');
    }
}