Skip to content

Commit 321ef5e

Browse files
TavoNiievezNaktibalda
authored andcommitted
Added dontSeeAuthentication function
1 parent 3c65247 commit 321ef5e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

documentation.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,20 @@ For checking the raw source code, use `seeInSource()`.
376376
* `param array|string` $selector optional
377377

378378

379+
### dontSeeAuthentication
380+
381+
Check that user is not authenticated.
382+
You can specify whether users logged in with the 'remember me' option should be ignored by passing 'false' as a parameter.
383+
384+
```php
385+
<?php
386+
$I->dontSeeAuthentication();
387+
$I->dontSeeAuthentication(false);
388+
```
389+
390+
* `param bool` $remembered
391+
392+
379393
### dontSeeCheckboxIsChecked
380394

381395
Check that the specified checkbox is unchecked.

src/Codeception/Module/Symfony.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,4 +998,38 @@ public function seeUserHasRole($role)
998998
)
999999
);
10001000
}
1001+
1002+
/**
1003+
* Check that user is not authenticated.
1004+
* You can specify whether users logged in with the 'remember me' option should be ignored by passing 'false' as a parameter.
1005+
*
1006+
* ```php
1007+
* <?php
1008+
* $I->dontSeeAuthentication();
1009+
* ```
1010+
*
1011+
* @param bool $remembered
1012+
*/
1013+
public function dontSeeAuthentication($remembered = true)
1014+
{
1015+
$container = $this->_getContainer();
1016+
1017+
if (!$container->has('security.helper')) {
1018+
$this->fail("Symfony container doesn't have 'security.helper' service");
1019+
return;
1020+
}
1021+
1022+
$security = $this->grabService('security.helper');
1023+
1024+
if ($remembered) {
1025+
$role = 'IS_AUTHENTICATED_REMEMBERED';
1026+
} else {
1027+
$role = 'IS_AUTHENTICATED_FULLY';
1028+
}
1029+
1030+
$this->assertFalse(
1031+
$security->isGranted($role),
1032+
'There is an user authenticated'
1033+
);
1034+
}
10011035
}

0 commit comments

Comments
 (0)