2013-05-20 14:42:44 +01:00
|
|
|
<?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.
|
|
|
|
*/
|
|
|
|
|
2013-09-16 09:03:00 +01:00
|
|
|
namespace Symfony\Component\Security\Http\Tests;
|
2013-05-20 14:42:44 +01:00
|
|
|
|
2017-02-08 07:24:27 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2013-05-20 14:42:44 +01:00
|
|
|
use Symfony\Component\Security\Http\AccessMap;
|
|
|
|
|
2017-02-08 07:24:27 +00:00
|
|
|
class AccessMapTest extends TestCase
|
2013-05-20 14:42:44 +01:00
|
|
|
{
|
|
|
|
public function testReturnsFirstMatchedPattern()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
|
2013-05-20 14:42:44 +01:00
|
|
|
$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()
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
$request = $this->getMockBuilder('Symfony\Component\HttpFoundation\Request')->getMock();
|
2013-05-20 14:42:44 +01:00
|
|
|
$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)
|
|
|
|
{
|
2016-12-19 09:02:29 +00:00
|
|
|
$requestMatcher = $this->getMockBuilder('Symfony\Component\HttpFoundation\RequestMatcherInterface')->getMock();
|
2013-05-20 14:42:44 +01:00
|
|
|
$requestMatcher->expects($this->once())
|
|
|
|
->method('matches')->with($request)
|
|
|
|
->will($this->returnValue($matches));
|
|
|
|
|
|
|
|
return $requestMatcher;
|
|
|
|
}
|
|
|
|
}
|