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