Update to drupal 8.0.0-rc1. For more information, see https://www.drupal.org/node/2582663
This commit is contained in:
parent
eb34d130a8
commit
f32e58e4b1
8476 changed files with 211648 additions and 170042 deletions
31
vendor/symfony/routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
31
vendor/symfony/routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function getReader()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
public function getClassLoader($reader)
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
|
||||
->setConstructorArgs(array($reader))
|
||||
->getMockForAbstractClass()
|
||||
;
|
||||
}
|
||||
}
|
188
vendor/symfony/routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
188
vendor/symfony/routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,188 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
private $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = $this->getClassLoader($this->reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadMissingClass()
|
||||
{
|
||||
$this->loader->load('MissingClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadAbstractClass()
|
||||
{
|
||||
$this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestSupportsChecksResource
|
||||
*/
|
||||
public function testSupportsChecksResource($resource, $expectedSupports)
|
||||
{
|
||||
$this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
|
||||
}
|
||||
|
||||
public function provideTestSupportsChecksResource()
|
||||
{
|
||||
return array(
|
||||
array('class', true),
|
||||
array('\fully\qualified\class\name', true),
|
||||
array('namespaced\class\without\leading\slash', true),
|
||||
array('ÿClassWithLegalSpecialCharacters', true),
|
||||
array('5', false),
|
||||
array('foo.foo', false),
|
||||
array(null, false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSupportsChecksTypeIfSpecified()
|
||||
{
|
||||
$this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function getLoadTests()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('name' => 'route1', 'path' => '/path'),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('defaults' => array('arg2' => 'foo'), 'requirements' => array('arg3' => '\w+')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('options' => array('foo' => 'bar')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('schemes' => array('https'), 'methods' => array('GET')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('condition' => 'context.getMethod() == "GET"'),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadTests
|
||||
*/
|
||||
public function testLoad($className, $routeData = array(), $methodArgs = array())
|
||||
{
|
||||
$routeData = array_replace(array(
|
||||
'name' => 'route',
|
||||
'path' => '/',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
'condition' => '',
|
||||
), $routeData);
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($routeData))))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load($className);
|
||||
$route = $routeCollection->get($routeData['name']);
|
||||
|
||||
$this->assertSame($routeData['path'], $route->getPath(), '->load preserves path annotation');
|
||||
$this->assertCount(
|
||||
count($routeData['requirements']),
|
||||
array_intersect_assoc($routeData['requirements'], $route->getRequirements()),
|
||||
'->load preserves requirements annotation'
|
||||
);
|
||||
$this->assertCount(
|
||||
count($routeData['options']),
|
||||
array_intersect_assoc($routeData['options'], $route->getOptions()),
|
||||
'->load preserves options annotation'
|
||||
);
|
||||
$defaults = array_replace($methodArgs, $routeData['defaults']);
|
||||
$this->assertCount(
|
||||
count($defaults),
|
||||
array_intersect_assoc($defaults, $route->getDefaults()),
|
||||
'->load preserves defaults annotation and merges them with default arguments in method signature'
|
||||
);
|
||||
$this->assertEquals($routeData['schemes'], $route->getSchemes(), '->load preserves schemes annotation');
|
||||
$this->assertEquals($routeData['methods'], $route->getMethods(), '->load preserves methods annotation');
|
||||
$this->assertSame($routeData['condition'], $route->getCondition(), '->load preserves condition annotation');
|
||||
}
|
||||
|
||||
public function testClassRouteLoad()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'path' => '/prefix',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$methodRouteData = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/path',
|
||||
'schemes' => array('http'),
|
||||
'methods' => array('POST', 'PUT'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getClassAnnotation')
|
||||
->will($this->returnValue($this->getAnnotatedRoute($classRouteData)))
|
||||
;
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($methodRouteData))))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass');
|
||||
$route = $routeCollection->get($methodRouteData['name']);
|
||||
|
||||
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
|
||||
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
|
||||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
||||
}
|
||||
|
||||
private function getAnnotatedRoute($data)
|
||||
{
|
||||
return new Route($data);
|
||||
}
|
||||
}
|
53
vendor/symfony/routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
53
vendor/symfony/routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
|
||||
class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->exactly(2))->method('getClassAnnotation');
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixturesDir = __DIR__.'/../Fixtures';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
}
|
61
vendor/symfony/routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
61
vendor/symfony/routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
|
||||
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testLoadVariadic()
|
||||
{
|
||||
$route = new Route(array('path' => '/path/to/{id}'));
|
||||
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||
$this->reader->expects($this->once())->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($route)));
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixture = __DIR__.'/../Fixtures/annotated.php';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
}
|
48
vendor/symfony/routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
48
vendor/symfony/routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\ClosureLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$closure = function () {};
|
||||
|
||||
$this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$route = new Route('/');
|
||||
$routes = $loader->load(function () use ($route) {
|
||||
$routes = new RouteCollection();
|
||||
|
||||
$routes->add('foo', $route);
|
||||
|
||||
return $routes;
|
||||
});
|
||||
|
||||
$this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
|
||||
}
|
||||
}
|
82
vendor/symfony/routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
82
vendor/symfony/routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,82 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\PhpFileLoader;
|
||||
|
||||
class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.php');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(1, $routes, 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadWithImport()
|
||||
{
|
||||
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.php');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(1, $routes, 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/prefix/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatDefiningVariableInConfigFileHasNoSideEffects()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('with_define_path_variable.php');
|
||||
$resources = $routeCollection->getResources();
|
||||
$this->assertCount(1, $resources);
|
||||
$this->assertContainsOnly('Symfony\Component\Config\Resource\ResourceInterface', $resources);
|
||||
$fileResource = reset($resources);
|
||||
$this->assertSame(
|
||||
realpath($locator->locate('with_define_path_variable.php')),
|
||||
(string) $fileResource
|
||||
);
|
||||
}
|
||||
}
|
152
vendor/symfony/routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
152
vendor/symfony/routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader;
|
||||
|
||||
class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.xml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyRouteDefinitionLoading()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('legacy_validpattern.xml');
|
||||
$route = $routeCollection->get('blog_show_legacy');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
public function testLoadWithNamespacePrefix()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('namespaceprefix.xml');
|
||||
|
||||
$this->assertCount(1, $routeCollection->all(), 'One route is loaded');
|
||||
|
||||
$route = $routeCollection->get('blog_show');
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{_locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('slug'));
|
||||
$this->assertSame('en|fr|de', $route->getRequirement('_locale'));
|
||||
$this->assertNull($route->getDefault('slug'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
}
|
||||
|
||||
public function testLoadWithImport()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
|
||||
{
|
||||
$loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Document types are not allowed.
|
||||
*/
|
||||
public function testDocTypeIsNotAllowed()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load('withdoctype.xml');
|
||||
}
|
||||
|
||||
public function testNullValues()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('null_values.xml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertTrue($route->hasDefault('foo'));
|
||||
$this->assertNull($route->getDefault('foo'));
|
||||
$this->assertTrue($route->hasDefault('bar'));
|
||||
$this->assertNull($route->getDefault('bar'));
|
||||
$this->assertEquals('foo', $route->getDefault('foobar'));
|
||||
$this->assertEquals('bar', $route->getDefault('baz'));
|
||||
}
|
||||
}
|
130
vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
130
vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
<?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 Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
|
||||
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
|
||||
$this->assertTrue($loader->supports('foo.yaml', 'yaml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$collection = $loader->load('empty.yml');
|
||||
|
||||
$this->assertEquals(array(), $collection->all());
|
||||
$this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(
|
||||
array('nonvalid.yml'),
|
||||
array('nonvalid2.yml'),
|
||||
array('incomplete.yml'),
|
||||
array('nonvalidkeys.yml'),
|
||||
array('nonesense_resource_plus_path.yml'),
|
||||
array('nonesense_type_without_resource.yml'),
|
||||
array('bad_format.yml'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadSpecialRouteName()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('special_route_name.yml');
|
||||
$route = $routeCollection->get('#$péß^a|');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/true', $route->getPath());
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.yml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group legacy
|
||||
*/
|
||||
public function testLegacyRouteDefinitionLoading()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('legacy_validpattern.yml');
|
||||
$route = $routeCollection->get('blog_show_legacy');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
public function testLoadWithResource()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.yml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue