Updating Media dependent modules to versions compatible with core Media.
[yaffs-website] / vendor / symfony / http-foundation / Tests / 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
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     /**
22      * @expectedException \LogicException
23      */
24     public function testWhenNoExpressionIsSet()
25     {
26         $expressionRequestMatcher = new ExpressionRequestMatcher();
27         $expressionRequestMatcher->matches(new Request());
28     }
29
30     /**
31      * @dataProvider provideExpressions
32      */
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
42     /**
43      * @dataProvider provideExpressions
44      */
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 }