From 91e6dc9fef6926b42c0b391b67ca630c2399a8a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20H=C3=A9rault?= Date: Sun, 26 Jun 2011 11:28:17 +0200 Subject: [PATCH] [Security] Add tests for the anonymous authentication listener --- .../AnonymousAuthenticationListenerTest.php | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 tests/Symfony/Tests/Component/Security/Http/Firewall/AnonymousAuthenticationListenerTest.php diff --git a/tests/Symfony/Tests/Component/Security/Http/Firewall/AnonymousAuthenticationListenerTest.php b/tests/Symfony/Tests/Component/Security/Http/Firewall/AnonymousAuthenticationListenerTest.php new file mode 100644 index 0000000000..dad7f8a765 --- /dev/null +++ b/tests/Symfony/Tests/Component/Security/Http/Firewall/AnonymousAuthenticationListenerTest.php @@ -0,0 +1,46 @@ +getMock('Symfony\Component\Security\Core\SecurityContextInterface'); + $context + ->expects($this->any()) + ->method('getToken') + ->will($this->returnValue($this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'))) + ; + $context + ->expects($this->never()) + ->method('setToken') + ; + + $listener = new AnonymousAuthenticationListener($context, 'TheKey'); + $listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false)); + } + + public function testHandleWithContextHavingNoToken() + { + $context = $this->getMock('Symfony\Component\Security\Core\SecurityContextInterface'); + $context + ->expects($this->any()) + ->method('getToken') + ->will($this->returnValue(null)) + ; + $context + ->expects($this->once()) + ->method('setToken') + ->with(self::logicalAnd( + $this->isInstanceOf('Symfony\Component\Security\Core\Authentication\Token\AnonymousToken'), + $this->attributeEqualTo('key', 'TheKey') + )) + ; + + $listener = new AnonymousAuthenticationListener($context, 'TheKey'); + $listener->handle($this->getMock('Symfony\Component\HttpKernel\Event\GetResponseEvent', array(), array(), '', false)); + } +}