Вход Регистрация
Файл: symfony-2.7/src/Symfony/Component/Routing/Tests/Matcher/RedirectableUrlMatcherTest.php
Строк: 94
<?php

/*
 * This file is part of the Symfony package.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace SymfonyComponentRoutingTestsMatcher;

use 
SymfonyComponentRoutingRoute;
use 
SymfonyComponentRoutingRouteCollection;
use 
SymfonyComponentRoutingRequestContext;

class 
RedirectableUrlMatcherTest extends PHPUnit_Framework_TestCase
{
    public function 
testRedirectWhenNoSlash()
    {
        
$coll = new RouteCollection();
        
$coll->add('foo', new Route('/foo/'));

        
$matcher $this->getMockForAbstractClass('SymfonyComponentRoutingMatcherRedirectableUrlMatcher', array($coll, new RequestContext()));
        
$matcher->expects($this->once())->method('redirect');
        
$matcher->match('/foo');
    }

    
/**
     * @expectedException SymfonyComponentRoutingExceptionResourceNotFoundException
     */
    
public function testRedirectWhenNoSlashForNonSafeMethod()
    {
        
$coll = new RouteCollection();
        
$coll->add('foo', new Route('/foo/'));

        
$context = new RequestContext();
        
$context->setMethod('POST');
        
$matcher $this->getMockForAbstractClass('SymfonyComponentRoutingMatcherRedirectableUrlMatcher', array($coll$context));
        
$matcher->match('/foo');
    }

    public function 
testSchemeRedirectRedirectsToFirstScheme()
    {
        
$coll = new RouteCollection();
        
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('FTP''HTTPS')));

        
$matcher $this->getMockForAbstractClass('SymfonyComponentRoutingMatcherRedirectableUrlMatcher', array($coll, new RequestContext()));
        
$matcher
            
->expects($this->once())
            ->
method('redirect')
            ->
with('/foo''foo''ftp')
            ->
will($this->returnValue(array('_route' => 'foo')))
        ;
        
$matcher->match('/foo');
    }

    public function 
testNoSchemaRedirectIfOnOfMultipleSchemesMatches()
    {
        
$coll = new RouteCollection();
        
$coll->add('foo', new Route('/foo', array(), array(), array(), '', array('https''http')));

        
$matcher $this->getMockForAbstractClass('SymfonyComponentRoutingMatcherRedirectableUrlMatcher', array($coll, new RequestContext()));
        
$matcher
            
->expects($this->never())
            ->
method('redirect')
        ;
        
$matcher->match('/foo');
    }
}
Онлайн: 2
Реклама