Scenario: A user has a default role when he's logged in
Given I am logged in as User
Then I should have a "ROLE_USER" role
/**
* @Given /^(?:|I )am logged in as User$/
*/
public function IAmLoggedInAsUser()
{
return array(
new Step\When('I am on "/login"'),
new Step\When('I fill in "username" with "user"'),
new Step\When('I fill in "password" with "password"'),
new Step\When('I press "submit_login"'),
new Step\Then('I have a token for "user" User')
);
}
/**
* @Then /^(?:|I) have a token for "([^"]*)" User$/
*/
public function IHaveATokenForUser($user)
{
$user = $this->getRepository('HoverflySecurityBundle:User')->findOneByUsername($user);
$context = $this->getContainer()->get('security.context');
$provider = 'hoverflyers';
$token = new UsernamePasswordToken($user, null, $provider, $user->getRoles());
$context->setToken($token);
}
/**
* @Then /I should have a "([^"]*)" role/
*/
public function iShouldHaveARole($role)
{
$user = $this->getContainer()->get('security.context')->getToken()->getUser();
assertTrue(in_array($role, $user->getRoles()));
}
Is it the right way ?
how well i've copy pasted from my blog in draft mode. the css is from the twitter bootstrap. i use only the <code> tags in the html.
how well i've copy pasted from my blog in draft mode. the css is from the twitter bootstrap. i use only the <code> tags in the html.
Le 11 avr. 2012 18:30, "Luis Cordova" <cord...@gmail.com> a écrit :
how can you copy paste such nice code, what tool are you using?
Hi.
Yes I found a solution. In fact you can log in your user manually by generating the token.
I do not have the code here right now, ill send you when im at home this evening