X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fsymfony%2Frouting%2FTests%2FLoader%2FYamlFileLoaderTest.php;fp=vendor%2Fsymfony%2Frouting%2FTests%2FLoader%2FYamlFileLoaderTest.php;h=822bddf1f0c348bee3a56394b54741d64362ab3b;hp=8342c266dfa181fdaf8d490a706eed1b854904fd;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php b/vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php index 8342c266d..822bddf1f 100644 --- a/vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php +++ b/vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php @@ -108,4 +108,99 @@ class YamlFileLoaderTest extends TestCase $this->assertSame('context.getMethod() == "POST"', $route->getCondition()); } } + + public function testLoadRouteWithControllerAttribute() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $routeCollection = $loader->load('routing.yml'); + + $route = $routeCollection->get('app_homepage'); + + $this->assertSame('AppBundle:Homepage:show', $route->getDefault('_controller')); + } + + public function testLoadRouteWithoutControllerAttribute() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $routeCollection = $loader->load('routing.yml'); + + $route = $routeCollection->get('app_logout'); + + $this->assertNull($route->getDefault('_controller')); + } + + public function testLoadRouteWithControllerSetInDefaults() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $routeCollection = $loader->load('routing.yml'); + + $route = $routeCollection->get('app_blog'); + + $this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller')); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/ + */ + public function testOverrideControllerInDefaults() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $loader->load('override_defaults.yml'); + } + + /** + * @dataProvider provideFilesImportingRoutesWithControllers + */ + public function testImportRouteWithController($file) + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $routeCollection = $loader->load($file); + + $route = $routeCollection->get('app_homepage'); + $this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller')); + + $route = $routeCollection->get('app_blog'); + $this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller')); + + $route = $routeCollection->get('app_logout'); + $this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller')); + } + + public function provideFilesImportingRoutesWithControllers() + { + yield array('import_controller.yml'); + yield array('import__controller.yml'); + } + + /** + * @expectedException \InvalidArgumentException + * @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "_static"/ + */ + public function testImportWithOverriddenController() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller'))); + $loader->load('import_override_defaults.yml'); + } + + public function testImportRouteWithGlobMatchingSingleFile() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob'))); + $routeCollection = $loader->load('import_single.yml'); + + $route = $routeCollection->get('bar_route'); + $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller')); + } + + public function testImportRouteWithGlobMatchingMultipleFiles() + { + $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob'))); + $routeCollection = $loader->load('import_multiple.yml'); + + $route = $routeCollection->get('bar_route'); + $this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller')); + + $route = $routeCollection->get('baz_route'); + $this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller')); + } }