8000 Remove param flags from authentication methods by TavoNiievez · Pull Request #70 · Codeception/module-symfony · GitHub
[go: up one dir, main page]

Skip to content

Remove param flags from authentication methods #70

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Dec 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 43 additions & 15 deletions src/Codeception/Module/Symfony.php
BB3C
Original file line number Diff line number Diff line change
Expand Up @@ -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
* <?php
* $I->seeAuthentication();
* $I->seeAuthentication(true);
* ```
*
* @param bool $remembered
*/
public function seeAuthentication(bool $remembered = false)
public function seeAuthentication()
{
$security = $this->grabService('security.helper');

Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -1035,6 +1029,45 @@ public function submitSymfonyForm(string $name, array $fields)
$this->submitForm($selector, $params, $button);
}

/**
* Checks that a user is authenticated with the 'remember me' option.
*
* ```php
* <?php
* $I->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 user is not authenticated with the 'remember me' option.
*
* ```php
* <?php
* $I->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
*
Expand Down Expand Up @@ -1067,23 +1100,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
* <?php
* $I->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'
);
}
Expand Down
0