File
4 years ago
Fixtures
4 years ago
Session
4 years ago
schema
4 years ago
AcceptHeaderItemTest.php
4 years ago
AcceptHeaderTest.php
4 years ago
ApacheRequestTest.php
4 years ago
BinaryFileResponseTest.php
4 years ago
CookieTest.php
4 years ago
ExpressionRequestMatcherTest.php
4 years ago
FileBagTest.php
4 years ago
HeaderBagTest.php
4 years ago
IpUtilsTest.php
4 years ago
JsonResponseTest.php
4 years ago
ParameterBagTest.php
4 years ago
RedirectResponseTest.php
4 years ago
RequestMatcherTest.php
4 years ago
RequestStackTest.php
4 years ago
RequestTest.php
4 years ago
ResponseFunctionalTest.php
4 years ago
ResponseHeaderBagTest.php
4 years ago
ResponseTest.php
4 years ago
ResponseTestCase.php
4 years ago
ServerBagTest.php
4 years ago
StreamedResponseTest.php
4 years ago
ExpressionRequestMatcherTest.php
68 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * This file is part of the Symfony package. |
| 5 | * |
| 6 | * (c) Fabien Potencier <fabien@symfony.com> |
| 7 | * |
| 8 | * For the full copyright and license information, please view the LICENSE |
| 9 | * file that was distributed with this source code. |
| 10 | */ |
| 11 | |
| 12 | namespace Symfony\Component\HttpFoundation\Tests; |
| 13 | |
| 14 | use PHPUnit\Framework\TestCase; |
| 15 | use Symfony\Component\ExpressionLanguage\ExpressionLanguage; |
| 16 | use Symfony\Component\HttpFoundation\ExpressionRequestMatcher; |
| 17 | use Symfony\Component\HttpFoundation\Request; |
| 18 | |
| 19 | class ExpressionRequestMatcherTest extends TestCase |
| 20 | { |
| 21 | public function testWhenNoExpressionIsSet() |
| 22 | { |
| 23 | $this->expectException('LogicException'); |
| 24 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 25 | $expressionRequestMatcher->matches(new Request()); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @dataProvider provideExpressions |
| 30 | */ |
| 31 | public function testMatchesWhenParentMatchesIsTrue($expression, $expected) |
| 32 | { |
| 33 | $request = Request::create('/foo'); |
| 34 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 35 | |
| 36 | $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression); |
| 37 | $this->assertSame($expected, $expressionRequestMatcher->matches($request)); |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * @dataProvider provideExpressions |
| 42 | */ |
| 43 | public function testMatchesWhenParentMatchesIsFalse($expression) |
| 44 | { |
| 45 | $request = Request::create('/foo'); |
| 46 | $request->attributes->set('foo', 'foo'); |
| 47 | $expressionRequestMatcher = new ExpressionRequestMatcher(); |
| 48 | $expressionRequestMatcher->matchAttribute('foo', 'bar'); |
| 49 | |
| 50 | $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression); |
| 51 | $this->assertFalse($expressionRequestMatcher->matches($request)); |
| 52 | } |
| 53 | |
| 54 | public function provideExpressions() |
| 55 | { |
| 56 | return [ |
| 57 | ['request.getMethod() == method', true], |
| 58 | ['request.getPathInfo() == path', true], |
| 59 | ['request.getHost() == host', true], |
| 60 | ['request.getClientIp() == ip', true], |
| 61 | ['request.attributes.all() == attributes', true], |
| 62 | ['request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true], |
| 63 | ['request.getMethod() != method', false], |
| 64 | ['request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false], |
| 65 | ]; |
| 66 | } |
| 67 | } |
| 68 |