2 Commits

Author SHA1 Message Date
  raphael 8fbbf46cb9 @fixed test unitaire 3 years ago
  raphael 21afbafd0f BGC-171 @fixed unit test 3 years ago

+ 10
- 4
.env.test View File

@@ -1,4 +1,10 @@
1
-# define your env variables for the test env here
2
-KERNEL_CLASS='Symfony\Component\HttpKernel\Kernel\AppKernel'
3
-APP_SECRET='s$cretf0rt3st'
4
-SYMFONY_DEPRECATIONS_HELPER=999999
1
+    APP_ENV=test
2
+    APP_URL_PREFIX="/phoenix"
3
+    APP_LANGUAGE="fr"
4
+
5
+    # define your env variables for the test env here
6
+    KERNEL_CLASS='Logipro\Phoenix\Kernel\AppKernel'
7
+    APP_SECRET='s$cretf0rt3st'
8
+    SYMFONY_DEPRECATIONS_HELPER=999999
9
+
10
+    DATABASE_TEST_URL="sqlite:///%kernel.project_dir%/var/app.db"

+ 5
- 0
composer.json View File

@@ -10,6 +10,11 @@
10 10
 			"Logipro\\Phoenix\\" : "src/Phoenix"
11 11
 		}
12 12
 	},
13
+	"autoload-dev": {
14
+        "psr-4": {
15
+            "Logipro\\Phoenix\\tests\\": "tests/"
16
+        }
17
+    },
13 18
 	"require" : {
14 19
 		"symfony/flex" : "~1.1",
15 20
 		"symfony/console" : "~4.0",

+ 6
- 1
src/Phoenix/Component/PhxCrypt.php View File

@@ -6,6 +6,11 @@ class PhxCrypt
6 6
     private static $cryptPassword = "__Pas.s:Word_!/_";
7 7
     private static $cryptIV = '1234567812345678';
8 8
 
9
+    protected static function serialize(array $data): string
10
+    {
11
+        return serialize($data);
12
+    }
13
+
9 14
     public static function crypt($data,$withDate = true)
10 15
     {
11 16
         if (is_string($data))
@@ -15,7 +20,7 @@ class PhxCrypt
15 20
         
16 21
         $data['_d_'] = time();
17 22
 
18
-        $data = serialize($data);
23
+        $data = self::serialize($data);
19 24
 		$openSslCrypt = openssl_encrypt($data, 'aes128',self::$cryptPassword,0,self::$cryptIV);
20 25
         return rtrim(strtr(($openSslCrypt), '+/', '-_'), '=');
21 26
     }

+ 75
- 100
src/Phoenix/Controller/Catalog/LoginController.php View File

@@ -1,4 +1,5 @@
1 1
 <?php
2
+
2 3
 namespace Logipro\Phoenix\Controller\Catalog;
3 4
 
4 5
 use Logipro\Phoenix\Events;
@@ -32,11 +33,11 @@ use Logipro\Phoenix\Service\LoginService;
32 33
 class LoginController extends CatalogController
33 34
 {
34 35
 	protected function phxRenderView(string $view, array $parameters = array()): string
35
-    {
36
-		$view = str_replace($this->viewPath,'',$view);
36
+	{
37
+		$view = str_replace($this->viewPath, '', $view);
37 38
 		$view = $this->viewPath . $view;
38 39
 
39
-		return parent::phxRenderView($view,$parameters);
40
+		return parent::phxRenderView($view, $parameters);
40 41
 	}
41 42
 
42 43
 	private function createLoginForm()
@@ -63,16 +64,16 @@ class LoginController extends CatalogController
63 64
 	private function createRecoverForm()
64 65
 	{
65 66
 		$formBuilder = $this->createFormBuilder();
66
-		
67
+
67 68
 		$formBuilder->add('username', TextType::class, array(
68
-			'required' => true, 
69
+			'required' => true,
69 70
 			'label_format' => 'catalog_recover_%id%'
70 71
 		));
71 72
 
72 73
 		return $formBuilder->getForm();
73 74
 	}
74 75
 
75
-	public function manageLogin(Request $request, UserPasswordEncoderInterface $passwordEncoder,SessionInterface $session)
76
+	public function manageLogin(Request $request, UserPasswordEncoderInterface $passwordEncoder, SessionInterface $session)
76 77
 	{
77 78
 		$continue = $request->request->get('continue');
78 79
 
@@ -80,7 +81,7 @@ class LoginController extends CatalogController
80 81
 
81 82
 		$formLogin = $this->createLoginForm();
82 83
 
83
-		$formSubscribe = $this->createForm(CatalogSubscribeType::class,$person); 
84
+		$formSubscribe = $this->createForm(CatalogSubscribeType::class, $person);
84 85
 
85 86
 		$formRecover = $this->createRecoverForm();
86 87
 
@@ -95,14 +96,13 @@ class LoginController extends CatalogController
95 96
 			"form_recover" => $formRecover->createView()
96 97
 		);
97 98
 
98
-		$html = $this->phxRenderView('layouts/partials/header/modal-login-content.html.twig',$renderVars);
99
+		$html = $this->phxRenderView('layouts/partials/header/modal-login-content.html.twig', $renderVars);
99 100
 
100 101
 		$response['html'] = $html;
101 102
 		$response['nav'] = $this->phxRenderView('layouts/partials/header/header.html.twig');
102
-		
103
+
103 104
 		$response['success'] = false;
104
-		if ($this->getUser())
105
-		{
105
+		if ($this->getUser()) {
106 106
 			$response['success'] = true;
107 107
 		}
108 108
 		$response['continue'] = $continue;
@@ -110,63 +110,56 @@ class LoginController extends CatalogController
110 110
 		return $this->json($response);
111 111
 	}
112 112
 
113
-	public function validateSubscribe(Request $request,LearnerAccountGenerator $accountGenerator,ValidatorInterface $validator, EventDispatcherInterface $eventDispatcher,LoginService $loginService)
113
+	public function validateSubscribe(Request $request, LearnerAccountGenerator $accountGenerator, ValidatorInterface $validator, EventDispatcherInterface $eventDispatcher, LoginService $loginService)
114 114
 	{
115 115
 		// si l'utilisateur est connecté => erreur
116
-		if ($this->getLearnerSpaceUser())
117
-		{
116
+		if ($this->getLearnerSpaceUser()) {
118 117
 			throw $this->createAccessDeniedException($this->translate('error_403_message'));
119 118
 		}
120
-		
119
+
121 120
 		$person = new Person();
122 121
 
123 122
 		$service = $this->get('phxSettings');
124 123
 		$person->setSociety($service->getDefaultSociety());
125 124
 
126
-		$formSubscribe = $this->createForm(CatalogSubscribeType::class,$person); 
125
+		$formSubscribe = $this->createForm(CatalogSubscribeType::class, $person);
127 126
 
128 127
 		$succes = $error = null;
129 128
 
130 129
 		$response = array();
131
-		try
132
-		{
133
-			if ($request->isMethod('POST'))
134
-			{
130
+		try {
131
+			if ($request->isMethod('POST')) {
135 132
 				$formSubscribe->handleRequest($request);
136 133
 
137 134
 				// valide l'objet distant et remonte l'erreur sur le formulaire d'origine
138 135
 				$result = $validator->validate($person->getLearnerAccount());
139 136
 				$learnerAccountField = $formSubscribe->get('learnerAccount');
140
-				foreach ($result as $error)
141
-				{
142
-					$this->addFormError($learnerAccountField->get($error->getPropertyPath()),$error->getMessage());
137
+				foreach ($result as $error) {
138
+					$this->addFormError($learnerAccountField->get($error->getPropertyPath()), $error->getMessage());
143 139
 				}
144 140
 
145 141
 				// test rgpd
146 142
 				$rgpdField = $formSubscribe->get('rgpd');
147
-				if (!$rgpdField->getData())
148
-				{
143
+				if (!$rgpdField->getData()) {
149 144
 					// ajoute une erreur sur le champ
150 145
 					$message = 'la case doit être cochée';
151
-					$this->addFormError($rgpdField,$message);
146
+					$this->addFormError($rgpdField, $message);
152 147
 				}
153 148
 
154 149
 				// test le mot de passe
155 150
 				$plainPasswordField = $learnerAccountField->get('plainPassword')->get('first');
156 151
 				$plainPassword = $plainPasswordField->getData();
157
-				$errorMsg = PasswordValidator::renderError($this->get('translator'),$this->get('phxSettings'),$plainPassword);
158
-				if ($errorMsg != '')
159
-				{
160
-					$this->addFormError($plainPasswordField,$errorMsg);
152
+				$errorMsg = PasswordValidator::renderError($this->get('translator'), $this->get('phxSettings'), $plainPassword);
153
+				if ($errorMsg != '') {
154
+					$this->addFormError($plainPasswordField, $errorMsg);
161 155
 				}
162 156
 
163
-				if ($formSubscribe->isSubmitted() && $formSubscribe->isValid())
164
-				{
157
+				if ($formSubscribe->isSubmitted() && $formSubscribe->isValid()) {
165 158
 					$learnerAccount = $accountGenerator->generateLearnerAccount($person);
166 159
 
167 160
 					//$learnerAccount = $person->getLearnerAccount();
168 161
 					$encoder = $this->get('security.password_encoder');
169
-					$learnerAccount->setPassword($encoder->encodePassword($learnerAccount,$plainPassword));
162
+					$learnerAccount->setPassword($encoder->encodePassword($learnerAccount, $plainPassword));
170 163
 					$learnerAccount->setUsername($learnerAccountField->get('username')->getData());
171 164
 					$learnerAccount->setStatus(EnumAccountStatusType::STATUS_ENABLED);
172 165
 					$person->setLearnerAccount($learnerAccount);
@@ -176,40 +169,34 @@ class LoginController extends CatalogController
176 169
 
177 170
 					$manager->persist($person);
178 171
 					$manager->persist($learnerAccount);
179
-					
172
+
180 173
 					$manager->flush();
181 174
 
182 175
 					// connecte l'utilisateur
183
-					$loginService->loginCatalogUser($learnerAccount,$plainPassword);
176
+					$loginService->loginCatalogUser($learnerAccount, $plainPassword);
184 177
 
185 178
 					// envoi l'email
186 179
 					$event = new GenericEvent($person);
187
-					$eventDispatcher->dispatch($event,Events::LEARNER_SUBSCRIBE);
180
+					$eventDispatcher->dispatch($event, Events::LEARNER_SUBSCRIBE);
188 181
 
189 182
 					$succes = true;
190
-				}
191
-				else
192
-				{
183
+				} else {
193 184
 					$errors = $this->getFormFieldError($formSubscribe);
194 185
 					throw $this->createNotFoundException($this->serializeFormFieldError($errors));
195 186
 				}
196 187
 			}
197
-		}
198
-		catch (\Exception $exp)
199
-		{
188
+		} catch (\Exception $exp) {
200 189
 			$succes = false;
201
-			
190
+
202 191
 			$errors = $this->getFormFieldError($formSubscribe);
203 192
 
204 193
 			$response['error'] = $exp->getMessage();
205 194
 			$response['formError'] = array();
206 195
 
207 196
 			// parcours les erreurs
208
-			foreach ($errors as $fieldId => $errorField)
209
-			{
197
+			foreach ($errors as $fieldId => $errorField) {
210 198
 				$message = $this->getFormFieldErrorMessage($errorField);
211
-				if ($message)
212
-				{
199
+				if ($message) {
213 200
 					$response['formError'][$fieldId] = $message;
214 201
 				}
215 202
 			}
@@ -224,36 +211,29 @@ class LoginController extends CatalogController
224 211
 
225 212
 	public function validateRecover(Request $request, EventDispatcherInterface $eventDispatcher)
226 213
 	{
227
-		if ($this->getLearnerSpaceUser())
228
-		{
214
+		if ($this->getLearnerSpaceUser()) {
229 215
 			throw $this->createErrorException($this->translate('error_recover_password_logged'));
230 216
 		}
231 217
 
232 218
 		$error = $succes = null;
233
-		try
234
-		{
235
-			if ($request->isMethod('POST'))
236
-			{
219
+		try {
220
+			if ($request->isMethod('POST')) {
237 221
 				$formRecover = $this->createRecoverForm();
238 222
 				$formRecover->handleRequest($request);
239
-				if ($formRecover->isSubmitted() && $formRecover->isValid())
240
-				{
223
+				if ($formRecover->isSubmitted() && $formRecover->isValid()) {
241 224
 					// cherche le compte
242 225
 					$learnerAccountRepository = $this->getRepository(LearnerAccount::class);
243 226
 					$learnerAccountSearch = $learnerAccountRepository->loadUserByUsername($formRecover->get('username')->getData());
244
-					if (!$learnerAccountSearch)
245
-					{
227
+					if (!$learnerAccountSearch) {
246 228
 						throw $this->createNotFoundException();
247 229
 					}
248 230
 
249 231
 					// déclanche l'événement du mail
250 232
 					$event = new GenericEvent($learnerAccountSearch);
251
-					$eventDispatcher->dispatch($event,Events::LEARNER_RECOVER_ON_CATALOG);
233
+					$eventDispatcher->dispatch($event, Events::LEARNER_RECOVER_ON_CATALOG);
252 234
 				}
253 235
 			}
254
-		}
255
-		catch (\Exception $exp)
256
-		{
236
+		} catch (\Exception $exp) {
257 237
 			$error = $exp->getMessage();
258 238
 		}
259 239
 
@@ -268,8 +248,7 @@ class LoginController extends CatalogController
268 248
 
269 249
 	public function validateLogout(Request $request)
270 250
 	{
271
-		if (!$this->getLearnerSpaceUser())
272
-		{
251
+		if (!$this->getLearnerSpaceUser()) {
273 252
 			throw $this->createAccessDeniedException($this->translate('error_403_message'));
274 253
 		}
275 254
 
@@ -281,89 +260,85 @@ class LoginController extends CatalogController
281 260
 		$session->set('_security_' . $name, null);
282 261
 		$session->save();
283 262
 
284
-//		$request->getSession()->invalidate();
263
+		//		$request->getSession()->invalidate();
285 264
 
286 265
 		$response['nav'] = $this->phxRenderView('layouts/partials/header/header.html.twig');
287 266
 		return $this->json($response);
288 267
 	}
289 268
 
290
-	public function manageDefinePassword(Request $request,LoginService $loginService)
269
+	public function manageDefinePassword(Request $request, LoginService $loginService)
291 270
 	{
292
-		if ($this->getLearnerSpaceUser())
293
-		{
271
+		if ($this->getLearnerSpaceUser()) {
294 272
 			throw $this->createErrorException($this->translate('error_recover_password_logged'));
295 273
 		}
296 274
 		$token = $request->get('token');
275
+		if (!$token) {
276
+			throw $this->createNotFoundException($this->translate('error_403_message'));
277
+		}
297 278
 
298 279
 		$tokenData = PasswordRecoverNotifyLearner::decrytUrlArg($token);
299 280
 		if (!$tokenData) {
300
-            // token expiré
301
-            $parameters = array(
302
-                'text' => $this->translate('catalog_password_expired'),
303
-                'path' => 'catalog_homepage',
304
-                'go' => $this->translate('catalog_password_return')
305
-            );
306
-            return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters);
281
+			$response = new Response('', 404);
282
+
283
+			// token expiré
284
+			$parameters = array(
285
+				'text' => $this->translate('catalog_password_expired'),
286
+				'path' => 'catalog_homepage',
287
+				'go' => $this->translate('catalog_password_return')
288
+			);
289
+			return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters,$response);
307 290
 		}
308
-		
291
+
309 292
 		$respository = $this->getRepository(LearnerAccount::class);
310 293
 		$learnerAccount = $respository->findOneBy(array('learnerAccountId' => $tokenData['learnerAccountId']));
311
-		if (!$learnerAccount)
312
-		{
294
+		if (!$learnerAccount) {
313 295
 			throw $this->createNotFoundException($this->translate('error_403_message'));
314 296
 		}
315
-		$form = $this->createForm(CatalogDefinePasswordType::class,$learnerAccount); 
297
+		$form = $this->createForm(CatalogDefinePasswordType::class, $learnerAccount);
316 298
 
317
-		try
318
-		{
319
-			if ($request->isMethod('POST'))
320
-			{
299
+		try {
300
+			if ($request->isMethod('POST')) {
321 301
 				$form->handleRequest($request);
322 302
 
323 303
 				// test le mot de passe
324 304
 				$plainPasswordField = $form->get('plainPassword')->get('first');
325 305
 				$plainPassword = $plainPasswordField->getData();
326
-				$errorMsg = PasswordValidator::renderError($this->get('translator'),$this->get('phxSettings'),$plainPassword);
327
-				if ($errorMsg != '')
328
-				{
329
-					$this->addFormError($plainPasswordField,$errorMsg);
306
+				$errorMsg = PasswordValidator::renderError($this->get('translator'), $this->get('phxSettings'), $plainPassword);
307
+				if ($errorMsg != '') {
308
+					$this->addFormError($plainPasswordField, $errorMsg);
330 309
 				}
331 310
 
332 311
 				// test le formulaire
333
-				if ($form->isSubmitted() && $form->isValid())
334
-				{
312
+				if ($form->isSubmitted() && $form->isValid()) {
335 313
 					$encoder = $this->get('security.password_encoder');
336
-					$learnerAccount->setPassword($encoder->encodePassword($learnerAccount,$plainPassword));
314
+					$learnerAccount->setPassword($encoder->encodePassword($learnerAccount, $plainPassword));
337 315
 
338 316
 					$manager = $this->getManager();
339 317
 					$manager->flush();
340 318
 
341 319
 					// logue l'utilisateur
342
-					$loginService->loginCatalogUser($learnerAccount,$plainPassword);
343
-					
320
+					$loginService->loginCatalogUser($learnerAccount, $plainPassword);
321
+
344 322
 					//$this->addFlash('success', "mot de passe redéfini");
345 323
 
346 324
 					// redirige sur le catalogue
347 325
 					$route = $tokenData['route'];
348
-					if ($route)
349
-					{
326
+					if ($route) {
350 327
 						$route = 'catalog_homepage';
351 328
 					}
352 329
 
353 330
 					$this->addFlash('success', $this->translate('new_password_defined'));
354
-					
331
+
355 332
 					return $this->redirectToRoute($route);
356 333
 				}
357 334
 			}
358
-		}
359
-		catch (\Exception $exp)
360
-		{
335
+		} catch (\Exception $exp) {
361 336
 			$error = $exp->getMessage();
362 337
 			$succes = false;
363 338
 		}
364 339
 
365 340
 		// affiche la vue pour définir le mot de passe
366
-		$parameters = array('token' => $token,'form' => $form->createView());
367
-		return $this->phxRender('catalog/pages/define_password.html.twig',$parameters);
341
+		$parameters = array('token' => $token, 'form' => $form->createView());
342
+		return $this->phxRender('catalog/pages/define_password.html.twig', $parameters);
368 343
 	}
369
-}
344
+}

+ 6
- 1
src/Phoenix/Controller/LearningSpace/LoginController.php View File

@@ -118,15 +118,20 @@ class LoginController extends LearningSpaceController
118 118
 		}
119 119
 		$token = $request->get('token');
120 120
 
121
+		if (!$token) {
122
+			throw $this->createNotFoundException($this->translate('error_403_message'));
123
+		}
124
+
121 125
 		$tokenData = PasswordRecoverNotifyLearner::decrytUrlArg($token);
122 126
 		if (!$tokenData) {
127
+			$response = new Response('', 404);
123 128
 			// token expiré
124 129
 			$parameters = array(
125 130
 				'text' => $this->translate('ls_password_expired'),
126 131
 				'path' => 'ls_homepage',
127 132
 				'go' => $this->translate('ls_password_return')
128 133
 			);
129
-			return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters);
134
+			return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters, $response);
130 135
 		}
131 136
 
132 137
 		$respository = $this->getRepository(LearnerAccount::class);

+ 6
- 1
src/Phoenix/Controller/NewBackOffice/Admin/LoginController.php View File

@@ -18,6 +18,7 @@ use Logipro\Phoenix\Entity\Account\LearnerAccount;
18 18
 use Symfony\Component\Security\Http\Firewall\ContextListener;
19 19
 use Symfony\Component\HttpKernel\KernelInterface;
20 20
 use Logipro\Phoenix\Service\LoginService;
21
+use Symfony\Component\HttpFoundation\Response;
21 22
 
22 23
 class LoginController extends BackOfficeAdminController
23 24
 {
@@ -120,16 +121,20 @@ class LoginController extends BackOfficeAdminController
120 121
             throw $this->createNotFoundException($this->translate('error_403_message'));
121 122
         }
122 123
         $token = $request->get('token');
124
+        if (!$token) {
125
+            throw $this->createNotFoundException($this->translate('error_403_message'));
126
+        }
123 127
 
124 128
         $tokenData = PasswordRecoverNotifyUser::decrytUrlArg($token);
125 129
         if (!$tokenData) {
130
+            $response = new Response('', 404);
126 131
             // token expiré
127 132
             $parameters = array(
128 133
                 'text' => $this->translate('bo_password_expired'),
129 134
                 'path' => 'bo_homepage',
130 135
                 'go' => $this->translate('back_homepage')
131 136
             );
132
-            return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters);
137
+            return $this->phxRender('bundles/TwigBundle/Exception/definePassword.html.twig', $parameters, $response);
133 138
         }
134 139
 
135 140
         $respository = $this->getRepository(User::class);

+ 14
- 0
tests/Phoenix/Component/ExpiredPhxCrypt.php View File

@@ -0,0 +1,14 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Component;
4
+
5
+use Logipro\Phoenix\Component\PhxCrypt;
6
+
7
+class ExpiredPhxCrypt extends PhxCrypt
8
+{
9
+    protected static function serialize(array $data):string
10
+    {
11
+        $data['_d_'] = 0;
12
+        return parent::serialize($data);
13
+    }
14
+}

+ 99
- 0
tests/Phoenix/Controller/LearningSpace/LoginControllerTest.php View File

@@ -0,0 +1,99 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice\Session\Follow;
4
+
5
+use Logipro\Phoenix\Component\PhxCrypt;
6
+use Logipro\Phoenix\tests\Phoenix\Component\ExpiredPhxCrypt;
7
+use Logipro\Phoenix\tests\PhxWebTestCase;
8
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
9
+
10
+
11
+class LoginControllerTest extends PhxWebTestCase
12
+{
13
+    /*
14
+    sera développé quand les fatory seront présents
15
+    public function testManageDefinePasswordWithUser()
16
+    { }*/
17
+
18
+    public function testManageDefinePasswordWithoutToken()
19
+    {
20
+        $client = static::createClient();
21
+
22
+        $params = array();
23
+        $crawler = $client->request(
24
+            'GET',
25
+            $this->getRoutePath('ls_password_define'),
26
+            $params
27
+        );
28
+
29
+        $this->assertSame(404, $client->getResponse()->getStatusCode());
30
+    }
31
+    public function testManageDefinePasswordWithEmptyToken()
32
+    {
33
+        $client = static::createClient();
34
+
35
+        $params = array(
36
+            'token' =>  ''
37
+        );
38
+        $crawler = $client->request(
39
+            'GET',
40
+            $this->getRoutePath('ls_password_define'),
41
+            $params
42
+        );
43
+
44
+        $this->assertSame(404, $client->getResponse()->getStatusCode());
45
+    }
46
+
47
+    public function testManageDefinePasswordWithoutLearner()
48
+    {
49
+        $client = static::createClient();
50
+
51
+        $params = array(
52
+            'token' =>  PhxCrypt::crypt(array(
53
+                'learnerAccountId' => 0,
54
+                'route' => 'ls_homepage'
55
+            ))
56
+        );
57
+        $crawler = $client->request(
58
+            'GET',
59
+            $this->getRoutePath('ls_password_define'),
60
+            $params
61
+        );
62
+
63
+        $this->assertSame(404, $client->getResponse()->getStatusCode());
64
+    }
65
+
66
+    public function testManageDefinePasswordWithExpiredToken()
67
+    {
68
+        $client = static::createClient();
69
+
70
+        $params = array(
71
+            'token' =>  ExpiredPhxCrypt::crypt(array(
72
+                'learnerAccountId' => 0,
73
+                'route' => 'ls_homepage'
74
+            ))
75
+        );
76
+        $crawler = $client->request(
77
+            'GET',
78
+            $this->getRoutePath('ls_password_define'),
79
+            $params
80
+        );
81
+
82
+        $this->assertSame(404, $client->getResponse()->getStatusCode());
83
+    }
84
+
85
+    /*
86
+    // A TERMINER IL Y A UN PB AVEC L'AUTHENTIFCATION
87
+    public function testList()
88
+    {
89
+        $client = static::createClient();
90
+
91
+        $crawler = $client->request(
92
+            'GET',
93
+            '/follow/sessions'
94
+        );
95
+
96
+        $this->assertSame(200, $client->getResponse()->getStatusCode());
97
+    }
98
+    */
99
+}

+ 6
- 6
tests/Phoenix/Controller/NewBackOffice/Session/Follow/SessionFixedControllerTest.php View File

@@ -1,11 +1,12 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Controller\NewBackOffice\Session\Follow;
3 2
 
4
-use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
3
+namespace Logipro\Phoenix\tests\Phoenix\Controller\NewBackOffice\Session\Follow;
5 4
 
5
+use Logipro\Phoenix\tests\PhxWebTestCase;
6 6
 
7
-class SessionFiexedControllerTest extends WebTestCase
8
-{  
7
+
8
+class SessionFiexedControllerTest extends PhxWebTestCase
9
+{
9 10
 
10 11
     /*
11 12
     // A TERMINER IL Y A UN PB AVEC L'AUTHENTIFCATION
@@ -20,5 +21,4 @@ class SessionFiexedControllerTest extends WebTestCase
20 21
 
21 22
         $this->assertSame(200, $client->getResponse()->getStatusCode());
22 23
     }
23
-    */   
24
-}
24
+    */ }

+ 29
- 19
tests/Phoenix/Service/Comment/CommentHandlerTest.php View File

@@ -1,5 +1,6 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Service\Comment;
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Service\Comment;
3 4
 
4 5
 use PHPUnit\Framework\TestCase;
5 6
 use Logipro\Phoenix\Entity\Comment;
@@ -16,26 +17,28 @@ use Twig\Environment;
16 17
 use Doctrine\ORM\EntityManagerInterface;
17 18
 use Symfony\Component\Security\Core\Security;
18 19
 
20
+use Logipro\Phoenix\Service\Session\SessionHandler;
21
+
19 22
 class CommentHandlerTest extends TestCase
20
-{	
23
+{
21 24
 	private $comment;
22 25
 	private $session;
23 26
 	private $person;
24 27
 
25 28
 
26
-    private $entityManager;
29
+	private $entityManager;
27 30
 
28
-    public function setUp()
29
-    {
31
+	public function setUp()
32
+	{
30 33
 		$this->person = new Person();
31 34
 		$this->person->setGivenName('Laurent');
32 35
 
33
-        $this->session = new SessionOpen();
36
+		$this->session = new SessionOpen();
34 37
 		$this->session->setTitle('Test CommentHandlerTest');
35 38
 
36 39
 		$this->comment = new Comment($this->person);
37 40
 		$this->comment->setContent('Mon commentaire');
38
-		$this->comment->setSession($this->session);	
41
+		$this->comment->setSession($this->session);
39 42
 	}
40 43
 
41 44
 	/**
@@ -54,10 +57,11 @@ class CommentHandlerTest extends TestCase
54 57
 		$translator = $this->createMock(TranslatorInterface::class);
55 58
 		$templing = $this->createMock(Environment::class);
56 59
 		$security = $this->createMock(Security::class);
60
+		$sessionHandler = $this->createMock(SessionHandler::class);
57 61
 
58
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
59
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
60
-	}		
62
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
63
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
64
+	}
61 65
 
62 66
 	/**
63 67
 	 * Test pour verifier que le mail nouveau commentaire ne soit pas envoyé si l'option notifyMailForum est à false
@@ -75,8 +79,10 @@ class CommentHandlerTest extends TestCase
75 79
 		$templing = $this->createMock(Environment::class);
76 80
 		$security = $this->createMock(Security::class);
77 81
 
78
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
79
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
82
+		$sessionHandler = $this->createMock(SessionHandler::class);
83
+
84
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
85
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
80 86
 	}
81 87
 
82 88
 
@@ -96,9 +102,11 @@ class CommentHandlerTest extends TestCase
96 102
 		$templing = $this->createMock(Environment::class);
97 103
 		$security = $this->createMock(Security::class);
98 104
 
99
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
100
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
101
-	}	
105
+		$sessionHandler = $this->createMock(SessionHandler::class);
106
+
107
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
108
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
109
+	}
102 110
 
103 111
 	/**
104 112
 	 * Test pour verifier que le mail nouveau commentaire ne soit pas envoyé si il n'y a pas de responsable pédagogique
@@ -116,7 +124,9 @@ class CommentHandlerTest extends TestCase
116 124
 		$templing = $this->createMock(Environment::class);
117 125
 		$security = $this->createMock(Security::class);
118 126
 
119
-		$commentHandler = new CommentHandler($dispatcher,$entityManager,$translator,$templing,$security);
120
-		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');	
121
-	}	
122
-}
127
+		$sessionHandler = $this->createMock(SessionHandler::class);
128
+
129
+		$commentHandler = new CommentHandler($dispatcher, $entityManager, $translator, $templing, $security, $sessionHandler);
130
+		$commentHandler->sendNotificationNewComment($this->comment, $this->session, 'session');
131
+	}
132
+}

+ 19
- 17
tests/Phoenix/Service/FormHandlerTest.php View File

@@ -1,5 +1,6 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Service;
2
+
3
+namespace Logipro\Phoenix\tests\Phoenix\Service;
3 4
 
4 5
 use Symfony\Component\Form\Test\TypeTestCase;
5 6
 
@@ -12,35 +13,36 @@ use Symfony\Component\Form\FormError;
12 13
 use Logipro\Phoenix\Service\FormHandler;
13 14
 use Symfony\Component\HttpFoundation\RequestStack;
14 15
 use Symfony\Component\HttpFoundation\Request;
16
+use Symfony\Component\Form\FormFactoryInterface;
15 17
 
16 18
 class FormHandlerTest extends TypeTestCase
17 19
 {
18
-	private function generateHandler(bool $isMethod = true) : FormHandler
20
+	private function generateHandler(bool $isMethod = true): FormHandler
19 21
 	{
20 22
 		$requestStackMock = $this->createMock(RequestStack::class);
21
-		
23
+
22 24
 		$request = $this->createMock(Request::class);
23 25
 		$request->method('isMethod')->willReturn($isMethod);
24
-		
26
+
25 27
 		$requestStackMock->method('getCurrentRequest')->willReturn($request);
26
-		
28
+
27 29
 		$trnaslatorMock = $this->createMock(TranslatorInterface::class);
28
-		
29
-		return new FormHandler($requestStackMock,$trnaslatorMock);
30
+		$factoryMock = $this->createMock(FormFactoryInterface::class);
30 31
 
32
+		return new FormHandler($requestStackMock, $trnaslatorMock, $factoryMock);
31 33
 	}
32
-    public function testGetFormFieldError()
33
-    {
34
+	public function testGetFormFieldError()
35
+	{
34 36
 		$handler = $this->generateHandler();
35 37
 
36 38
 		$form = $this->factory->createBuilder(FormType::class)
37 39
 			->add('task', TextType::class)
38 40
 			->getForm();
39 41
 
40
-		$newError = new FormError('','');
42
+		$newError = new FormError('', '');
41 43
 		$taskField = $form->get('task');
42 44
 		// soumettre le formulaire sinon la validation ne se fait pas
43
-		$form->submit(array('task' => 'Fabien'),false);
45
+		$form->submit(array('task' => 'Fabien'), false);
44 46
 		$taskField->addError($newError);
45 47
 
46 48
 		$errors = $handler->getFormFieldError($form);
@@ -57,7 +59,7 @@ class FormHandlerTest extends TypeTestCase
57 59
 			$form
58 60
 		);
59 61
 	}
60
-	
62
+
61 63
 	/**
62 64
 	 * @expectedException \Exception
63 65
 	 *
@@ -68,13 +70,13 @@ class FormHandlerTest extends TypeTestCase
68 70
 		$handler = $this->generateHandler();
69 71
 
70 72
 		$form = $this->factory->createBuilder(FormType::class)
71
-		->add('task', TextType::class)
72
-		->getForm();
73
+			->add('task', TextType::class)
74
+			->getForm();
73 75
 
74
-		$newError = new FormError('','');
76
+		$newError = new FormError('', '');
75 77
 		$taskField = $form->get('task');
76 78
 		// soumettre le formulaire sinon la validation ne se fait pas
77
-		$form->submit(array('task' => 'Fabien'),false);
79
+		$form->submit(array('task' => 'Fabien'), false);
78 80
 		$taskField->addError($newError);
79 81
 
80 82
 		$handler->validForm($form);
@@ -94,4 +96,4 @@ class FormHandlerTest extends TypeTestCase
94 96
 
95 97
 		$handler->validate($form);
96 98
 	}
97
-}
99
+}

+ 1
- 1
tests/Phoenix/Tools/Tree/TreeWalkerTest.php View File

@@ -1,5 +1,5 @@
1 1
 <?php
2
-namespace Logipro\Phoenix\Tests\Tools\Tree;
2
+namespace Logipro\Phoenix\tests\Phoenix\Tools\Tree;
3 3
 
4 4
 use PHPUnit\Framework\TestCase;
5 5
 use Logipro\Phoenix\Tools\Tree\TreeNode;

+ 22
- 0
tests/PhxWebTestCase.php View File

@@ -0,0 +1,22 @@
1
+<?php
2
+
3
+namespace Logipro\Phoenix\tests;
4
+
5
+use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
6
+use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
7
+
8
+class PhxWebTestCase extends WebTestCase
9
+{
10
+    protected function getRoutePath(string $path): string
11
+    {
12
+        self::bootKernel();
13
+
14
+        $container = self::$kernel->getContainer();
15
+
16
+        $route = $container->get('router')->getRouteCollection()->get($path);
17
+        if (!$route) {
18
+            throw new NotFoundHttpException();
19
+        }
20
+        return $route->getPath();
21
+    }
22
+}

Loading…
Cancel
Save