Open Journal Systems  3.3.0
ExpressionRequestMatcherTest.php
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 
13 
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\ExpressionLanguage\ExpressionLanguage;
18 
19 class ExpressionRequestMatcherTest extends TestCase
20 {
24  public function testWhenNoExpressionIsSet()
25  {
26  $expressionRequestMatcher = new ExpressionRequestMatcher();
27  $expressionRequestMatcher->matches(new Request());
28  }
29 
33  public function testMatchesWhenParentMatchesIsTrue($expression, $expected)
34  {
35  $request = Request::create('/foo');
36  $expressionRequestMatcher = new ExpressionRequestMatcher();
37 
38  $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
39  $this->assertSame($expected, $expressionRequestMatcher->matches($request));
40  }
41 
45  public function testMatchesWhenParentMatchesIsFalse($expression)
46  {
47  $request = Request::create('/foo');
48  $request->attributes->set('foo', 'foo');
49  $expressionRequestMatcher = new ExpressionRequestMatcher();
50  $expressionRequestMatcher->matchAttribute('foo', 'bar');
51 
52  $expressionRequestMatcher->setExpression(new ExpressionLanguage(), $expression);
53  $this->assertFalse($expressionRequestMatcher->matches($request));
54  }
55 
56  public function provideExpressions()
57  {
58  return array(
59  array('request.getMethod() == method', true),
60  array('request.getPathInfo() == path', true),
61  array('request.getHost() == host', true),
62  array('request.getClientIp() == ip', true),
63  array('request.attributes.all() == attributes', true),
64  array('request.getMethod() == method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', true),
65  array('request.getMethod() != method', false),
66  array('request.getMethod() != method && request.getPathInfo() == path && request.getHost() == host && request.getClientIp() == ip && request.attributes.all() == attributes', false),
67  );
68  }
69 }
Symfony\Component\HttpFoundation\ExpressionRequestMatcher
Definition: lib/vendor/symfony/http-foundation/ExpressionRequestMatcher.php:21
Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest\provideExpressions
provideExpressions()
Definition: ExpressionRequestMatcherTest.php:56
Symfony\Component\HttpFoundation\Request
Definition: lib/vendor/symfony/http-foundation/Request.php:31
Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest\testMatchesWhenParentMatchesIsTrue
testMatchesWhenParentMatchesIsTrue($expression, $expected)
Definition: ExpressionRequestMatcherTest.php:33
Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest\testWhenNoExpressionIsSet
testWhenNoExpressionIsSet()
Definition: ExpressionRequestMatcherTest.php:24
Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest\testMatchesWhenParentMatchesIsFalse
testMatchesWhenParentMatchesIsFalse($expression)
Definition: ExpressionRequestMatcherTest.php:45
Symfony\Component\HttpFoundation\Tests\ExpressionRequestMatcherTest
Definition: ExpressionRequestMatcherTest.php:19
Symfony\Component\HttpFoundation\Tests
Definition: AcceptHeaderItemTest.php:12
Symfony\Component\HttpFoundation\Request\create
static create($uri, $method='GET', $parameters=array(), $cookies=array(), $files=array(), $server=array(), $content=null)
Definition: lib/vendor/symfony/http-foundation/Request.php:408