Update to drupal-org-drupal 8.0.0-rc2. For more information, see https://www.drupal.org/node/2598668

This commit is contained in:
Pantheon Automation 2015-10-21 21:44:50 -07:00 committed by Greg Anderson
parent f32e58e4b1
commit 8e18df8c36
3062 changed files with 15044 additions and 172506 deletions

View file

@ -1,105 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2013 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Candidates;
use Symfony\Cmf\Component\Routing\Candidates\Candidates;
use Symfony\Component\HttpFoundation\Request;
class CandidatesTest extends \PHPUnit_Framework_Testcase
{
/**
* Everything is a candidate
*/
public function testIsCandidate()
{
$candidates = new Candidates();
$this->assertTrue($candidates->isCandidate('/routes'));
$this->assertTrue($candidates->isCandidate('/routes/my/path'));
}
/**
* Nothing should be called on the query builder
*/
public function testRestrictQuery()
{
$candidates = new Candidates();
$candidates->restrictQuery(null);
}
public function testGetCandidates()
{
$request = Request::create('/my/path.html');
$candidates = new Candidates();
$paths = $candidates->getCandidates($request);
$this->assertEquals(
array(
'/my/path.html',
'/my/path',
'/my',
'/',
),
$paths
);
}
public function testGetCandidatesLocales()
{
$candidates = new Candidates(array('de', 'fr'));
$request = Request::create('/fr/path.html');
$paths = $candidates->getCandidates($request);
$this->assertEquals(
array(
'/fr/path.html',
'/fr/path',
'/fr',
'/',
'/path.html',
'/path'
),
$paths
);
$request = Request::create('/it/path.html');
$paths = $candidates->getCandidates($request);
$this->assertEquals(
array(
'/it/path.html',
'/it/path',
'/it',
'/',
),
$paths
);
}
public function testGetCandidatesLimit()
{
$candidates = new Candidates(array(), 1);
$request = Request::create('/my/path/is/deep.html');
$paths = $candidates->getCandidates($request);
$this->assertEquals(
array(
'/my/path/is/deep.html',
'/my/path/is/deep',
),
$paths
);
}
}

View file

@ -1,71 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\DependencyInjection\Compiler;
use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRouteEnhancersPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
class RegisterRouteEnhancersPassTest extends \PHPUnit_Framework_TestCase
{
public function testRouteEnhancerPass()
{
$serviceIds = array(
'test_enhancer' => array(
0 => array(
'id' => 'foo_enhancer'
)
),
);
$definition = new Definition('router');
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$builder->expects($this->at(0))
->method('hasDefinition')
->with('cmf_routing.dynamic_router')
->will($this->returnValue(true))
;
$builder->expects($this->once())
->method('findTaggedServiceIds')
->will($this->returnValue($serviceIds))
;
$builder->expects($this->once())
->method('getDefinition')
->with('cmf_routing.dynamic_router')
->will($this->returnValue($definition))
;
$pass = new RegisterRouteEnhancersPass();
$pass->process($builder);
$calls = $definition->getMethodCalls();
$this->assertEquals(1, count($calls));
$this->assertEquals('addRouteEnhancer', $calls[0][0]);
}
/**
* If there is no dynamic router defined in the container builder, nothing
* should be processed.
*/
public function testNoDynamicRouter()
{
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
$builder->expects($this->once())
->method('hasDefinition')
->with('cmf_routing.dynamic_router')
->will($this->returnValue(false))
;
$pass = new RegisterRouteEnhancersPass();
$pass->process($builder);
}
}

View file

@ -1,98 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Routing\Tests\DependencyInjection\Compiler;
use Symfony\Cmf\Component\Routing\DependencyInjection\Compiler\RegisterRoutersPass;
use Symfony\Component\DependencyInjection\Reference;
class RegisterRoutersPassTest extends \PHPUnit_Framework_TestCase
{
/**
* @dataProvider getValidRoutersData
*/
public function testValidRouters($name, $priority = null)
{
if (!method_exists($this, 'callback')) {
$this->markTestSkipped('PHPUnit version too old for this test');
}
$services = array();
$services[$name] = array(0 => array('priority' => $priority));
$priority = $priority ?: 0;
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
$definition->expects($this->atLeastOnce())
->method('addMethodCall')
->with($this->equalTo('add'), $this->callback(function ($arg) use ($name, $priority) {
if (!$arg[0] instanceof Reference || $name !== $arg[0]->__toString()) {
return false;
}
if ($priority !== $arg[1]) {
return false;
}
return true;
}));
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'));
$builder->expects($this->any())
->method('hasDefinition')
->with('cmf_routing.router')
->will($this->returnValue(true));
$builder->expects($this->atLeastOnce())
->method('findTaggedServiceIds')
->will($this->returnValue($services));
$builder->expects($this->atLeastOnce())
->method('getDefinition')
->will($this->returnValue($definition));
$registerRoutersPass = new RegisterRoutersPass();
$registerRoutersPass->process($builder);
}
public function getValidRoutersData()
{
return array(
array('my_router'),
array('my_primary_router', 99),
array('my_router', 0),
);
}
/**
* If there is no chain router defined in the container builder, nothing
* should be processed.
*/
public function testNoChainRouter()
{
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder', array('hasDefinition', 'findTaggedServiceIds', 'getDefinition'));
$builder->expects($this->once())
->method('hasDefinition')
->with('cmf_routing.router')
->will($this->returnValue(false))
;
$builder->expects($this->never())
->method('findTaggedServiceIds')
;
$builder->expects($this->never())
->method('getDefinition')
;
$registerRoutersPass = new RegisterRoutersPass();
$registerRoutersPass->process($builder);
}
}

View file

@ -1,71 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
use Symfony\Cmf\Component\Routing\Enhancer\FieldByClassEnhancer;
class FieldByClassEnhancerTest extends CmfUnitTestCase
{
private $request;
/**
* @var FieldByClassEnhancer
*/
private $mapper;
private $document;
public function setUp()
{
$this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject');
$mapping = array('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject'
=> 'cmf_content.controller:indexAction');
$this->mapper = new FieldByClassEnhancer('_content', '_controller', $mapping);
$this->request = Request::create('/test');
}
public function testClassFoundInMapping()
{
// this is the mock, thus a child class to make sure we properly check with instanceof
$defaults = array('_content' => $this->document);
$expected = array(
'_content' => $this->document,
'_controller' => 'cmf_content.controller:indexAction',
);
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = array(
'_content' => $this->document,
'_controller' => 'custom.controller:indexAction',
);
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testClassNotFoundInMapping()
{
$defaults = array('_content' => $this);
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoClass()
{
$defaults = array('foo' => 'bar');
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
}

View file

@ -1,69 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Mapper;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
use Symfony\Cmf\Component\Routing\Enhancer\FieldMapEnhancer;
class FieldMapEnhancerTest extends CmfUnitTestCase
{
/**
* @var Request
*/
private $request;
/**
* @var FieldMapEnhancer
*/
private $enhancer;
public function setUp()
{
$this->request = Request::create('/test');
$mapping = array('static_pages' => 'cmf_content.controller:indexAction');
$this->enhancer = new FieldMapEnhancer('type', '_controller', $mapping);
}
public function testFieldFoundInMapping()
{
$defaults = array('type' => 'static_pages');
$expected = array(
'type' => 'static_pages',
'_controller' => 'cmf_content.controller:indexAction',
);
$this->assertEquals($expected, $this->enhancer->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = array(
'type' => 'static_pages',
'_controller' => 'custom.controller:indexAction',
);
$this->assertEquals($defaults, $this->enhancer->enhance($defaults, $this->request));
}
public function testNoType()
{
$defaults = array();
$this->assertEquals(array(), $this->enhancer->enhance($defaults, $this->request));
}
public function testNotFoundInMapping()
{
$defaults = array('type' => 'unknown_route');
$this->assertEquals($defaults, $this->enhancer->enhance($defaults, $this->request));
}
}

View file

@ -1,71 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\Enhancer\FieldPresenceEnhancer;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class FieldPresenceEnhancerTest extends CmfUnitTestCase
{
/**
* @var FieldPresenceEnhancer
*/
private $mapper;
private $request;
public function setUp()
{
$this->mapper = new FieldPresenceEnhancer('_template', '_controller', 'cmf_content.controller:indexAction');
$this->request = Request::create('/test');
}
public function testHasTemplate()
{
$defaults = array('_template' => 'Bundle:Topic:template.html.twig');
$expected = array(
'_template' => 'Bundle:Topic:template.html.twig',
'_controller' => 'cmf_content.controller:indexAction',
);
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$defaults = array(
'_template' => 'Bundle:Topic:template.html.twig',
'_controller' => 'custom.controller:indexAction',
);
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testHasNoSourceValue()
{
$defaults = array('foo' => 'bar');
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testHasNoSource()
{
$this->mapper = new FieldPresenceEnhancer(null, '_controller', 'cmf_content.controller:indexAction');
$defaults = array('foo' => 'bar');
$expected = array(
'foo' => 'bar',
'_controller' => 'cmf_content.controller:indexAction',
);
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
}

View file

@ -1,87 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\Enhancer\RouteContentEnhancer;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class RouteContentEnhancerTest extends CmfUnitTestCase
{
/**
* @var RouteContentEnhancer
*/
private $mapper;
private $document;
private $request;
public function setUp()
{
$this->document = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Enhancer\RouteObject',
array('getContent', 'getRouteDefaults', 'getUrl'));
$this->mapper = new RouteContentEnhancer(RouteObjectInterface::ROUTE_OBJECT, '_content');
$this->request = Request::create('/test');
}
public function testContent()
{
$targetDocument = new TargetDocument();
$this->document->expects($this->once())
->method('getContent')
->will($this->returnValue($targetDocument));
$defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
$expected = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => $targetDocument);
$this->assertEquals($expected, $this->mapper->enhance($defaults, $this->request));
}
public function testFieldAlreadyThere()
{
$this->document->expects($this->never())
->method('getContent')
;
$defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document, '_content' => 'foo');
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoContent()
{
$this->document->expects($this->once())
->method('getContent')
->will($this->returnValue(null));
$defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->document);
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
public function testNoCmfRoute()
{
$defaults = array(RouteObjectInterface::ROUTE_OBJECT => $this->buildMock('Symfony\Component\Routing\Route'));
$this->assertEquals($defaults, $this->mapper->enhance($defaults, $this->request));
}
}
class TargetDocument
{
}
class UnknownDocument
{
}

View file

@ -1,27 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Enhancer;
use Symfony\Component\Routing\Route;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
/**
* Empty abstract class to be able to mock an object that both extends Route
* and implements RouteObjectInterface
*/
abstract class RouteObject extends Route implements RouteObjectInterface
{
public function getRouteKey()
{
return null;
}
}

View file

@ -1,139 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\NestedMatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Cmf\Component\Routing\NestedMatcher\NestedMatcher;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class NestedMatcherTest extends CmfUnitTestCase
{
private $provider;
private $routeFilter1;
private $routeFilter2;
private $finalMatcher;
public function setUp()
{
$this->provider = $this->buildMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$this->routeFilter1 = $this->buildMock('Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface');
$this->routeFilter2 = $this->buildMock('Symfony\Cmf\Component\Routing\NestedMatcher\RouteFilterInterface');
$this->finalMatcher = $this->buildMock('Symfony\Cmf\Component\Routing\NestedMatcher\FinalMatcherInterface');
}
public function testNestedMatcher()
{
$request = Request::create('/path/one');
$routeCollection = new RouteCollection();
$route = $this->getMockBuilder('Symfony\Component\Routing\Route')->disableOriginalConstructor()->getMock();
$routeCollection->add('route', $route);
$this->provider->expects($this->once())
->method('getRouteCollectionForRequest')
->with($request)
->will($this->returnValue($routeCollection))
;
$this->routeFilter1->expects($this->once())
->method('filter')
->with($routeCollection, $request)
->will($this->returnValue($routeCollection))
;
$this->routeFilter2->expects($this->once())
->method('filter')
->with($routeCollection, $request)
->will($this->returnValue($routeCollection))
;
$this->finalMatcher->expects($this->once())
->method('finalMatch')
->with($routeCollection, $request)
->will($this->returnValue(array('foo' => 'bar')))
;
$matcher = new NestedMatcher($this->provider, $this->finalMatcher);
$matcher->addRouteFilter($this->routeFilter1);
$matcher->addRouteFilter($this->routeFilter2);
$attributes = $matcher->matchRequest($request);
$this->assertEquals(array('foo' => 'bar'), $attributes);
}
/**
* Test priorities and exception handling
*/
public function testNestedMatcherPriority()
{
$request = Request::create('/path/one');
$routeCollection = new RouteCollection();
$route = $this->getMockBuilder('Symfony\Component\Routing\Route')->disableOriginalConstructor()->getMock();
$routeCollection->add('route', $route);
$wrongProvider = $this->buildMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$wrongProvider->expects($this->never())
->method('getRouteCollectionForRequest')
;
$this->provider->expects($this->once())
->method('getRouteCollectionForRequest')
->with($request)
->will($this->returnValue($routeCollection))
;
$this->routeFilter1->expects($this->once())
->method('filter')
->with($routeCollection, $request)
->will($this->throwException(new ResourceNotFoundException()))
;
$this->routeFilter2->expects($this->never())
->method('filter')
;
$this->finalMatcher->expects($this->never())
->method('finalMatch')
;
$matcher = new NestedMatcher($wrongProvider, $this->finalMatcher);
$matcher->setRouteProvider($this->provider);
$matcher->addRouteFilter($this->routeFilter2, 10);
$matcher->addRouteFilter($this->routeFilter1, 20);
try {
$matcher->matchRequest($request);
fail('nested matcher is eating exception');
} catch (ResourceNotFoundException $e) {
// expected
}
}
public function testProviderNoMatch()
{
$request = Request::create('/path/one');
$routeCollection = new RouteCollection();
$this->provider->expects($this->once())
->method('getRouteCollectionForRequest')
->with($request)
->will($this->returnValue($routeCollection))
;
$this->finalMatcher->expects($this->never())
->method('finalMatch')
;
$matcher = new NestedMatcher($this->provider, $this->finalMatcher);
$this->setExpectedException('Symfony\Component\Routing\Exception\ResourceNotFoundException');
$matcher->matchRequest($request);
}
}

View file

@ -1,152 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\NestedMatcher;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\Routing\Route;
use Symfony\Cmf\Component\Routing\NestedMatcher\UrlMatcher;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class UrlMatcherTest extends CmfUnitTestCase
{
protected $routeDocument;
protected $routeCompiled;
protected $matcher;
protected $context;
protected $request;
protected $url = '/foo/bar';
public function setUp()
{
$this->routeDocument = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'getRouteKey', 'compile'));
$this->routeCompiled = $this->buildMock('Symfony\Component\Routing\CompiledRoute');
$this->context = $this->buildMock('Symfony\Component\Routing\RequestContext');
$this->request = Request::create($this->url);
$this->matcher = new UrlMatcher(new RouteCollection(), $this->context);
}
public function testMatchRouteKey()
{
$this->doTestMatchRouteKey($this->url);
}
public function testMatchNoKey()
{
$this->doTestMatchRouteKey(null);
}
public function doTestMatchRouteKey($routeKey)
{
$this->routeCompiled->expects($this->atLeastOnce())
->method('getStaticPrefix')
->will($this->returnValue($this->url))
;
$this->routeCompiled->expects($this->atLeastOnce())
->method('getRegex')
->will($this->returnValue('#'.str_replace('/', '\/', $this->url).'#'))
;
$this->routeDocument->expects($this->atLeastOnce())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->routeDocument->expects($this->atLeastOnce())
->method('getRouteKey')
->will($this->returnValue($routeKey))
;
$this->routeDocument->expects($this->atLeastOnce())
->method('getDefaults')
->will($this->returnValue(array('foo' => 'bar')))
;
$mockCompiled = $this->buildMock('Symfony\Component\Routing\CompiledRoute');
$mockCompiled->expects($this->any())
->method('getStaticPrefix')
->will($this->returnValue('/no/match'))
;
$mockRoute = $this->getMockBuilder('Symfony\Component\Routing\Route')->disableOriginalConstructor()->getMock();
$mockRoute->expects($this->any())
->method('compile')
->will($this->returnValue($mockCompiled))
;
$routeCollection = new RouteCollection();
$routeCollection->add('some', $mockRoute);
$routeCollection->add('_company_more', $this->routeDocument);
$routeCollection->add('other', $mockRoute);
$results = $this->matcher->finalMatch($routeCollection, $this->request);
$expected = array(
RouteObjectInterface::ROUTE_NAME => ($routeKey) ? $routeKey : '_company_more',
RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument,
'foo' => 'bar',
);
$this->assertEquals($expected, $results);
}
public function testMatchNoRouteObject()
{
$this->routeCompiled->expects($this->atLeastOnce())
->method('getStaticPrefix')
->will($this->returnValue($this->url))
;
$this->routeCompiled->expects($this->atLeastOnce())
->method('getRegex')
->will($this->returnValue('#'.str_replace('/', '\/', $this->url).'#'))
;
$this->routeDocument = $this->getMockBuilder('Symfony\Component\Routing\Route')->disableOriginalConstructor()->getMock();
$this->routeDocument->expects($this->atLeastOnce())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->routeDocument->expects($this->never())
->method('getRouteKey')
;
$this->routeDocument->expects($this->atLeastOnce())
->method('getDefaults')
->will($this->returnValue(array('foo' => 'bar')))
;
$mockCompiled = $this->buildMock('Symfony\Component\Routing\CompiledRoute');
$mockCompiled->expects($this->any())
->method('getStaticPrefix')
->will($this->returnValue('/no/match'))
;
$mockRoute = $this->getMockBuilder('Symfony\Component\Routing\Route')->disableOriginalConstructor()->getMock();
$mockRoute->expects($this->any())
->method('compile')
->will($this->returnValue($mockCompiled))
;
$routeCollection = new RouteCollection();
$routeCollection->add('some', $mockRoute);
$routeCollection->add('_company_more', $this->routeDocument);
$routeCollection->add('other', $mockRoute);
$results = $this->matcher->finalMatch($routeCollection, $this->request);
$expected = array(
RouteObjectInterface::ROUTE_NAME => '_company_more',
RouteObjectInterface::ROUTE_OBJECT => $this->routeDocument,
'foo' => 'bar',
);
$this->assertEquals($expected, $results);
}
}

View file

@ -1,730 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Cmf\Component\Routing\VersatileGeneratorInterface;
use Symfony\Component\HttpKernel\CacheWarmer\WarmableInterface;
use Symfony\Component\Routing\Exception\MethodNotAllowedException;
use Symfony\Component\Routing\Exception\ResourceNotFoundException;
use Symfony\Component\Routing\Exception\RouteNotFoundException;
use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Cmf\Component\Routing\ChainRouter;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
use Symfony\Component\Routing\RouterInterface;
class ChainRouterTest extends CmfUnitTestCase
{
/**
* @var ChainRouter
*/
private $router;
/**
* @var RequestContext|\PHPUnit_Framework_MockObject_MockObject
*/
private $context;
public function setUp()
{
$this->router = new ChainRouter($this->getMock('Psr\Log\LoggerInterface'));
$this->context = $this->getMock('Symfony\Component\Routing\RequestContext');
}
public function testPriority()
{
$this->assertEquals(array(), $this->router->all());
list($low, $high) = $this->createRouterMocks();
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->assertEquals(array(
$high,
$low,
), $this->router->all());
}
/**
* Routers are supposed to be sorted only once.
* This test will check that by trying to get all routers several times.
*
* @covers \Symfony\Cmf\Component\Routing\ChainRouter::sortRouters
* @covers \Symfony\Cmf\Component\Routing\ChainRouter::all
*/
public function testSortRouters()
{
list($low, $medium, $high) = $this->createRouterMocks();
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
/** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
$router = $this->buildMock('Symfony\Cmf\Component\Routing\ChainRouter', array('sortRouters'));
$router
->expects($this->once())
->method('sortRouters')
->will(
$this->returnValue(
array($high, $medium, $low)
)
)
;
$router->add($low, 10);
$router->add($medium, 50);
$router->add($high, 100);
$expectedSortedRouters = array($high, $medium, $low);
// Let's get all routers 5 times, we should only sort once.
for ($i = 0; $i < 5; ++$i) {
$this->assertSame($expectedSortedRouters, $router->all());
}
}
/**
* This test ensures that if a router is being added on the fly, the sorting is reset.
*
* @covers \Symfony\Cmf\Component\Routing\ChainRouter::sortRouters
* @covers \Symfony\Cmf\Component\Routing\ChainRouter::all
* @covers \Symfony\Cmf\Component\Routing\ChainRouter::add
*/
public function testReSortRouters()
{
list($low, $medium, $high) = $this->createRouterMocks();
$highest = clone $high;
// We're using a mock here and not $this->router because we need to ensure that the sorting operation is done only once.
/** @var $router ChainRouter|\PHPUnit_Framework_MockObject_MockObject */
$router = $this->buildMock('Symfony\Cmf\Component\Routing\ChainRouter', array('sortRouters'));
$router
->expects($this->at(0))
->method('sortRouters')
->will(
$this->returnValue(
array($high, $medium, $low)
)
)
;
// The second time sortRouters() is called, we're supposed to get the newly added router ($highest)
$router
->expects($this->at(1))
->method('sortRouters')
->will(
$this->returnValue(
array($highest, $high, $medium, $low)
)
)
;
$router->add($low, 10);
$router->add($medium, 50);
$router->add($high, 100);
$this->assertSame(array($high, $medium, $low), $router->all());
// Now adding another router on the fly, sorting must have been reset
$router->add($highest, 101);
$this->assertSame(array($highest, $high, $medium, $low), $router->all());
}
/**
* context must be propagated to chained routers and be stored locally
*/
public function testContext()
{
list($low, $high) = $this->createRouterMocks();
$low
->expects($this->once())
->method('setContext')
->with($this->context)
;
$high
->expects($this->once())
->method('setContext')
->with($this->context)
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->setContext($this->context);
$this->assertSame($this->context, $this->router->getContext());
}
/**
* context must be propagated also when routers are added after context is set
*/
public function testContextOrder()
{
list($low, $high) = $this->createRouterMocks();
$low
->expects($this->once())
->method('setContext')
->with($this->context)
;
$high
->expects($this->once())
->method('setContext')
->with($this->context)
;
$this->router->setContext($this->context);
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->all();
$this->assertSame($this->context, $this->router->getContext());
}
/**
* The first usable match is used, no further routers are queried once a match is found
*/
public function testMatch()
{
$url = '/test';
list($lower, $low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->returnValue(array('test')))
;
$lower
->expects($this->never())
->method('match');
$this->router->add($lower, 5);
$this->router->add($low, 10);
$this->router->add($high, 100);
$result = $this->router->match('/test');
$this->assertEquals(array('test'), $result);
}
/**
* The first usable match is used, no further routers are queried once a match is found
*/
public function testMatchRequest()
{
$url = '/test';
list($lower, $low, $high) = $this->createRouterMocks();
$highest = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\RequestMatcher');
$request = Request::create('/test');
$highest
->expects($this->once())
->method('matchRequest')
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->returnValue(array('test')))
;
$lower
->expects($this->never())
->method('match')
;
$this->router->add($lower, 5);
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->add($highest, 200);
$result = $this->router->matchRequest($request);
$this->assertEquals(array('test'), $result);
}
/**
* Call match on ChainRouter that has RequestMatcher in the chain.
*/
public function testMatchWithRequestMatchers()
{
$url = '/test';
list($low) = $this->createRouterMocks();
$high = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\RequestMatcher');
$high
->expects($this->once())
->method('matchRequest')
->with($this->callback(function (Request $r) use ($url) {
return $r->getPathInfo() === $url;
}))
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->returnValue(array('test')))
;
$this->router->add($low, 10);
$this->router->add($high, 20);
$result = $this->router->match($url);
$this->assertEquals(array('test'), $result);
}
/**
* If there is a method not allowed but another router matches, that one is used
*/
public function testMatchAndNotAllowed()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new \Symfony\Component\Routing\Exception\MethodNotAllowedException(array())))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->returnValue(array('test')))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$result = $this->router->match('/test');
$this->assertEquals(array('test'), $result);
}
/**
* If there is a method not allowed but another router matches, that one is used
*/
public function testMatchRequestAndNotAllowed()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new \Symfony\Component\Routing\Exception\MethodNotAllowedException(array())))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->returnValue(array('test')))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$result = $this->router->matchRequest(Request::create('/test'));
$this->assertEquals(array('test'), $result);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testMatchNotFound()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->match('/test');
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testMatchRequestNotFound()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->matchRequest(Request::create('/test'));
}
/**
* Call match on ChainRouter that has RequestMatcher in the chain.
*
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
* @expectedExceptionMessage None of the routers in the chain matched url '/test'
*/
public function testMatchWithRequestMatchersNotFound()
{
$url = '/test';
$request = Request::create('/test');
$high = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\RequestMatcher');
$high
->expects($this->once())
->method('matchRequest')
->with($request)
->will($this->throwException(new \Symfony\Component\Routing\Exception\ResourceNotFoundException))
;
$this->router->add($high, 20);
$this->router->match($url);
}
/**
* If any of the routers throws a not allowed exception and no other matches, we need to see this
*
* @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
*/
public function testMatchMethodNotAllowed()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new MethodNotAllowedException(array())))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->match('/test');
}
/**
* If any of the routers throws a not allowed exception and no other matches, we need to see this
*
* @expectedException \Symfony\Component\Routing\Exception\MethodNotAllowedException
*/
public function testMatchRequestMethodNotAllowed()
{
$url = '/test';
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new MethodNotAllowedException(array())))
;
$low
->expects($this->once())
->method('match')
->with($url)
->will($this->throwException(new ResourceNotFoundException()))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->matchRequest(Request::create('/test'));
}
public function testGenerate()
{
$url = '/test';
$name = 'test';
$parameters = array('test' => 'value');
list($lower, $low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->throwException(new RouteNotFoundException()))
;
$low
->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->returnValue($url))
;
$lower
->expects($this->never())
->method('generate')
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$result = $this->router->generate($name, $parameters);
$this->assertEquals($url, $result);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNotFound()
{
$name = 'test';
$parameters = array('test' => 'value');
list($low, $high) = $this->createRouterMocks();
$high
->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->throwException(new RouteNotFoundException()))
;
$low->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->throwException(new RouteNotFoundException()))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->generate($name, $parameters);
}
/**
* Route is an object but no versatile generator around to do the debug message.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateObjectNotFound()
{
$name = new \stdClass();
$parameters = array('test' => 'value');
$defaultRouter = $this->getMock('Symfony\Component\Routing\RouterInterface');
$defaultRouter
->expects($this->never())
->method('generate')
;
$this->router->add($defaultRouter, 200);
$this->router->generate($name, $parameters);
}
/**
* A versatile router will generate the debug message.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateObjectNotFoundVersatile()
{
$name = new \stdClass();
$parameters = array('test' => 'value');
$chainedRouter = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\VersatileRouter');
$chainedRouter
->expects($this->once())
->method('supports')
->will($this->returnValue(true))
;
$chainedRouter->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->throwException(new RouteNotFoundException()))
;
$chainedRouter->expects($this->once())
->method('getRouteDebugMessage')
->with($name, $parameters)
->will($this->returnValue('message'))
;
$this->router->add($chainedRouter, 10);
$this->router->generate($name, $parameters);
}
public function testGenerateObjectName()
{
$name = new \stdClass();
$parameters = array('test' => 'value');
$defaultRouter = $this->getMock('Symfony\Component\Routing\RouterInterface');
$chainedRouter = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\VersatileRouter');
$defaultRouter
->expects($this->never())
->method('generate')
;
$chainedRouter
->expects($this->once())
->method('supports')
->will($this->returnValue(true))
;
$chainedRouter
->expects($this->once())
->method('generate')
->with($name, $parameters, false)
->will($this->returnValue($name))
;
$this->router->add($defaultRouter, 200);
$this->router->add($chainedRouter, 100);
$result = $this->router->generate($name, $parameters);
$this->assertEquals($name, $result);
}
public function testWarmup()
{
$dir = 'test_dir';
list($low) = $this->createRouterMocks();
$low
->expects($this->never())
->method('warmUp')
;
$high = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\WarmableRouterMock');
$high
->expects($this->once())
->method('warmUp')
->with($dir)
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$this->router->warmUp($dir);
}
public function testRouteCollection()
{
list($low, $high) = $this->createRouterMocks();
$lowcol = new RouteCollection();
$lowcol->add('low', $this->buildMock('Symfony\Component\Routing\Route'));
$highcol = new RouteCollection();
$highcol->add('high', $this->buildMock('Symfony\Component\Routing\Route'));
$low
->expects($this->once())
->method('getRouteCollection')
->will($this->returnValue($lowcol))
;
$high
->expects($this->once())
->method('getRouteCollection')
->will($this->returnValue($highcol))
;
$this->router->add($low, 10);
$this->router->add($high, 100);
$collection = $this->router->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
$names = array();
foreach ($collection->all() as $name => $route) {
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
$names[] = $name;
}
$this->assertEquals(array('high', 'low'), $names);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testSupport()
{
$router = $this->getMock('Symfony\Cmf\Component\Routing\Tests\Routing\VersatileRouter');
$router
->expects($this->once())
->method('supports')
->will($this->returnValue(false))
;
$router
->expects($this->never())
->method('generate')
->will($this->returnValue(false))
;
$this->router->add($router);
$this->router->generate('foobar');
}
/**
* @return RouterInterface[]|\PHPUnit_Framework_MockObject_MockObject[]
*/
protected function createRouterMocks()
{
return array(
$this->getMock('Symfony\Component\Routing\RouterInterface'),
$this->getMock('Symfony\Component\Routing\RouterInterface'),
$this->getMock('Symfony\Component\Routing\RouterInterface'),
);
}
}
abstract class WarmableRouterMock implements RouterInterface, WarmableInterface
{
}
abstract class RequestMatcher implements RouterInterface, RequestMatcherInterface
{
}
abstract class VersatileRouter implements VersatileGeneratorInterface, RequestMatcherInterface
{
}

View file

@ -1,457 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Cmf\Component\Routing\RouteReferrersReadInterface;
use Symfony\Cmf\Component\Routing\ContentAwareGenerator;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class ContentAwareGeneratorTest extends CmfUnitTestCase
{
protected $contentDocument;
protected $routeDocument;
protected $routeCompiled;
protected $provider;
/**
* @var ContentAwareGenerator
*/
protected $generator;
protected $context;
public function setUp()
{
$this->contentDocument = $this->buildMock('Symfony\Cmf\Component\Routing\RouteReferrersReadInterface');
$this->routeDocument = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile'));
$this->routeCompiled = $this->buildMock('Symfony\Component\Routing\CompiledRoute');
$this->provider = $this->buildMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$this->context = $this->buildMock('Symfony\Component\Routing\RequestContext');
$this->generator = new TestableContentAwareGenerator($this->provider);
}
public function testGenerateFromContent()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($this->routeDocument)))
;
$this->routeDocument->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($this->contentDocument));
}
public function testGenerateFromContentId()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$contentRepository = $this->buildMock('Symfony\Cmf\Component\Routing\ContentRepositoryInterface', array('findById', 'getContentId'));
$contentRepository->expects($this->once())
->method('findById')
->with('/content/id')
->will($this->returnValue($this->contentDocument))
;
$this->generator->setContentRepository($contentRepository);
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($this->routeDocument)))
;
$this->routeDocument->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate('', array('content_id' => '/content/id')));
}
public function testGenerateEmptyRouteString()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($this->routeDocument)))
;
$this->routeDocument->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($this->contentDocument));
}
public function testGenerateRouteMultilang()
{
$route_en = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile', 'getContent'));
$route_en->setLocale('en');
$route_de = $this->routeDocument;
$route_de->setLocale('de');
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($route_en, $route_de)))
;
$route_en->expects($this->once())
->method('getContent')
->will($this->returnValue($this->contentDocument))
;
$route_en->expects($this->never())
->method('compile')
;
$route_de->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($route_en, array('_locale' => 'de')));
}
public function testGenerateRouteMultilangDefaultLocale()
{
$route = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock');
$route->expects($this->any())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$route->expects($this->any())
->method('getRequirement')
->with('_locale')
->will($this->returnValue('de|en'))
;
$route->expects($this->any())
->method('getDefault')
->with('_locale')
->will($this->returnValue('en'))
;
$this->routeCompiled->expects($this->any())
->method('getVariables')
->will($this->returnValue(array()))
;
$this->assertEquals('result_url', $this->generator->generate($route, array('_locale' => 'en')));
}
public function testGenerateRouteMultilangLocaleNomatch()
{
$route_en = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile', 'getContent'));
$route_en->setLocale('en');
$route_de = $this->routeDocument;
$route_de->setLocale('de');
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($route_en, $route_de)))
;
$route_en->expects($this->once())
->method('getContent')
->will($this->returnValue($this->contentDocument))
;
$route_en->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$route_de->expects($this->never())
->method('compile')
;
$this->assertEquals('result_url', $this->generator->generate($route_en, array('_locale' => 'fr')));
}
public function testGenerateNoncmfRouteMultilang()
{
$route_en = $this->buildMock('Symfony\Component\Routing\Route', array('getDefaults', 'compile', 'getContent'));
$route_en->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($route_en, array('_locale' => 'de')));
}
public function testGenerateRoutenameMultilang()
{
$name = 'foo/bar';
$route_en = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile', 'getContent'));
$route_en->setLocale('en');
$route_de = $this->routeDocument;
$route_de->setLocale('de');
$this->provider->expects($this->once())
->method('getRouteByName')
->with($name)
->will($this->returnValue($route_en))
;
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($route_en, $route_de)))
;
$route_en->expects($this->once())
->method('getContent')
->will($this->returnValue($this->contentDocument))
;
$route_en->expects($this->never())
->method('compile')
;
$route_de->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($name, array('_locale' => 'de')));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateRoutenameMultilangNotFound()
{
$name = 'foo/bar';
$this->provider->expects($this->once())
->method('getRouteByName')
->with($name)
->will($this->returnValue(null))
;
$this->generator->generate($name, array('_locale' => 'de'));
}
public function testGenerateDocumentMultilang()
{
$route_en = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile'));
$route_en->setLocale('en');
$route_de = $this->routeDocument;
$route_de->setLocale('de');
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($route_en, $route_de)))
;
$route_en->expects($this->never())
->method('compile')
;
$route_de->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($this->contentDocument, array('_locale' => 'de')));
}
public function testGenerateDocumentMultilangLocaleNomatch()
{
$route_en = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults', 'compile'));
$route_en->setLocale('en');
$route_de = $this->routeDocument;
$route_de->setLocale('de');
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($route_en, $route_de)))
;
$route_en->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$route_de->expects($this->never())
->method('compile')
;
$this->assertEquals('result_url', $this->generator->generate($this->contentDocument, array('_locale' => 'fr')));
}
/**
* Generate without any information.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNoContent()
{
$this->generator->generate('', array());
}
/**
* Generate with an object that is neither a route nor route aware.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateInvalidContent()
{
$this->generator->generate($this);
}
/**
* Generate with a content_id but there is no content repository.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNoContentRepository()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$this->generator->generate('', array('content_id' => '/content/id'));
}
/**
* Generate with content_id but the content is not found.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNoContentFoundInRepository()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$contentRepository = $this->buildMock('Symfony\Cmf\Component\Routing\ContentRepositoryInterface', array('findById', 'getContentId'));
$contentRepository->expects($this->once())
->method('findById')
->with('/content/id')
->will($this->returnValue(null))
;
$this->generator->setContentRepository($contentRepository);
$this->generator->generate('', array('content_id' => '/content/id'));
}
/**
* Generate with content_id but the object at id is not route aware.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateWrongContentClassInRepository()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$contentRepository = $this->buildMock('Symfony\Cmf\Component\Routing\ContentRepositoryInterface', array('findById', 'getContentId'));
$contentRepository->expects($this->once())
->method('findById')
->with('/content/id')
->will($this->returnValue($this))
;
$this->generator->setContentRepository($contentRepository);
$this->generator->generate('', array('content_id' => '/content/id'));
}
/**
* Generate from a content that has no routes associated.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNoRoutes()
{
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array()));
$this->generator->generate($this->contentDocument);
}
/**
* Generate from a content that returns something that is not a route as route.
*
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateInvalidRoute()
{
$this->contentDocument->expects($this->once())
->method('getRoutes')
->will($this->returnValue(array($this)));
$this->generator->generate($this->contentDocument);
}
public function testGetLocaleAttribute()
{
$this->generator->setDefaultLocale('en');
$attributes = array('_locale' => 'fr');
$this->assertEquals('fr', $this->generator->getLocale($attributes));
}
public function testGetLocaleDefault()
{
$this->generator->setDefaultLocale('en');
$attributes = array();
$this->assertEquals('en', $this->generator->getLocale($attributes));
}
public function testGetLocaleContext()
{
$this->generator->setDefaultLocale('en');
$this->generator->getContext()->setParameter('_locale', 'de');
$attributes = array();
$this->assertEquals('de', $this->generator->getLocale($attributes));
}
public function testSupports()
{
$this->assertTrue($this->generator->supports(''));
$this->assertTrue($this->generator->supports(null));
$this->assertTrue($this->generator->supports($this->contentDocument));
$this->assertFalse($this->generator->supports($this));
}
public function testGetRouteDebugMessage()
{
$this->assertContains('/some/content', $this->generator->getRouteDebugMessage(null, array('content_id' => '/some/content')));
$this->assertContains('Route aware content Symfony\Cmf\Component\Routing\Tests\Routing\RouteAware', $this->generator->getRouteDebugMessage(new RouteAware()));
$this->assertContains('/some/content', $this->generator->getRouteDebugMessage('/some/content'));
}
}
/**
* Overwrite doGenerate to reduce amount of mocking needed
*/
class TestableContentAwareGenerator extends ContentAwareGenerator
{
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
{
return 'result_url';
}
// expose as public
public function getLocale($parameters)
{
return parent::getLocale($parameters);
}
}
class RouteAware implements RouteReferrersReadInterface
{
public function getRoutes()
{
return array();
}
}

View file

@ -1,330 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Cmf\Component\Routing\Event\Events;
use Symfony\Cmf\Component\Routing\Event\RouterMatchEvent;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\RouteCollection;
use Symfony\Cmf\Component\Routing\DynamicRouter;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class DynamicRouterTest extends CmfUnitTestCase
{
protected $routeDocument;
protected $matcher;
protected $generator;
protected $enhancer;
/** @var DynamicRouter */
protected $router;
protected $context;
public $request;
protected $url = '/foo/bar';
public function setUp()
{
$this->routeDocument = $this->buildMock('Symfony\Cmf\Component\Routing\Tests\Routing\RouteMock', array('getDefaults'));
$this->matcher = $this->buildMock('Symfony\Component\Routing\Matcher\UrlMatcherInterface');
$this->generator = $this->buildMock('Symfony\Cmf\Component\Routing\VersatileGeneratorInterface', array('supports', 'generate', 'setContext', 'getContext', 'getRouteDebugMessage'));
$this->enhancer = $this->buildMock('Symfony\Cmf\Component\Routing\Enhancer\RouteEnhancerInterface', array('enhance'));
$this->context = $this->buildMock('Symfony\Component\Routing\RequestContext');
$this->request = Request::create($this->url);
$this->router = new DynamicRouter($this->context, $this->matcher, $this->generator);
$this->router->addRouteEnhancer($this->enhancer);
}
/**
* rather trivial, but we want 100% coverage
*/
public function testContext()
{
$this->router->setContext($this->context);
$this->assertSame($this->context, $this->router->getContext());
}
public function testRouteCollectionEmpty()
{
$collection = $this->router->getRouteCollection();
$this->assertInstanceOf('Symfony\Component\Routing\RouteCollection', $collection);
}
public function testRouteCollectionLazy()
{
$provider = $this->getMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$router = new DynamicRouter($this->context, $this->matcher, $this->generator, '', null, $provider);
$collection = $router->getRouteCollection();
$this->assertInstanceOf('Symfony\Cmf\Component\Routing\LazyRouteCollection', $collection);
}
/// generator tests ///
public function testGetGenerator()
{
$this->generator->expects($this->once())
->method('setContext')
->with($this->equalTo($this->context));
$generator = $this->router->getGenerator();
$this->assertInstanceOf('Symfony\Component\Routing\Generator\UrlGeneratorInterface', $generator);
$this->assertSame($this->generator, $generator);
}
public function testGenerate()
{
$name = 'my_route_name';
$parameters = array('foo' => 'bar');
$absolute = true;
$this->generator->expects($this->once())
->method('generate')
->with($name, $parameters, $absolute)
->will($this->returnValue('http://test'))
;
$url = $this->router->generate($name, $parameters, $absolute);
$this->assertEquals('http://test', $url);
}
public function testSupports()
{
$name = 'foo/bar';
$this->generator->expects($this->once())
->method('supports')
->with($this->equalTo($name))
->will($this->returnValue(true))
;
$this->assertTrue($this->router->supports($name));
}
public function testSupportsNonversatile()
{
$generator = $this->buildMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface', array('generate', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $this->matcher, $generator);
$this->assertInternalType('string', $router->getRouteDebugMessage('test'));
$this->assertTrue($router->supports('some string'));
$this->assertFalse($router->supports($this));
}
/// match tests ///
public function testGetMatcher()
{
$this->matcher->expects($this->once())
->method('setContext')
->with($this->equalTo($this->context));
$matcher = $this->router->getMatcher();
$this->assertInstanceOf('Symfony\Component\Routing\Matcher\UrlMatcherInterface', $matcher);
$this->assertSame($this->matcher, $matcher);
}
public function testMatchUrl()
{
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->will($this->returnValue($routeDefaults))
;
$expected = array('this' => 'that');
$this->enhancer->expects($this->once())
->method('enhance')
->with($this->equalTo($routeDefaults), $this->equalTo($this->request))
->will($this->returnValue($expected))
;
$results = $this->router->match($this->url);
$this->assertEquals($expected, $results);
}
public function testMatchRequestWithUrlMatcher()
{
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->will($this->returnValue($routeDefaults))
;
$expected = array('this' => 'that');
$this->enhancer->expects($this->once())
->method('enhance')
// somehow request object gets confused, check on instance only
->with($this->equalTo($routeDefaults), $this->isInstanceOf('Symfony\Component\HttpFoundation\Request'))
->will($this->returnValue($expected))
;
$results = $this->router->matchRequest($this->request);
$this->assertEquals($expected, $results);
}
public function testMatchRequest()
{
$routeDefaults = array('foo' => 'bar');
$matcher = $this->buildMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface', array('matchRequest', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $matcher, $this->generator);
$matcher->expects($this->once())
->method('matchRequest')
->with($this->request)
->will($this->returnValue($routeDefaults))
;
$expected = array('this' => 'that');
$this->enhancer->expects($this->once())
->method('enhance')
->with($this->equalTo($routeDefaults), $this->equalTo($this->request))
->will($this->returnValue($expected))
;
$router->addRouteEnhancer($this->enhancer);
$this->assertEquals($expected, $router->matchRequest($this->request));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testMatchFilter()
{
$router = new DynamicRouter($this->context, $this->matcher, $this->generator, '#/different/prefix.*#');
$router->addRouteEnhancer($this->enhancer);
$this->matcher->expects($this->never())
->method('match')
;
$this->enhancer->expects($this->never())
->method('enhance')
;
$router->match($this->url);
}
/**
* @expectedException \Symfony\Component\Routing\Exception\ResourceNotFoundException
*/
public function testMatchRequestFilter()
{
$matcher = $this->buildMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface', array('matchRequest', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $matcher, $this->generator, '#/different/prefix.*#');
$router->addRouteEnhancer($this->enhancer);
$matcher->expects($this->never())
->method('matchRequest')
;
$this->enhancer->expects($this->never())
->method('enhance')
;
$router->matchRequest($this->request);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testMatchUrlWithRequestMatcher()
{
$matcher = $this->buildMock('Symfony\Component\Routing\Matcher\RequestMatcherInterface', array('matchRequest', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $matcher, $this->generator);
$router->match($this->url);
}
/**
* @expectedException \InvalidArgumentException
*/
public function testInvalidMatcher()
{
new DynamicRouter($this->context, $this, $this->generator);
}
public function testRouteDebugMessage()
{
$this->generator->expects($this->once())
->method('getRouteDebugMessage')
->with($this->equalTo('test'), $this->equalTo(array()))
->will($this->returnValue('debug message'))
;
$this->assertEquals('debug message', $this->router->getRouteDebugMessage('test'));
}
public function testRouteDebugMessageNonversatile()
{
$generator = $this->buildMock('Symfony\Component\Routing\Generator\UrlGeneratorInterface', array('generate', 'setContext', 'getContext'));
$router = new DynamicRouter($this->context, $this->matcher, $generator);
$this->assertInternalType('string', $router->getRouteDebugMessage('test'));
}
public function testEventHandler()
{
$eventDispatcher = $this->buildMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$router = new DynamicRouter($this->context, $this->matcher, $this->generator, '', $eventDispatcher);
$eventDispatcher->expects($this->once())
->method('dispatch')
->with(Events::PRE_DYNAMIC_MATCH, $this->equalTo(new RouterMatchEvent()))
;
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->will($this->returnValue($routeDefaults))
;
$this->assertEquals($routeDefaults, $router->match($this->url));
}
public function testEventHandlerRequest()
{
$eventDispatcher = $this->buildMock('Symfony\Component\EventDispatcher\EventDispatcherInterface');
$router = new DynamicRouter($this->context, $this->matcher, $this->generator, '', $eventDispatcher);
$that = $this;
$eventDispatcher->expects($this->once())
->method('dispatch')
->with(Events::PRE_DYNAMIC_MATCH_REQUEST, $this->callback(function ($event) use ($that) {
$that->assertInstanceOf('Symfony\Cmf\Component\Routing\Event\RouterMatchEvent', $event);
$that->assertEquals($that->request, $event->getRequest());
return true;
}))
;
$routeDefaults = array('foo' => 'bar');
$this->matcher->expects($this->once())
->method('match')
->with($this->url)
->will($this->returnValue($routeDefaults))
;
$this->assertEquals($routeDefaults, $router->matchRequest($this->request));
}
}

View file

@ -1,42 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
use Symfony\Component\Routing\Route;
/**
* Tests the lazy route collection.
*
* @group cmf/routing
*/
class LazyRouteCollectionTest extends CmfUnitTestCase
{
/**
* Tests the iterator without a paged route provider.
*/
public function testGetIterator()
{
$routeProvider = $this->getMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$testRoutes = array(
'route_1' => new Route('/route-1'),
'route_2"' => new Route('/route-2'),
);
$routeProvider->expects($this->exactly(2))
->method('getRoutesByNames')
->with(null)
->will($this->returnValue($testRoutes));
$lazyRouteCollection = new LazyRouteCollection($routeProvider);
$this->assertEquals($testRoutes, iterator_to_array($lazyRouteCollection->getIterator()));
$this->assertEquals($testRoutes, $lazyRouteCollection->all());
}
}

View file

@ -1,132 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
use Symfony\Component\Routing\Route;
/**
* Tests the page route collection.
*
* @group cmf/routing
*/
class PagedRouteCollectionTest extends CmfUnitTestCase
{
/**
* Contains a mocked route provider.
*
* @var \Symfony\Cmf\Component\Routing\PagedRouteProviderInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $routeProvider;
protected function setUp()
{
$this->routeProvider = $this->getMock('Symfony\Cmf\Component\Routing\PagedRouteProviderInterface');
}
/**
* Tests iterating a small amount of routes.
*
* @dataProvider providerIterator
*/
public function testIterator($amountRoutes, $routesLoadedInParallel, $expectedCalls = array())
{
$routes = array();
for ($i = 0; $i < $amountRoutes; $i++) {
$routes['test_' . $i] = new Route("/example-$i");
}
$names = array_keys($routes);
foreach ($expectedCalls as $i => $range)
{
$this->routeProvider->expects($this->at($i))
->method('getRoutesPaged')
->with($range[0], $range[1])
->will($this->returnValue(array_slice($routes, $range[0], $range[1])));
}
$route_collection = new PagedRouteCollection($this->routeProvider, $routesLoadedInParallel);
$counter = 0;
foreach ($route_collection as $route_name => $route) {
// Ensure the route did not changed.
$this->assertEquals($routes[$route_name], $route);
// Ensure that the order did not changed.
$this->assertEquals($route_name, $names[$counter]);
$counter++;
}
}
/**
* Provides test data for testIterator().
*/
public function providerIterator()
{
$data = array();
// Non total routes.
$data[] = array(0, 20, array(array(0, 20)));
// Less total routes than loaded in parallel.
$data[] = array(10, 20, array(array(0, 20)));
// Exact the same amount of routes then loaded in parallel.
$data[] = array(20, 20, array(array(0, 20), array(20, 20)));
// Less than twice the amount.
$data[] = array(39, 20, array(array(0, 20), array(20, 20)));
// More total routes than loaded in parallel.
$data[] = array(40, 20, array(array(0, 20), array(20, 20), array(40, 20)));
$data[] = array(41, 20, array(array(0, 20), array(20, 20), array(40, 20)));
// why not.
$data[] = array(42, 23, array(array(0, 23), array(23, 23)));
return $data;
}
/**
* Tests the count() method.
*/
public function testCount()
{
$this->routeProvider->expects($this->once())
->method('getRoutesCount')
->will($this->returnValue(12));
$routeCollection = new PagedRouteCollection($this->routeProvider);
$this->assertEquals(12, $routeCollection->count());
}
/**
* Tests the rewind method once the iterator is at the end.
*/
public function testIteratingAndRewind()
{
$routes = array();
for ($i = 0; $i < 30; $i++) {
$routes['test_' . $i] = new Route("/example-$i");
}
$this->routeProvider->expects($this->any())
->method('getRoutesPaged')
->will($this->returnValueMap(array(
array(0, 10, array_slice($routes, 0, 10)),
array(10, 10, array_slice($routes, 9, 10)),
array(20, 10, array()),
)));
$routeCollection = new PagedRouteCollection($this->routeProvider, 10);
// Force the iterating process.
$routeCollection->rewind();
for ($i = 0; $i < 29; $i++) {
$routeCollection->next();
}
$routeCollection->rewind();
$this->assertEquals('test_0', $routeCollection->key());
$this->assertEquals($routes['test_0'], $routeCollection->current());
}
}

View file

@ -1,149 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\Routing\RequestContext;
use Symfony\Component\Routing\Route;
use Symfony\Cmf\Component\Routing\ProviderBasedGenerator;
use Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase;
class ProviderBasedGeneratorTest extends CmfUnitTestCase
{
protected $routeDocument;
protected $routeCompiled;
protected $provider;
/** @var ProviderBasedGenerator */
protected $generator;
protected $context;
public function setUp()
{
$this->routeDocument = $this->buildMock('Symfony\Component\Routing\Route', array('getDefaults', 'compile'));
$this->routeCompiled = $this->buildMock('Symfony\Component\Routing\CompiledRoute');
$this->provider = $this->buildMock('Symfony\Cmf\Component\Routing\RouteProviderInterface');
$this->context = $this->buildMock('Symfony\Component\Routing\RequestContext');
$this->generator= new TestableProviderBasedGenerator($this->provider);
}
public function testGenerateFromName()
{
$name = 'foo/bar';
$this->provider->expects($this->once())
->method('getRouteByName')
->with($name)
->will($this->returnValue($this->routeDocument))
;
$this->routeDocument->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($name));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNotFound()
{
$name = 'foo/bar';
$this->provider->expects($this->once())
->method('getRouteByName')
->with($name)
->will($this->returnValue(null))
;
$this->generator->generate($name);
}
public function testGenerateFromRoute()
{
$this->provider->expects($this->never())
->method('getRouteByName')
;
$this->routeDocument->expects($this->once())
->method('compile')
->will($this->returnValue($this->routeCompiled))
;
$this->assertEquals('result_url', $this->generator->generate($this->routeDocument));
}
public function testSupports()
{
$this->assertTrue($this->generator->supports('foo/bar'));
$this->assertTrue($this->generator->supports($this->routeDocument));
$this->assertFalse($this->generator->supports($this));
}
public function testGetRouteDebugMessage()
{
$this->assertContains('/some/key', $this->generator->getRouteDebugMessage(new RouteObject()));
$this->assertContains('/de/test', $this->generator->getRouteDebugMessage(new Route('/de/test')));
$this->assertContains('/some/route', $this->generator->getRouteDebugMessage('/some/route'));
$this->assertContains('a:1:{s:10:"route_name";s:7:"example";}', $this->generator->getRouteDebugMessage(array('route_name' => 'example')));
}
/**
* Tests the generate method with passing in a route object into generate().
*
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
*/
public function testGenerateByRoute()
{
$this->generator = new ProviderBasedGenerator($this->provider);
// Setup a route with a numeric parameter, but pass in a string, so it
// fails and getRouteDebugMessage should be triggered.
$route = new Route('/test');
$route->setPath('/test/{number}');
$route->setRequirement('number', '\+d');
$this->generator->setStrictRequirements(true);
$context = new RequestContext();
$this->generator->setContext($context);
$this->assertSame(null, $this->generator->generate($route, array('number' => 'string')));
}
}
/**
* Overwrite doGenerate to reduce amount of mocking needed
*/
class TestableProviderBasedGenerator extends ProviderBasedGenerator
{
protected function doGenerate($variables, $defaults, $requirements, $tokens, $parameters, $name, $referenceType, $hostTokens, array $requiredSchemes = array())
{
return 'result_url';
}
}
class RouteObject implements RouteObjectInterface
{
public function getRouteKey()
{
return '/some/key';
}
public function getContent()
{
return null;
}
}

View file

@ -1,55 +0,0 @@
<?php
/*
* This file is part of the Symfony CMF package.
*
* (c) 2011-2014 Symfony CMF
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Cmf\Component\Routing\Tests\Routing;
use Symfony\Component\Routing\Route as SymfonyRoute;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
class RouteMock extends SymfonyRoute implements RouteObjectInterface
{
private $locale;
public function setLocale($locale)
{
$this->locale = $locale;
}
public function getContent()
{
return null;
}
public function getDefaults()
{
$defaults = array();
if (! is_null($this->locale)) {
$defaults['_locale'] = $this->locale;
}
return $defaults;
}
public function getRequirement($key)
{
if (! $key == '_locale') {
throw new \Exception;
}
return $this->locale;
}
public function getRouteKey()
{
return null;
}
}

View file

@ -1,20 +0,0 @@
<?php
$file = __DIR__.'/../vendor/autoload.php';
if (!file_exists($file)) {
throw new RuntimeException('Install dependencies to run test suite.');
}
require_once $file;
spl_autoload_register(function ($class) {
if (0 === strpos($class, 'Symfony\Cmf\Component\Routing\\')) {
$path = __DIR__.'/../'.implode('/', array_slice(explode('\\', $class), 4)).'.php';
if (!stream_resolve_include_path($path)) {
return false;
}
require_once $path;
return true;
}
});