ba4c6e972f19c136ae83455f572cc7735a4d931a
[yaffs-website] / vendor / symfony / routing / Tests / Matcher / RedirectableUrlMatcherTest.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\Routing\Tests\Matcher;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Routing\Route;
16 use Symfony\Component\Routing\RouteCollection;
17 use Symfony\Component\Routing\RequestContext;
18
19 class RedirectableUrlMatcherTest extends TestCase
20 {
21     public function testRedirectWhenNoSlash()
22     {
23         $coll = new RouteCollection();
24         $coll->add('foo', new Route('/foo/'));
25
26         $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
27         $matcher->expects($this->once())->method('redirect');
28         $matcher->match('/foo');
29     }
30
31     /**
32      * @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
33      */
34     public function testRedirectWhenNoSlashForNonSafeMethod()
35     {
36         $coll = new RouteCollection();
37         $coll->add('foo', new Route('/foo/'));
38
39         $context = new RequestContext();
40         $context->setMethod('POST');
41         $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, $context));
42         $matcher->match('/foo');
43     }
44
45     public function testSchemeRedirectRedirectsToFirstScheme()
46     {
47         $coll = new RouteCollection();
48         $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('FTP', 'HTTPS')));
49
50         $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
51         $matcher
52             ->expects($this->once())
53             ->method('redirect')
54             ->with('/foo', 'foo', 'ftp')
55             ->will($this->returnValue(array('_route' => 'foo')))
56         ;
57         $matcher->match('/foo');
58     }
59
60     public function testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
61     {
62         $coll = new RouteCollection();
63         $coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https', 'http')));
64
65         $matcher = $this->getMockForAbstractClass('Symfony\Component\Routing\Matcher\RedirectableUrlMatcher', array($coll, new RequestContext()));
66         $matcher
67             ->expects($this->never())
68             ->method('redirect')
69         ;
70         $matcher->match('/foo');
71     }
72 }