Commit 5db8276af6fa4aec3d533324c398da80d717b357
1 parent
b711c664
Exists in
master
and in
3 other branches
dernières optimisation sur les tests
Showing
6 changed files
with
112 additions
and
45 deletions
Show diff stats
README-LABINVENT.md
... | ... | @@ -47,8 +47,8 @@ Logiciel testé et validé sur les configurations suivantes : |
47 | 47 | |
48 | 48 | VERSION ACTUELLE |
49 | 49 | |
50 | -Date: 28/08/2017 | |
51 | -Version: 2.7.6 | |
50 | +Date: 29/08/2017 | |
51 | +Version: 2.7.7 | |
52 | 52 | Grosse amelioration des tests (refactorisation, généralisation) |
53 | 53 | |
54 | 54 | Version majeure en cours (2.7): https://projects.irap.omp.eu/versions/162 |
... | ... | @@ -65,6 +65,10 @@ CHANGEMENTS IMPORTANTS (MILESTONES) |
65 | 65 | |
66 | 66 | Liste complète des évolutions: https://gitlab.irap.omp.eu/epallier/labinvent/commits/master |
67 | 67 | |
68 | +28/08/2017 Version: 2.7.6 | |
69 | + - renforcement important des TESTS : généralisation, refactorisation, simplification + numérotation systématique (cf doc ACL) | |
70 | + - nouvelle philo mise en place : 1 fichier tests par Controleur (c'était déjà le cas), puis pour un controleur donné, tri des tests par ACTION, puis pour chaque action, tests systématique de tous les ROLES (profils) avec les cas particuliers de chacun | |
71 | + | |
68 | 72 | 06/07/2017 Version: 2.7.3 |
69 | 73 | - suppression du contenu de vendor/ => désormais ignoré car autogénéré |
70 | 74 | - update des plugins phpqrcode et fpdf => désormais via composer.json | ... | ... |
src/Controller/AppController.php
... | ... | @@ -49,6 +49,9 @@ class AppController extends Controller { |
49 | 49 | 'Super Administrateur' => self::PROFILE_SUPERADMIN |
50 | 50 | ]; |
51 | 51 | |
52 | + // Current role (profile) of the user | |
53 | + private $CURRENT_ROLE = null; | |
54 | + | |
52 | 55 | |
53 | 56 | public static function getRoleLevel($role) { |
54 | 57 | //return $this->allProfiles[$role]; |
... | ... | @@ -105,12 +108,15 @@ class AppController extends Controller { |
105 | 108 | } |
106 | 109 | |
107 | 110 | public function getUserRole() { |
108 | - $configuration = $this->confLabinvent; | |
109 | - $user = TableRegistry::get('Users')->find() | |
110 | - ->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]]) | |
111 | - //->where(['username' => $this->LdapAuth->user('cn')[0]]) | |
112 | - ->first(); | |
113 | - return $user['role']; | |
111 | + if (! $this->CURRENT_ROLE) { | |
112 | + $configuration = $this->confLabinvent; | |
113 | + $user = TableRegistry::get('Users')->find() | |
114 | + ->where(['username' => $this->LdapAuth->user($configuration->authentificationType_ldap)[0]]) | |
115 | + //->where(['username' => $this->LdapAuth->user('cn')[0]]) | |
116 | + ->first(); | |
117 | + $this->CURRENT_ROLE = $user['role']; | |
118 | + } | |
119 | + return $this->CURRENT_ROLE; | |
114 | 120 | } |
115 | 121 | |
116 | 122 | public function userHasRole($expectedRole, $ORMORE=false) { | ... | ... |
src/Template/Layout/default.ctp
... | ... | @@ -115,7 +115,7 @@ $cakeDescription = 'Labinvent 2'; |
115 | 115 | </i></td> |
116 | 116 | <td id="version"> |
117 | 117 | <!-- VERSION M.m.f.b (version (M)ajeure, version (m)ineure, numero de nouvelle (f)onctionnalite, numero de (b)ugfix) --> |
118 | - <font color="black">VERSION 2.7.6 (28/08/2017)</font> | |
118 | + <font color="black">VERSION 2.7.7 (29/08/2017)</font> | |
119 | 119 | <br/> |
120 | 120 | <font color="black"><a href="<?php |
121 | 121 | ... | ... |
tests/TestCase/Controller/General.php
... | ... | @@ -30,6 +30,9 @@ class General extends IntegrationTestCase { |
30 | 30 | ]; |
31 | 31 | |
32 | 32 | const PROFILES = AppController::PROFILES; |
33 | + | |
34 | + // Current role (profile) of the user | |
35 | + private $CURRENT_ROLE = null; | |
33 | 36 | |
34 | 37 | /* |
35 | 38 | public $ControllerApp = null; |
... | ... | @@ -67,11 +70,14 @@ class General extends IntegrationTestCase { |
67 | 70 | |
68 | 71 | // Definition DIFFERENTE de celle de AppController |
69 | 72 | public function getUserRole() { |
70 | - $user = TableRegistry::get('Users')->find()->where([ | |
71 | - //'username' => 'user1_SUPER' | |
72 | - 'username' => $this->_session['Auth']['User']['cn'][0] | |
73 | - ])->first(); | |
74 | - return $user['role']; | |
73 | + if (! $this->CURRENT_ROLE) { | |
74 | + $user = TableRegistry::get('Users')->find()->where([ | |
75 | + //'username' => 'user1_SUPER' | |
76 | + 'username' => $this->_session['Auth']['User']['cn'][0] | |
77 | + ])->first(); | |
78 | + $this->CURRENT_ROLE = $user['role']; | |
79 | + } | |
80 | + return $this->CURRENT_ROLE; | |
75 | 81 | } |
76 | 82 | // MEME Definition de celle de AppController (mais n'utilise la meme fonction getUserRole()) |
77 | 83 | public function userHasRole($expectedRole, $ORMORE=false) { |
... | ... | @@ -106,20 +112,30 @@ class General extends IntegrationTestCase { |
106 | 112 | |
107 | 113 | public function authAs($role) { |
108 | 114 | switch ($role) { |
109 | - case 'USER': $this->authUtilisateur(); | |
110 | - break; | |
111 | - case 'RESP': $this->authResponsable(); | |
112 | - break; | |
113 | - case 'ADMIN': $this->authAdmin(); | |
114 | - break; | |
115 | - case 'ADMINP': $this->authAdminPlus(); | |
116 | - break; | |
117 | - case 'SUPER': $this->authSuperAdmin(); | |
118 | - break; | |
115 | + case 'USER': | |
116 | + $this->authUtilisateur(); | |
117 | + //$this->CURRENT_ROLE = 'Utilisateur'; | |
118 | + break; | |
119 | + case 'RESP': | |
120 | + $this->authResponsable(); | |
121 | + //$this->CURRENT_ROLE = 'Responsable'; | |
122 | + break; | |
123 | + case 'ADMIN': | |
124 | + $this->authAdmin(); | |
125 | + //$this->CURRENT_ROLE = 'Administration'; | |
126 | + break; | |
127 | + case 'ADMINP': | |
128 | + $this->authAdminPlus(); | |
129 | + //$this->CURRENT_ROLE = 'Administration Plus'; | |
130 | + break; | |
131 | + case 'SUPER': | |
132 | + $this->authSuperAdmin(); | |
133 | + //$this->CURRENT_ROLE = 'Super Administrateur'; | |
134 | + break; | |
119 | 135 | } |
120 | 136 | } |
121 | 137 | |
122 | - public function authUser($cn, $givenName='test1', $sn='test2') { | |
138 | + private function authUser($cn, $givenName='test1', $sn='test2') { | |
123 | 139 | $user = [ |
124 | 140 | 'Auth' => [ |
125 | 141 | 'User' => [ | ... | ... |
tests/TestCase/Controller/MaterielsControllerTest.php
... | ... | @@ -141,13 +141,20 @@ class MaterielsControllerTest extends General { |
141 | 141 | * |
142 | 142 | * @return void |
143 | 143 | */ |
144 | - public function testMat20ReadAll() { // test INDEX action | |
144 | + // test INDEX action | |
145 | + /* | |
146 | + public function testMat20ReadAll() { | |
145 | 147 | foreach ($this->ROLES as $role) $this->_testMatReadAllAs($role); |
146 | 148 | } |
147 | - | |
149 | + */ | |
150 | + public function testMat20ReadAllAsUser() { $this->_testMatReadAllAs('USER'); } | |
151 | + public function testMat20ReadAllAsResp() { $this->_testMatReadAllAs('RESP'); } | |
152 | + public function testMat20ReadAllAsAdmin() { $this->_testMatReadAllAs('ADMIN'); } | |
153 | + public function testMat20ReadAllAsAdminP() { $this->_testMatReadAllAs('ADMINP'); } | |
154 | + public function testMat20ReadAllAsSuperAdmin() { $this->_testMatReadAllAs('SUPER'); } | |
148 | 155 | private function _testMatReadAllAs($role) |
149 | 156 | { |
150 | - $this->setUp(); | |
157 | + //$this->setUp(); | |
151 | 158 | |
152 | 159 | // On doit pouvoir accéder à la page une fois authentifié |
153 | 160 | $this->authAs($role); |
... | ... | @@ -190,7 +197,7 @@ class MaterielsControllerTest extends General { |
190 | 197 | } |
191 | 198 | */ |
192 | 199 | |
193 | - $this->tearDown(); | |
200 | + //$this->tearDown(); | |
194 | 201 | } |
195 | 202 | public function testMat21ReadAllAsAnonymous() { // test INDEX action |
196 | 203 | // On ne doit pas avoir accès sans authentification |
... | ... | @@ -216,12 +223,20 @@ class MaterielsControllerTest extends General { |
216 | 223 | * @group failing |
217 | 224 | * @return void |
218 | 225 | */ |
226 | + /* | |
219 | 227 | public function testMat10ReadOne() { // test VIEW action |
220 | 228 | foreach ($this->ROLES as $role) $this->_testMatReadOneAs($role); |
221 | 229 | } |
230 | + */ | |
231 | + // test VIEW action | |
232 | + public function testMat10ReadOneAsUser() { $this->_testMatReadOneAs('USER'); } | |
233 | + public function testMat10ReadOneAsResp() { $this->_testMatReadOneAs('RESP'); } | |
234 | + public function testMat10ReadOneAsAdmin() { $this->_testMatReadOneAs('ADMIN'); } | |
235 | + public function testMat10ReadOneAsAdminPlus() { $this->_testMatReadOneAs('ADMINP'); } | |
236 | + public function testMat10ReadOneAsSuperAdmin() { $this->_testMatReadOneAs('SUPER'); } | |
222 | 237 | private function _testMatReadOneAs($role) |
223 | 238 | { |
224 | - $this->setUp(); | |
239 | + //$this->setUp(); | |
225 | 240 | |
226 | 241 | //$this->authSuperAdmin(); |
227 | 242 | $this->authAs($role); |
... | ... | @@ -243,7 +258,7 @@ class MaterielsControllerTest extends General { |
243 | 258 | } |
244 | 259 | else $this->assertResponseNotContains("Informations administratives"); |
245 | 260 | |
246 | - $this->tearDown(); | |
261 | + //$this->tearDown(); | |
247 | 262 | |
248 | 263 | } |
249 | 264 | |
... | ... | @@ -260,13 +275,19 @@ class MaterielsControllerTest extends General { |
260 | 275 | * |
261 | 276 | * @return void |
262 | 277 | */ |
278 | + /* | |
263 | 279 | public function testMat30AccessCreateForm() { |
264 | 280 | foreach ($this->ROLES as $role) $this->_testMatAccessCreateFormAs($role); |
265 | 281 | } |
266 | - | |
282 | + */ | |
283 | + public function testMat30AccessCreateFormAsUser() { $this->_testMatAccessCreateFormAs('USER'); } | |
284 | + public function testMat30AccessCreateFormAsResp() { $this->_testMatAccessCreateFormAs('RESP'); } | |
285 | + public function testMat30AccessCreateFormAsAdmin() { $this->_testMatAccessCreateFormAs('ADMIN'); } | |
286 | + public function testMat30AccessCreateFormAsAdminPlus() { $this->_testMatAccessCreateFormAs('ADMINP'); } | |
287 | + public function testMat30AccessCreateFormAsSuperAdmin() { $this->_testMatAccessCreateFormAs('SUPER'); } | |
267 | 288 | private function _testMatAccessCreateFormAs($role) |
268 | 289 | { |
269 | - $this->setUp(); | |
290 | + //$this->setUp(); | |
270 | 291 | |
271 | 292 | // On doit pouvoir accéder à la page une fois authentifié |
272 | 293 | $this->authAs($role); |
... | ... | @@ -283,7 +304,7 @@ class MaterielsControllerTest extends General { |
283 | 304 | $this->assertResponseContains('EOTP', 'Le profil admin+ n\'a pas accès à la partie administrative sur le formulaire add.'); |
284 | 305 | */ |
285 | 306 | |
286 | - $this->tearDown(); | |
307 | + //$this->tearDown(); | |
287 | 308 | } |
288 | 309 | |
289 | 310 | |
... | ... | @@ -458,6 +479,8 @@ class MaterielsControllerTest extends General { |
458 | 479 | * @return void |
459 | 480 | */ |
460 | 481 | |
482 | + // ACTION 'edit' | |
483 | + /* | |
461 | 484 | public function testUpdate() { // ACTION 'edit' |
462 | 485 | foreach ($this->ROLES as $role) { |
463 | 486 | $this->authAs($role); |
... | ... | @@ -465,10 +488,15 @@ class MaterielsControllerTest extends General { |
465 | 488 | $this->_testUpdates($role); |
466 | 489 | } // foreach |
467 | 490 | } |
468 | - | |
469 | - | |
470 | - private function _testUpdates($role) { | |
471 | - | |
491 | + */ | |
492 | + //TODO: test as USER | |
493 | + //public function testUpdateAsUser() { $this->_testUpdatesAs('USER'); } | |
494 | + public function testUpdateAsResp() { $this->_testUpdatesAs('RESP'); } | |
495 | + public function testUpdateAsAdmin() { $this->_testUpdatesAs('ADMIN'); } | |
496 | + public function testUpdateAsAdminPlus() { $this->_testUpdatesAs('ADMINP'); } | |
497 | + public function testUpdateAsSuperAdmin() { $this->_testUpdatesAs('SUPER'); } | |
498 | + private function _testUpdatesAs($role) { | |
499 | + $this->authAs($role); | |
472 | 500 | // 1) Test qu'on peut modifier un materiel CREATED |
473 | 501 | // Toutes les donnees passees sont modifiees |
474 | 502 | $data = [ | ... | ... |
tests/TestCase/Controller/PagesControllerTest.php
... | ... | @@ -61,12 +61,18 @@ class PagesControllerTest extends General |
61 | 61 | * @return void |
62 | 62 | */ |
63 | 63 | |
64 | + //public function testDisplay() | |
65 | + /* | |
64 | 66 | public function testPage10AccessHome() { |
65 | 67 | foreach ($this->ROLES as $role) $this->subtestPageAccessHomeAs($role); |
66 | 68 | } |
67 | - //public function testDisplay() | |
68 | - private function subtestPageAccessHomeAs($role) | |
69 | - { | |
69 | + */ | |
70 | + public function testPage10AccessHomeAsUser() { $this->_testPageAccessHomeAs('USER'); } | |
71 | + public function testPage10AccessHomeAsResp() { $this->_testPageAccessHomeAs('RESP'); } | |
72 | + public function testPage10AccessHomeAsAdmin() { $this->_testPageAccessHomeAs('ADMIN'); } | |
73 | + public function testPage10AccessHomeAsAdminPlus() { $this->_testPageAccessHomeAs('ADMINP'); } | |
74 | + public function testPage10AccessHomeAsSuperAdmin() { $this->_testPageAccessHomeAs('SUPER'); } | |
75 | + private function _testPageAccessHomeAs($role) { | |
70 | 76 | //$this->authUser(); |
71 | 77 | $this->authAs($role); |
72 | 78 | |
... | ... | @@ -96,12 +102,18 @@ class PagesControllerTest extends General |
96 | 102 | |
97 | 103 | } |
98 | 104 | |
99 | - | |
105 | + //public function testDisplay() | |
106 | + /* | |
100 | 107 | public function testPage20AccessTools() { |
101 | 108 | foreach ($this->ROLES as $role) $this->subtestPageAccessToolsAs($role); |
102 | 109 | } |
103 | - //public function testDisplay() | |
104 | - private function subtestPageAccessToolsAs($role) | |
110 | + */ | |
111 | + public function testPage20AccessToolsAsUser() { $this->_testPageAccessToolsAs('USER'); } | |
112 | + public function testPage20AccessToolsAsResp() { $this->_testPageAccessToolsAs('RESP'); } | |
113 | + public function testPage20AccessToolsAsAdmin() { $this->_testPageAccessToolsAs('ADMIN'); } | |
114 | + public function testPage20AccessToolsAsAdminPlus() { $this->_testPageAccessToolsAs('ADMINP'); } | |
115 | + public function testPage20AccessToolsAsSuperAdmin() { $this->_testPageAccessToolsAs('SUPER'); } | |
116 | + private function _testPageAccessToolsAs($role) | |
105 | 117 | { |
106 | 118 | $this->authAs($role); |
107 | 119 | $this->get('/pages/tools'); |
... | ... | @@ -113,7 +125,8 @@ class PagesControllerTest extends General |
113 | 125 | $this->assertResponseOk(); |
114 | 126 | $this->assertResponseContains('Outils', $role.' should be allowed to access the Tools page'); |
115 | 127 | $this->assertResponseContains('Gérer le contenu variable de ', $role); |
116 | - if ($role == 'SUPER') | |
128 | + if ($this->USER_IS_SUPERADMIN()) | |
129 | + //if ($role == 'SUPER') | |
117 | 130 | $this->assertResponseContains('Passer en mode DEBUG'); |
118 | 131 | else |
119 | 132 | $this->assertResponseNotContains('Passer en mode DEBUG'); | ... | ... |