diff -r 000000000000 -r 7f95f8617b0b vendor/bundles/JMS/SecurityExtraBundle/Tests/Security/Authentication/Provider/RunAsAuthenticationProviderTest.php --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/vendor/bundles/JMS/SecurityExtraBundle/Tests/Security/Authentication/Provider/RunAsAuthenticationProviderTest.php Sat Sep 24 15:40:41 2011 +0200 @@ -0,0 +1,70 @@ +GetMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + + $this->assertNull($provider->authenticate($token)); + } + + /** + * @expectedException Symfony\Component\Security\Core\Exception\BadCredentialsException + */ + public function testAuthenticateThrowsExceptionWhenKeysDontMatch() + { + $provider = new RunAsAuthenticationProvider('foo'); + $token = $this->getSupportedToken(); + $token + ->expects($this->once()) + ->method('getKey') + ->will($this->returnValue('moo')) + ; + + $provider->authenticate($token); + } + + public function testAuthenticate() + { + $provider = new RunAsAuthenticationProvider('foo'); + $token = $this->getSupportedToken(); + $token + ->expects($this->once()) + ->method('getKey') + ->will($this->returnValue('foo')) + ; + + $this->assertSame($token, $provider->authenticate($token)); + } + + public function testSupportsDoesNotAcceptInvalidToken() + { + $provider = new RunAsAuthenticationProvider('foo'); + $token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + + $this->assertFalse($provider->supports($token)); + } + + public function testSupports() + { + $provider = new RunAsAuthenticationProvider('foo'); + + $token = $this->getSupportedToken(); + $this->assertTrue($provider->supports($token)); + } + + protected function getSupportedToken() + { + return $this->getMockBuilder('JMS\SecurityExtraBundle\Security\Authentication\Token\RunAsUserToken') + ->disableOriginalConstructor() + ->getMock(); + } +} \ No newline at end of file