From 175cc74921e411872fef3abce78e6287ad3eecec Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Wed, 9 Dec 2020 18:11:12 -0500 Subject: [PATCH 1/3] Remove param flags from SeeAuthentication methods --- src/Codeception/Module/Symfony.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index c228fe78..5e268ef9 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -979,17 +979,13 @@ public function amOnAction(string $action, array $params = []) /** * Checks that a user is authenticated. - * You can check users logged in with the option 'remember me' passing true as parameter. * * ```php * seeAuthentication(); - * $I->seeAuthentication(true); * ``` - * - * @param bool $remembered */ - public function seeAuthentication(bool $remembered = false) + public function seeAuthentication() { $security = $this->grabService('security.helper'); @@ -999,9 +995,7 @@ public function seeAuthentication(bool $remembered = false) $this->fail('There is no user in session'); } - $role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY'; - - $this->assertTrue($security->isGranted($role), 'There is no authenticated user'); + $this->assertTrue($security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is no authenticated user'); } /** @@ -1067,23 +1061,18 @@ public function seeUserHasRole(string $role) /** * Check that user is not authenticated. - * You can specify whether users logged in with the 'remember me' option should be ignored by passing 'false' as a parameter. * * ```php * dontSeeAuthentication(); * ``` - * - * @param bool $remembered */ - public function dontSeeAuthentication(bool $remembered = true) + public function dontSeeAuthentication() { $security = $this->grabService('security.helper'); - $role = $remembered ? 'IS_AUTHENTICATED_REMEMBERED' : 'IS_AUTHENTICATED_FULLY'; - $this->assertFalse( - $security->isGranted($role), + $security->isGranted('IS_AUTHENTICATED_FULLY'), 'There is an user authenticated' ); } From 3f41dd60686e8a98c080a84d1ed6d0b3f3361cb8 Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Wed, 9 Dec 2020 18:12:31 -0500 Subject: [PATCH 2/3] Added seeRememberedAuthentication function --- src/Codeception/Module/Symfony.php | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 5e268ef9..831dc248 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -1029,6 +1029,27 @@ public function submitSymfonyForm(string $name, array $fields) $this->submitForm($selector, $params, $button); } + /** + * Checks that a user is authenticated with the 'remember me' option. + * + * ```php + * seeRememberedAuthentication(); + * ``` + */ + public function seeRememberedAuthentication() + { + $security = $this->grabService('security.helper'); + + $user = $security->getUser(); + + if (!$user) { + $this->fail('There is no user in session'); + } + + $this->assertTrue($security->isGranted('IS_AUTHENTICATED_REMEMBERED'), 'There is no authenticated user'); + } + /** * Check that the current user has a role * From 59628ba913a3ea361790c94bc6ada8768432b25a Mon Sep 17 00:00:00 2001 From: Tavo Nieves J Date: Wed, 9 Dec 2020 18:12:55 -0500 Subject: [PATCH 3/3] Added dontSeeRememberedAuthentication function --- src/Codeception/Module/Symfony.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 831dc248..388a2e60 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -1050,6 +1050,24 @@ public function seeRememberedAuthentication() $this->assertTrue($security->isGranted('IS_AUTHENTICATED_REMEMBERED'), 'There is no authenticated user'); } + /** + * Check that user is not authenticated with the 'remember me' option. + * + * ```php + * dontSeeRememberedAuthentication(); + * ``` + */ + public function dontSeeRememberedAuthentication() + { + $security = $this->grabService('security.helper'); + + $this->assertFalse( + $security->isGranted('IS_AUTHENTICATED_REMEMBERED'), + 'There is an user authenticated' + ); + } + /** * Check that the current user has a role *