diff --git a/documentation.md b/documentation.md index a7cbf282..dd58e865 100644 --- a/documentation.md +++ b/documentation.md @@ -361,6 +361,20 @@ For checking the raw source code, use `seeInSource()`. * `param array|string` $selector optional +### dontSeeAuthentication + +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(); +$I->dontSeeAuthentication(false); +``` + + * `param bool` $remembered + + ### dontSeeCheckboxIsChecked Check that the specified checkbox is unchecked. diff --git a/src/Codeception/Module/Symfony.php b/src/Codeception/Module/Symfony.php index 39756533..1c9e4e0c 100644 --- a/src/Codeception/Module/Symfony.php +++ b/src/Codeception/Module/Symfony.php @@ -770,4 +770,38 @@ private function getPossibleKernelClasses() return [$this->config['kernel_class']]; } + + /** + * 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($remembered = true) + { + $container = $this->_getContainer(); + + if (!$container->has('security.helper')) { + $this->fail("Symfony container doesn't have 'security.helper' service"); + return; + } + + $security = $this->grabService('security.helper'); + + if ($remembered) { + $role = 'IS_AUTHENTICATED_REMEMBERED'; + } else { + $role = 'IS_AUTHENTICATED_FULLY'; + } + + $this->assertFalse( + $security->isGranted($role), + 'There is an user authenticated' + ); + } }