diff options
author | Jakub Zalas <jakub@zalas.pl> | 2013-05-20 15:27:53 +0100 |
---|---|---|
committer | Jakub Zalas <jakub@zalas.pl> | 2013-05-24 18:27:56 +0100 |
commit | 2115c942f097b45ab66a5fea457915e104573432 (patch) | |
tree | a1bb5c3df3ca11dfe484f2ac076a772d61ba10d5 /Tests/Http | |
parent | ce48be1189801b36a6ed444264611d9ade9c98dc (diff) | |
download | symfony-security-2115c942f097b45ab66a5fea457915e104573432.zip symfony-security-2115c942f097b45ab66a5fea457915e104573432.tar.gz symfony-security-2115c942f097b45ab66a5fea457915e104573432.tar.bz2 |
[Security] Added tests for the SessionAuthenticationStrategy.
Diffstat (limited to 'Tests/Http')
-rw-r--r-- | Tests/Http/Session/SessionAuthenticationStrategyTest.php | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/Tests/Http/Session/SessionAuthenticationStrategyTest.php b/Tests/Http/Session/SessionAuthenticationStrategyTest.php new file mode 100644 index 0000000..896d6ad --- /dev/null +++ b/Tests/Http/Session/SessionAuthenticationStrategyTest.php @@ -0,0 +1,80 @@ +<?php + +/* + * This file is part of the Symfony package. + * + * (c) Fabien Potencier <fabien@symfony.com> + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Symfony\Component\Security\Tests\Http\Session; + +use Symfony\Component\Security\Http\Session\SessionAuthenticationStrategy; + +class SessionAuthenticationStrategyTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Symfony\Component\HttpFoundation\Request')) { + $this->markTestSkipped('The "HttpFoundation" component is not available'); + } + } + + public function testSessionIsNotChanged() + { + $request = $this->getRequest(); + $request->expects($this->never())->method('getSession'); + + $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::NONE); + $strategy->onAuthentication($request, $this->getToken()); + } + + /** + * @expectedException \RuntimeException + * @expectedExceptionMessage Invalid session authentication strategy "foo" + */ + public function testUnsupportedStrategy() + { + $request = $this->getRequest(); + $request->expects($this->never())->method('getSession'); + + $strategy = new SessionAuthenticationStrategy('foo'); + $strategy->onAuthentication($request, $this->getToken()); + } + + public function testSessionIsMigrated() + { + $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); + $session->expects($this->once())->method('migrate'); + + $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::MIGRATE); + $strategy->onAuthentication($this->getRequest($session), $this->getToken()); + } + + public function testSessionIsInvalidated() + { + $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface'); + $session->expects($this->once())->method('invalidate'); + + $strategy = new SessionAuthenticationStrategy(SessionAuthenticationStrategy::INVALIDATE); + $strategy->onAuthentication($this->getRequest($session), $this->getToken()); + } + + private function getRequest($session = null) + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + + if (!is_null($session)) { + $request->expects($this->any())->method('getSession')->will($this->returnValue($session)); + } + + return $request; + } + + private function getToken() + { + return $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface'); + } +} |