added tests for the previous XmlFileLoader fixes
This commit is contained in:
parent
b20d6a7960
commit
45987eb2b7
@ -166,7 +166,9 @@ class XmlFileLoader extends FileLoader
|
|||||||
*
|
*
|
||||||
* @return \DOMDocument
|
* @return \DOMDocument
|
||||||
*
|
*
|
||||||
* @throws \InvalidArgumentException When loading of XML file returns error
|
* @throws \InvalidArgumentException When loading of XML file fails because of syntax errors
|
||||||
|
* or when the XML structure is not as expected by the scheme -
|
||||||
|
* see validate()
|
||||||
*/
|
*/
|
||||||
protected function loadFile($file)
|
protected function loadFile($file)
|
||||||
{
|
{
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<routes xmlns="http://symfony.com/schema/routing"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
|
<route pattern="/test"></route>
|
||||||
|
</routes>
|
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<routes xmlns="http://symfony.com/schema/routing"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
|
<route id="myroute"></route>
|
||||||
|
</routes>
|
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<r:routes xmlns:r="http://symfony.com/schema/routing"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
|
||||||
|
|
||||||
|
<r:route id="blog_show" pattern="/blog/{slug}" hostname-pattern="{_locale}.example.com">
|
||||||
|
<r:default key="_controller">MyBundle:Blog:show</r:default>
|
||||||
|
<requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement>
|
||||||
|
<r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement>
|
||||||
|
<r:option key="compiler_class">RouteCompiler</r:option>
|
||||||
|
</r:route>
|
||||||
|
</r:routes>
|
@ -56,6 +56,21 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testLoadWithNamespacePrefix()
|
||||||
|
{
|
||||||
|
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||||
|
$routeCollection = $loader->load('namespaceprefix.xml');
|
||||||
|
|
||||||
|
$this->assertCount(1, $routeCollection, 'One route is loaded');
|
||||||
|
$route = $routeCollection->get('blog_show');
|
||||||
|
$this->assertEquals('/blog/{slug}', $route->getPattern());
|
||||||
|
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||||
|
$this->assertEquals('\w+', $route->getRequirement('slug'));
|
||||||
|
$this->assertEquals('en|fr|de', $route->getRequirement('_locale'));
|
||||||
|
$this->assertEquals('{_locale}.example.com', $route->getHostnamePattern());
|
||||||
|
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoadWithImport()
|
public function testLoadWithImport()
|
||||||
{
|
{
|
||||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||||
@ -94,7 +109,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
public function getPathsToInvalidFiles()
|
public function getPathsToInvalidFiles()
|
||||||
{
|
{
|
||||||
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'));
|
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user