diff options
author | Jakub Zalas <jakub@zalas.pl> | 2013-05-20 14:42:44 +0100 |
---|---|---|
committer | Jakub Zalas <jakub@zalas.pl> | 2013-05-24 18:27:56 +0100 |
commit | ce48be1189801b36a6ed444264611d9ade9c98dc (patch) | |
tree | 0f8358c7e416b6f624e4a9b62c1c82dbf7c07950 /Tests/Http | |
parent | 76d806671c4598859f164f740cdbf1cc8e050f96 (diff) | |
download | symfony-security-ce48be1189801b36a6ed444264611d9ade9c98dc.zip symfony-security-ce48be1189801b36a6ed444264611d9ade9c98dc.tar.gz symfony-security-ce48be1189801b36a6ed444264611d9ade9c98dc.tar.bz2 |
[Security] Added tests for the AccessMap.
Diffstat (limited to 'Tests/Http')
-rw-r--r-- | Tests/Http/AccessMapTest.php | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/Tests/Http/AccessMapTest.php b/Tests/Http/AccessMapTest.php new file mode 100644 index 0000000..653152a --- /dev/null +++ b/Tests/Http/AccessMapTest.php @@ -0,0 +1,58 @@ +<?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\AccessMap; + +class AccessMapTest extends \PHPUnit_Framework_TestCase +{ + protected function setUp() + { + if (!class_exists('Symfony\Component\HttpFoundation\Request')) { + $this->markTestSkipped('The "HttpFoundation" component is not available'); + } + } + + public function testReturnsFirstMatchedPattern() + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + $requestMatcher1 = $this->getRequestMatcher($request, false); + $requestMatcher2 = $this->getRequestMatcher($request, true); + + $map = new AccessMap(); + $map->add($requestMatcher1, array('ROLE_ADMIN'), 'http'); + $map->add($requestMatcher2, array('ROLE_USER'), 'https'); + + $this->assertSame(array(array('ROLE_USER'), 'https'), $map->getPatterns($request)); + } + + public function testReturnsEmptyPatternIfNoneMatched() + { + $request = $this->getMock('Symfony\Component\HttpFoundation\Request'); + $requestMatcher = $this->getRequestMatcher($request, false); + + $map = new AccessMap(); + $map->add($requestMatcher, array('ROLE_USER'), 'https'); + + $this->assertSame(array(null, null), $map->getPatterns($request)); + } + + private function getRequestMatcher($request, $matches) + { + $requestMatcher = $this->getMock('Symfony\Component\HttpFoundation\RequestMatcherInterface'); + $requestMatcher->expects($this->once()) + ->method('matches')->with($request) + ->will($this->returnValue($matches)); + + return $requestMatcher; + } +} |