TaxonomysControllerTest.php 8.85 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
20
21
22
23
24
25
26
27
28
29
30
31
{

    /**
     * Fixtures
     *
     * @var array
     */
    public $fixtures = [
        'app.taxonomys',
        'app.relationships_taxonomys_sofwares',
        '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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74





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

    /**
     * Set session for a admin user
     */
    private function setAdminSession()
    {
        $this->session([
            'Auth' => [
                'User' => [
                    'id' => 2,
                    "user_type_id" => 2,
                    "role" => 'admin',
                ]
            ]
        ]);
    }


75
    /**
76
77
78
     * For a connected user
     * - loads the HTTP GET request
     * - expects a "not authorized" response.
79
     *
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
     * @param string $url
     * @return Array
     */
    private function getUrlOkForAdminUser(string $url): Array
    {
        $this->setAdminSession();
        return $this->getUrlOk($url);
    }


    /**
     * Test index method for admin user ---> allowed
     *
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
98
99
     * @return void
     */
100
    public function testIndexForAdminUser()
101
    {
102
103
104
        $result = $this->getUrlOkForAdminUser('/api/v1/taxonomys');
        $json = $result['json'];
        $html = $result['html'];
105
106
107
108
109
    }

    /**
     * Test view method
     *
110
111
112
113
114
     *      URL: /api/v1/taxonomys/view/1
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
115
116
     * @return void
     */
117
    public function testViewForAdminUser()
118
    {
119
        $result = $this->getUrlOkForAdminUser('/api/v1/taxonomys/view/1');
120
121
122
123
124
    }

    /**
     * Test add method
     *
125
126
127
128
129
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
130
131
     * @return void
     */
132
    public function testAddForAdminUser()
133
    {
134
        $this->setAdminSession();
135
136
137
138
139
140
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test edit method
     *
141
142
143
144
145
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
146
147
     * @return void
     */
148
    public function testEditForAdminUser()
149
    {
150
        $this->setAdminSession();
151
152
153
154
155
156
        $this->markTestIncomplete('Not implemented yet.');
    }

    /**
     * Test delete method
     *
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
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
265
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
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
318
319
320
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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
     *      URL: /api/v1/taxonomys
     *           ----> allowed only for user with "admin" role
     *
     * @group admin
     * @group taxonomy
     * @return void
     */
    public function testDeleteForAdminUser()
    {
        $this->setAdminSession();
        $this->markTestIncomplete('Not implemented yet.');
    }



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

    /**
     * Set session for a connected user
     */
    private function setConnectedUserSession()
    {
        $this->session([
            'Auth' => [
                'User' => [
                    'id' => 2,
                    "user_type_id" => 2,
                    "role" => 'User',
                ]
            ]
        ]);
    }

    /**
     * For a connected user
     * - loads the HTTP GET request
     * - expects a "not authorized" response.
     *
     * @param string $url
     */
    private function getUrlNotAuthorizedForConnectedUser(string $url)
    {
        $this->setConnectedUserSession();
        $this->getUrlNotAuthorized($url);
    }



    /**
     * 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()
    {
        $this->getUrlNotAuthorizedForConnectedUser('/api/v1/taxonomys');
    }

    /**
     * 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()
    {
        $this->getUrlNotAuthorizedForConnectedUser('/api/v1/taxonomys/view/1');
    }

    /**
     * Test add method for connected user
     * GET ---> not authorized
     * POST ---> @todo
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailAddForConnectedUser()
    {
        $this->getUrlNotAuthorizedForConnectedUser('/api/v1/taxonomys/add');
    }

    /**
     * Test edit method for connected user
     * GET ---> not authorized
     * POST ---> @todo
     *
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailEditForConnectedUser()
    {
        $this->getUrlNotAuthorizedForConnectedUser('/api/v1/taxonomys/edit/1');
    }

    /**
     * Test delete method for connected user
     *
     *
     * @todo
     * @group user
     * @group taxonomy
     * @return void
     */
    public function testFailDeleteForConnectedUser()
    {
        $this->markTestIncomplete('Not implemented yet.');
    }




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

    /**
     * Set session for a anonymous user
     */
    private function setAnonymousUserSession()
    {
        $this->session([]);
    }

    /**
     * For anonymous user:
     * - loads the HTTP GET request
     * - expects a redirect to login form.
     *
     * @param string $url
     */
    private function getUrlRedirectToLoginForAnonymousUser(string $url)
    {
        $redirectTo = '/users/login';
        $this->setAnonymousUserSession();
        $this->getUrlRedirectToAnotherUrl($url, $redirectTo);
    }


    /**
     * 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()
    {
        $this->getUrlRedirectToLoginForAnonymousUser('/api/v1/taxonomys');
    }

    /**
     * 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()
    {
        $this->getUrlRedirectToLoginForAnonymousUser('/api/v1/taxonomys/view/1');
    }

    /**
     * Test add method for anonymous user
     * GET ---> redirect to login form
     * POST ---> @todo
     *
     *      URL: /api/v1/taxonomys/add
     *           ----> allowed only for user with "admin" role
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailAddForAnonymousUser()
    {
        $this->getUrlRedirectToLoginForAnonymousUser('/api/v1/taxonomys/add');
    }

    /**
     * Test edit method for anonymous user
     * GET ---> redirect to login form
     * POST ---> @todo
     *
     * @group anonymous
     * @group taxonomy
     * @return void
     */
    public function testFailEditForAnonymousUser()
    {
        $this->getUrlRedirectToLoginForAnonymousUser('/api/v1/taxonomys/edit/1');
    }

    /**
     * Test delete method for anonymous user
     * @todo
     *
     * @group anonymous
     * @group taxonomy
377
378
     * @return void
     */
379
    public function testFailDeleteForAnonymousUser()
380
381
382
383
    {
        $this->markTestIncomplete('Not implemented yet.');
    }
}