symfony - get('security.context')->isGranted in functional test -


i want 1 functional test on over service symfony2. idea call before controller , after that, load service function. function one:

function save($title,$description,$setid,$html,$validate,$articles){     $articles = explode(',', $articles);      if (false === $this->container->get('security.context')->isgranted('role_user')) {         throw new \exception("not allowed");     }else{         $profileid  = $this->container->get('security.context')->gettoken()->getuser()->getid();         $username   = $this->container->get('security.context')->gettoken()->getuser()->getusername();     } } 

and test code :

    $client = static::createclient();      $crawler = $client->request('get','/sets/save',             array(                     "title"=>"rtyui",                     "description"=>"aksdjhashdkjahskjdh",                     "set_id"=>"",                     "html"=>"",                     "validate"=>1,                     "articels"=>"3,4"                 )         );  

but doesn't work have lines:

if (false === $this->container->get('security.context')->isgranted('role_user')) {         throw new \exception("not allowed"); 

now, question is, how can validation process? i've tried validation process show documentation:

$client = static::createclient(array(), array(     'php_auth_user' => 'username',     'php_auth_pw'   => 'pa$$word', )); 

but got same error.

also can login user security token:

$client = static::createclient(); $container = $client->getcontainer(); $container->get('security.context')->settoken(     new usernamepasswordtoken(         $user, null, 'main', $user->getroles()     ) ); 

where:

  1. $user - instance of user entity role role_user,
  2. main - security provider name

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -