summaryrefslogtreecommitdiffstats
path: root/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
diff options
context:
space:
mode:
authorBernhard Schussek <bschussek@gmail.com>2013-09-16 10:03:00 +0200
committerFabien Potencier <fabien.potencier@gmail.com>2013-09-18 09:16:41 +0200
commit5a6aaab2c35213f5ca7e57f061fbb2675e2ece35 (patch)
tree461816fef8160401dc113d3fef190fb437d01cc7 /Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
parent513a354be10f0ed87933adcb788e48660f8e6ed4 (diff)
downloadsymfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.zip
symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.gz
symfony-security-5a6aaab2c35213f5ca7e57f061fbb2675e2ece35.tar.bz2
[Security] Split the component into 3 sub-components Core, ACL, HTTP
Diffstat (limited to 'Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php')
-rw-r--r--Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php169
1 files changed, 0 insertions, 169 deletions
diff --git a/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php b/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
deleted file mode 100644
index 3ba6a17..0000000
--- a/Tests/Http/Authentication/DefaultAuthenticationSuccessHandlerTest.php
+++ /dev/null
@@ -1,169 +0,0 @@
-<?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;
-
-use Symfony\Component\Security\Http\Authentication\DefaultAuthenticationSuccessHandler;
-
-class DefaultAuthenticationSuccessHandlerTest extends \PHPUnit_Framework_TestCase
-{
- private $httpUtils = null;
-
- private $request = null;
-
- private $token = null;
-
- protected function setUp()
- {
- $this->httpUtils = $this->getMock('Symfony\Component\Security\Http\HttpUtils');
- $this->request = $this->getMock('Symfony\Component\HttpFoundation\Request');
- $this->request->headers = $this->getMock('Symfony\Component\HttpFoundation\HeaderBag');
- $this->token = $this->getMock('Symfony\Component\Security\Core\Authentication\Token\TokenInterface');
- }
-
- public function testRequestIsRedirected()
- {
- $response = $this->expectRedirectResponse('/');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testDefaultTargetPathCanBeForced()
- {
- $options = array(
- 'always_use_default_target_path' => true,
- 'default_target_path' => '/dashboard'
- );
-
- $response = $this->expectRedirectResponse('/dashboard');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testTargetPathIsPassedWithRequest()
- {
- $this->request->expects($this->once())
- ->method('get')->with('_target_path')
- ->will($this->returnValue('/dashboard'));
-
- $response = $this->expectRedirectResponse('/dashboard');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testTargetPathParameterIsCustomised()
- {
- $options = array('target_path_parameter' => '_my_target_path');
-
- $this->request->expects($this->once())
- ->method('get')->with('_my_target_path')
- ->will($this->returnValue('/dashboard'));
-
- $response = $this->expectRedirectResponse('/dashboard');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testTargetPathIsTakenFromTheSession()
- {
- $session = $this->getMock('Symfony\Component\HttpFoundation\Session\SessionInterface');
- $session->expects($this->once())
- ->method('get')->with('_security.admin.target_path')
- ->will($this->returnValue('/admin/dashboard'));
- $session->expects($this->once())
- ->method('remove')->with('_security.admin.target_path');
-
- $this->request->expects($this->any())
- ->method('getSession')
- ->will($this->returnValue($session));
-
- $response = $this->expectRedirectResponse('/admin/dashboard');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
- $handler->setProviderKey('admin');
-
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testTargetPathIsPassedAsReferer()
- {
- $options = array('use_referer' => true);
-
- $this->request->headers->expects($this->once())
- ->method('get')->with('Referer')
- ->will($this->returnValue('/dashboard'));
-
- $response = $this->expectRedirectResponse('/dashboard');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testRefererHasToBeDifferentThatLoginUrl()
- {
- $options = array('use_referer' => true);
-
- $this->request->headers->expects($this->any())
- ->method('get')->with('Referer')
- ->will($this->returnValue('/login'));
-
- $this->httpUtils->expects($this->once())
- ->method('generateUri')->with($this->request, '/login')
- ->will($this->returnValue('/login'));
-
- $response = $this->expectRedirectResponse('/');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, $options);
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- public function testRefererTargetPathIsIgnoredByDefault()
- {
- $this->request->headers->expects($this->never())->method('get');
-
- $response = $this->expectRedirectResponse('/');
-
- $handler = new DefaultAuthenticationSuccessHandler($this->httpUtils, array());
- $result = $handler->onAuthenticationSuccess($this->request, $this->token);
-
- $this->assertSame($response, $result);
- }
-
- private function expectRedirectResponse($path)
- {
- $response = $this->getMock('Symfony\Component\HttpFoundation\Response');
-
- $this->httpUtils->expects($this->once())
- ->method('createRedirectResponse')
- ->with($this->request, $path)
- ->will($this->returnValue($response));
-
- return $response;
- }
-}