Permalink
Browse files

[Routing] unify and fix the loader tests

  • Loading branch information...
1 parent 1678f5a commit 796280757d1ea0825736d4cc2ebf48290dd06f7e @Tobion Tobion committed Mar 5, 2013
@@ -4,5 +4,5 @@
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>
+ <route path="/test"></route>
</routes>
@@ -4,7 +4,7 @@
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}" host="{_locale}.example.com">
+ <r:route id="blog_show" path="/blog/{slug}" host="{_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>
@@ -4,9 +4,8 @@
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="blog_show" pattern="/blog/{slug}">
+ <route id="blog_show" path="/blog/{slug}">
<default key="_controller">MyBundle:Blog:show</default>
<requirement key="_method">GET</requirement>
- <option key="segment_separators">/</option>
<!-- </route> -->
</routes>
@@ -4,7 +4,7 @@
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="blog_show" pattern="/blog/{slug}">
+ <route id="blog_show" path="/blog/{slug}">
<default key="_controller">MyBundle:Blog:show</default>
<requirement key="_method">GET</requirement>
<option key="compiler_class">RouteCompiler</option>
@@ -6,18 +6,18 @@
$collection->add('blog_show', new Route(
'/blog/{slug}',
array('_controller' => 'MyBlogBundle:Blog:show'),
- array('_method' => 'GET', 'locale' => '\w+', '_scheme' => 'https'),
+ array('locale' => '\w+'),
array('compiler_class' => 'RouteCompiler'),
- '{locale}.example.com'
+ '{locale}.example.com',
+ array('https'),
+ array('GET','POST','put','OpTiOnS')
));
$collection->add('blog_show_legacy', new Route(
'/blog/{slug}',
array('_controller' => 'MyBlogBundle:Blog:show'),
- array('locale' => '\w+'),
+ array('_method' => 'GET|POST|put|OpTiOnS', '_scheme' => 'https', 'locale' => '\w+',),
array('compiler_class' => 'RouteCompiler'),
- '{locale}.example.com',
- array('https'),
- array('GET')
+ '{locale}.example.com'
));
return $collection;
@@ -4,16 +4,16 @@
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="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET" schemes="https">
+ <route id="blog_show" path="/blog/{slug}" host="{locale}.example.com" methods="GET|POST put,OpTiOnS" schemes="hTTps">
<default key="_controller">MyBundle:Blog:show</default>
<requirement key="locale">\w+</requirement>
<option key="compiler_class">RouteCompiler</option>
</route>
<route id="blog_show_legacy" pattern="/blog/{slug}" host="{locale}.example.com">
<default key="_controller">MyBundle:Blog:show</default>
- <requirement key="_method">GET</requirement>
- <requirement key="_scheme">https</requirement>
+ <requirement key="_method">GET|POST|put|OpTiOnS</requirement>
+ <requirement key="_scheme">hTTps</requirement>
<requirement key="locale">\w+</requirement>
<option key="compiler_class">RouteCompiler</option>
</route>
@@ -1,17 +1,17 @@
blog_show:
path: /blog/{slug}
- defaults: { _controller: MyBlogBundle:Blog:show }
+ defaults: { _controller: "MyBundle:Blog:show" }
host: "{locale}.example.com"
requirements: { 'locale': '\w+' }
- methods: ['GET']
+ methods: ['GET','POST','put','OpTiOnS']
schemes: ['https']
options:
compiler_class: RouteCompiler
blog_show_legacy:
pattern: /blog/{slug}
- defaults: { _controller: MyBlogBundle:Blog:show }
+ defaults: { _controller: "MyBundle:Blog:show" }
host: "{locale}.example.com"
- requirements: { '_method': 'GET', 'locale': '\w+', _scheme: 'https' }
+ requirements: { '_method': 'GET|POST|put|OpTiOnS', _scheme: https, 'locale': '\w+' }
options:
compiler_class: RouteCompiler
@@ -4,7 +4,7 @@
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">
- <import resource="validpattern.xml" prefix="/{foo}" host="{locale}.example.com">
+ <import resource="validpattern.xml" prefix="/{foo}" host="">
<default key="foo">123</default>
<requirement key="foo">\d+</requirement>
<option key="foo">bar</option>
@@ -1,7 +1,7 @@
-blog_show:
+_blog:
resource: validpattern.yml
prefix: /{foo}
defaults: { 'foo': '123' }
requirements: { 'foo': '\d+' }
options: { 'foo': 'bar' }
- host: "{locale}.example.com"
+ host: ""
@@ -44,12 +44,12 @@ public function testLoadWithRoute()
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
foreach ($routes as $route) {
- $this->assertEquals('/blog/{slug}', $route->getPath());
- $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
- $this->assertEquals('GET', $route->getRequirement('_method'));
- $this->assertEquals('https', $route->getRequirement('_scheme'));
- $this->assertEquals('{locale}.example.com', $route->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+ $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());
}
}
}
@@ -43,14 +43,16 @@ public function testLoadWithRoute()
$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
- $route = $routes['blog_show'];
- $this->assertEquals('/blog/{slug}', $route->getPath());
- $this->assertEquals('MyBundle:Blog:show', $route->getDefault('_controller'));
- $this->assertEquals('GET', $route->getRequirement('_method'));
- $this->assertEquals('https', $route->getRequirement('_scheme'));
- $this->assertEquals('\w+', $route->getRequirement('locale'));
- $this->assertEquals('{locale}.example.com', $route->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+
+ foreach ($routes as $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());
+ }
}
public function testLoadWithNamespacePrefix()
@@ -61,12 +63,12 @@ public function testLoadWithNamespacePrefix()
$this->assertCount(1, $routeCollection->all(), 'One route is loaded');
$route = $routeCollection->get('blog_show');
- $this->assertEquals('/blog/{slug}', $route->getPath());
- $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->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+ $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->assertSame('RouteCompiler', $route->getOption('compiler_class'));
}
public function testLoadWithImport()
@@ -79,12 +81,11 @@ public function testLoadWithImport()
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
foreach ($routes as $route) {
- $this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath());
- $this->assertEquals('MyBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
- $this->assertEquals('123', $routes['blog_show']->getDefault('foo'));
- $this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
- $this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
- $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost());
+ $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());
}
}
@@ -73,7 +73,7 @@ public function testLoadSpecialRouteName()
$this->assertSame('/true', $route->getPath());
}
- public function testLoadWithPattern()
+ public function testLoadWithRoute()
{
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
$routeCollection = $loader->load('validpattern.yml');
@@ -83,13 +83,13 @@ public function testLoadWithPattern()
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
foreach ($routes as $route) {
- $this->assertEquals('/blog/{slug}', $route->getPath());
- $this->assertEquals('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
- $this->assertEquals('GET', $route->getRequirement('_method'));
- $this->assertEquals('https', $route->getRequirement('_scheme'));
- $this->assertEquals('\w+', $route->getRequirement('locale'));
- $this->assertEquals('{locale}.example.com', $route->getHost());
- $this->assertEquals('RouteCompiler', $route->getOption('compiler_class'));
+ $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());
}
}
@@ -101,11 +101,13 @@ public function testLoadWithResource()
$this->assertCount(2, $routes, 'Two routes are loaded');
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
- $this->assertEquals('/{foo}/blog/{slug}', $routes['blog_show']->getPath());
- $this->assertEquals('MyBlogBundle:Blog:show', $routes['blog_show']->getDefault('_controller'));
- $this->assertEquals('123', $routes['blog_show']->getDefault('foo'));
- $this->assertEquals('\d+', $routes['blog_show']->getRequirement('foo'));
- $this->assertEquals('bar', $routes['blog_show']->getOption('foo'));
- $this->assertEquals('{locale}.example.com', $routes['blog_show']->getHost());
+
+ 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());
+ }
}
}

0 comments on commit 7962807

Please sign in to comment.