PagesControllerTest.php
5.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
116
117
118
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
173
174
175
176
177
178
179
180
181
182
183
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 1.2.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace App\Test\TestCase\Controller;
use Cake\Core\Configure;
use Cake\TestSuite\IntegrationTestCase;
/**
* PagesControllerTest class
*/
//class PagesControllerTest extends IntegrationTestCase
class PagesControllerTest extends General
{
/**
* Fixtures
*
* @var array
*/
public $fixtures = [
'app.Configurations',
//'app.fakeldapusers',
'app.Fakeldapusers',
'app.Users',
];
/*
public function authUser() {
$user = [
'Auth' => [
'User' => [
'sn' => [0 => 'test2'],
'mail' => [0 => 'test@test.fr'],
'givenname' => [0 => 'test1'],
'cn' => [0 => 'testa'],
'userpassword' => [0 => 'test'],
]
]
];
$this->session($user);
$authType = ['authType' => 'cn'];
$this->session($authType);
}
*/
/**
* testDisplay method
*
* @return void
*/
//public function testDisplay()
/*
public function testPage10AccessHome() {
foreach ($this->ROLES as $role) $this->subtestPageAccessHomeAs($role);
}
*/
public function testPage10AccessHomeAsUser() { $this->_testPageAccessHomeAs('USER'); }
public function testPage10AccessHomeAsResp() { $this->_testPageAccessHomeAs('RESP'); }
public function testPage10AccessHomeAsAdmin() { $this->_testPageAccessHomeAs('ADMIN'); }
//public function testPage10AccessHomeAsAdminPlus() { $this->_testPageAccessHomeAs('ADMINP'); }
public function testPage10AccessHomeAsSuperAdmin() { $this->_testPageAccessHomeAs('SUPER'); }
private function _testPageAccessHomeAs($role) {
//$this->authUser();
$this->authAs($role);
$this->get('/pages/home');
$this->assertResponseOk();
$this->assertResponseContains('Accueil');
$this->assertResponseContains('Voir mes matériels');
switch ($role) {
case 'USER':
$this->assertResponseContains('Utilisateur');
//$configuration->procedure_sur_accueil = TRUE;
$this->assertResponseContains('Procédure à suivre');
break;
case 'RESP': break;
case 'ADMIN':
$this->assertResponseContains('Administration');
//$this->assertResponseContains('Statistiques');
//$this->assertResponseContains('Voir mes matériels');
$this->assertResponseContains('Voir les matériels à Valider');
break;
//case 'ADMINP': break;
case 'SUPER':
$this->assertResponseContains('Super Administrateur');
break;
}
}
//public function testDisplay()
/*
public function testPage20AccessTools() {
foreach ($this->ROLES as $role) $this->subtestPageAccessToolsAs($role);
}
*/
public function testPage20AccessToolsAsUser() { $this->_testPageAccessToolsAs('USER'); }
public function testPage20AccessToolsAsResp() { $this->_testPageAccessToolsAs('RESP'); }
public function testPage20AccessToolsAsAdmin() { $this->_testPageAccessToolsAs('ADMIN'); }
//public function testPage20AccessToolsAsAdminPlus() { $this->_testPageAccessToolsAs('ADMINP'); }
public function testPage20AccessToolsAsSuperAdmin() { $this->_testPageAccessToolsAs('SUPER'); }
private function _testPageAccessToolsAs($role)
{
$this->authAs($role);
$this->get('/pages/tools');
if ( $this->USER_IS_ADMIN_AT_LEAST() ) {
//if ( in_array($role, ['ADMIN','ADMINP','SUPER']) ) {
//if ( $this->userHasRoleAtLeast('Administration') ) {
//if ( $this->ControllerApp->userHasRoleAtLeast('Administration') ) {
$this->assertResponseOk();
$this->assertResponseContains('Outils', $role.' should be allowed to access the Tools page');
$this->assertResponseContains('Gérer le contenu variable de ', $role);
if ($this->USER_IS_SUPERADMIN())
//if ($role == 'SUPER')
$this->assertResponseContains('Passer en mode DEBUG');
else
$this->assertResponseNotContains('Passer en mode DEBUG');
}
else {
$this->assertResponseNotContains('Outils', $role.' should not be allowed to access the Tools page');
}
}
/**
* Test that missing template renders 404 page in production
*
* @return void
*/
public function OFF_testMissingTemplate()
{
//$this->authUser();
$this->authSuperAdmin();
Configure::write('debug', false);
$this->get('/pages/not_existing');
$this->assertResponseContains('Cette action est impossible');
}
/**
* Test that missing template in debug mode renders missing_template error page
*
* @return void
*/
public function OFF_testMissingTemplateInDebug()
{
//$this->authUser();
$this->authSuperAdmin();
//Configure::write('debug', true);
$this->get('/pages/not_existing');
$this->assertResponseContains("Désolé, vous n'êtes pas autorisé à accéder à cette zone");
$this->assertRedirect('/pages/home', 'Redirection vers home ne marche pas');
//$this->assertRedirect('/users/login?redirect=%2Fmateriels%2Findex', 'Problème : Accès à materiels/index SANS AUTHENTIFICATION');
/*
$this->assertResponseFailure();
$this->assertResponseContains('Missing Template');
$this->assertResponseContains('Stacktrace');
*/
}
}