summaryrefslogtreecommitdiffstats
path: root/Http/Tests/Util/TargetPathTraitTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'Http/Tests/Util/TargetPathTraitTest.php')
-rw-r--r--Http/Tests/Util/TargetPathTraitTest.php76
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);
+ }
+}