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:
$user- instance of user entity rolerole_user,main- security provider name
Comments
Post a Comment