diff options
author | Ryan Weaver <ryan@thatsquality.com> | 2016-02-06 17:29:58 -0500 |
---|---|---|
committer | Fabien Potencier <fabien.potencier@gmail.com> | 2016-03-02 13:34:27 +0100 |
commit | 0d6c99afcc9f9392a4eea87caa9b197f176d54b7 (patch) | |
tree | 3a1cb28f5513b7e3b19394aabf624fe138915824 /Http/Tests/Util/TargetPathTraitTest.php | |
parent | a07df7b1ba2f304191e4b2232072f34475bd5bcc (diff) | |
download | symfony-security-0d6c99afcc9f9392a4eea87caa9b197f176d54b7.zip symfony-security-0d6c99afcc9f9392a4eea87caa9b197f176d54b7.tar.gz symfony-security-0d6c99afcc9f9392a4eea87caa9b197f176d54b7.tar.bz2 |
Adding new TargetPathTrait to get/set the authentication "target_path"
Diffstat (limited to 'Http/Tests/Util/TargetPathTraitTest.php')
-rw-r--r-- | Http/Tests/Util/TargetPathTraitTest.php | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/Http/Tests/Util/TargetPathTraitTest.php b/Http/Tests/Util/TargetPathTraitTest.php new file mode 100644 index 0000000..b2c4dc7 --- /dev/null +++ b/Http/Tests/Util/TargetPathTraitTest.php @@ -0,0 +1,76 @@ +<?php + +namespace Symfony\Component\Security\Http\Tests\Util; + +use Symfony\Component\HttpFoundation\Session\SessionInterface; +use Symfony\Component\Security\Http\Util\TargetPathTrait; + +class TargetPathTraitTest extends \PHPUnit_Framework_TestCase +{ + public function testSetTargetPath() + { + $obj = new TestClassWithTargetPathTrait(); + + $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface') + ->getMock(); + + $session->expects($this->once()) + ->method('set') + ->with('_security.firewall_name.target_path', '/foo'); + + $obj->doSetTargetPath($session, 'firewall_name', '/foo'); + } + + public function testGetTargetPath() + { + $obj = new TestClassWithTargetPathTrait(); + + $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface') + ->getMock(); + + $session->expects($this->once()) + ->method('get') + ->with('_security.cool_firewall.target_path') + ->willReturn('/bar'); + + $actualUri = $obj->doGetTargetPath($session, 'cool_firewall'); + $this->assertEquals( + '/bar', + $actualUri + ); + } + + public function testRemoveTargetPath() + { + $obj = new TestClassWithTargetPathTrait(); + + $session = $this->getMockBuilder('Symfony\Component\HttpFoundation\Session\SessionInterface') + ->getMock(); + + $session->expects($this->once()) + ->method('remove') + ->with('_security.best_firewall.target_path'); + + $obj->doRemoveTargetPath($session, 'best_firewall'); + } +} + +class TestClassWithTargetPathTrait +{ + use TargetPathTrait; + + public function doSetTargetPath(SessionInterface $session, $providerKey, $uri) + { + $this->saveTargetPath($session, $providerKey, $uri); + } + + public function doGetTargetPath(SessionInterface $session, $providerKey) + { + return $this->getTargetPath($session, $providerKey); + } + + public function doRemoveTargetPath(SessionInterface $session, $providerKey) + { + $this->removeTargetPath($session, $providerKey); + } +} |