From 5ccd013ebf0974b617ca39a8a8d57544729760eb Mon Sep 17 00:00:00 2001 From: Ben Scholzen Date: Sun, 28 Apr 2013 15:51:29 +0200 Subject: [PATCH] Add unit tests for chain route generation in tree route stack --- .../Zend/Mvc/Router/Http/TreeRouteStack.php | 2 +- .../Mvc/Router/Http/TreeRouteStackTest.php | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/library/Zend/Mvc/Router/Http/TreeRouteStack.php b/library/Zend/Mvc/Router/Http/TreeRouteStack.php index ab11d240997..31f56d2bcee 100644 --- a/library/Zend/Mvc/Router/Http/TreeRouteStack.php +++ b/library/Zend/Mvc/Router/Http/TreeRouteStack.php @@ -145,7 +145,7 @@ protected function routeFromArray($specs) throw new Exception\InvalidArgumentException('Chain routes must be an array or Traversable object'); } - $chainRoutes = array($specs) + $specs['chain_routes']; + $chainRoutes = array_merge(array($specs), $specs['chain_routes']); unset($chainRoutes[0]['chain_routes']); $options = array( diff --git a/tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php b/tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php index 68b3d441802..83121acc78a 100644 --- a/tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php +++ b/tests/ZendTest/Mvc/Router/Http/TreeRouteStackTest.php @@ -350,6 +350,39 @@ public function testPriorityIsPassedToPartRoute() $this->assertEquals(1000, $routes->get('foo')->priority); } + public function testPrototypeRoute() + { + $stack = new TreeRouteStack(); + $stack->addPrototype( + 'bar', + array('type' => 'literal', 'options' => array('route' => '/bar')) + ); + $stack->addRoute('foo', 'bar'); + $this->assertEquals('/bar', $stack->assemble(array(), array('name' => 'foo'))); + } + + public function testChainRouteAssembling() + { + $stack = new TreeRouteStack(); + $stack->addPrototype( + 'bar', + array('type' => 'literal', 'options' => array('route' => '/bar')) + ); + $stack->addRoute( + 'foo', + array( + 'type' => 'literal', + 'options' => array( + 'route' => '/foo' + ), + 'chain_routes' => array( + 'bar' + ), + ) + ); + $this->assertEquals('/foo/bar', $stack->assemble(array(), array('name' => 'foo'))); + } + public function testFactory() { $tester = new FactoryTester($this);