コード例 #1
0
 public function testVote()
 {
     $manager = $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface');
     $manager->expects($this->once())->method('decide')->will($this->returnValue(false));
     $context = new SecurityContext($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface'), $manager);
     $context->setToken($token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'));
     $token->expects($this->once())->method('isAuthenticated')->will($this->returnValue(true));
     $this->assertFalse($context->vote('ROLE_FOO'));
     $manager = $this->getMock('Symfony\\Component\\Security\\Core\\Authorization\\AccessDecisionManagerInterface');
     $manager->expects($this->once())->method('decide')->will($this->returnValue(true));
     $context = new SecurityContext($this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\AuthenticationManagerInterface'), $manager);
     $context->setToken($token = $this->getMock('Symfony\\Component\\Security\\Core\\Authentication\\Token\\TokenInterface'));
     $token->expects($this->once())->method('isAuthenticated')->will($this->returnValue(true));
     $this->assertTrue($context->vote('ROLE_FOO'));
 }