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

This commit is contained in:
Greg Anderson 2015-10-08 11:40:12 -07:00
parent eb34d130a8
commit f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions

View file

@ -0,0 +1,139 @@
<?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

@ -0,0 +1,152 @@
<?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);
}
}