8000 added tests for the previous XmlFileLoader fixes · symfony/symfony@45987eb · GitHub
[go: up one dir, main page]

Skip to content

Commit 45987eb

Browse files
committed
added tests for the previous XmlFileLoader fixes
1 parent b20d6a7 commit 45987eb

File tree

5 files changed

+48
-2
lines changed

5 files changed

+48
-2
lines changed

src/Symfony/Component/Routing/Loader/XmlFileLoader.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,9 @@ protected function parseImport(RouteCollection $collection, \DOMElement $node, $
166166
*
167167
* @return \DOMDocument
168168
*
169-
* @throws \InvalidArgumentException When loading of XML file returns error
169+
* @throws \InvalidArgumentException When loading of XML file fails because of syntax errors
170+
* or when the XML structure is not as expected by the scheme -
171+
* see validate()
170172
*/
171173
protected function loadFile($file)
172174
{
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route pattern="/test"></route>
8+
</routes>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<routes xmlns="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<route id="myroute"></route>
8+
</routes>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<r:routes xmlns:r="http://symfony.com/schema/routing"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/routing http://symfony.com/schema/routing/routing-1.0.xsd">
6+
7+
<r:route id="blog_show" pattern="/blog/{slug}" hostname-pattern="{_locale}.example.com">
8+
<r:default key="_controller">MyBundle:Blog:show</r:default>
9+
<requirement xmlns="http://symfony.com/schema/routing" key="slug">\w+</requirement>
10+
<r2:requirement xmlns:r2="http://symfony.com/schema/routing" key="_locale">en|fr|de</r2:requirement>
11+
<r:option key="compiler_class">RouteCompiler</r:option>
12+
</r:route>
13+
</r:routes>

src/Symfony/Component/Routing/Tests/Loader/XmlFileLoaderTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,21 @@ public function testLoadWithRoute()
5656
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
5757
}
5858

59+
public function testLoadWithNamespacePrefix()
60+
{
61+
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
62+
$routeCollection = $loader->load('namespaceprefix.xml');
63+
64+
$this->assertCount(1, $routeCollection, 'One route is loaded');
65+
$route = $routeCollection->get('blog_show');
66+
$this->assertEquals('/blog/{slug}', $route->getPattern());
67+
$this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
68+
$this->assertEquals('\w+', $route->getRequirement('slug'));
69+
$this->assertEquals('en|fr|de', $route->getRequirement('_locale'));
70+
$this->assertEquals('{_locale}.example.com', $route->getHostnamePattern());
71+
$this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
72+
}
73+
5974
public function testLoadWithImport()
6075
{
6176
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
@@ -94,7 +109,7 @@ public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidatio
94109

95110
public function getPathsToInvalidFiles()
96111
{
97-
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'));
112+
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
98113
}
99114

100115
/**

0 commit comments

Comments
 (0)
0