Exemple #1
0
 /**
  * @dataProvider routeProvider
  * @param        Part    $route
  * @param        string  $path
  * @param        integer $offset
  * @param        string  $routeName
  * @param        array   $params
  */
 public function testAssembling(Part $route, $path, $offset, $routeName, array $params = null)
 {
     if ($params === null) {
         // Data which will not match are not tested for assembling.
         return;
     }
     $result = $route->assemble($params, array('name' => $routeName));
     if ($offset !== null) {
         $this->assertEquals($offset, strpos($path, $result, $offset));
     } else {
         $this->assertEquals($path, $result);
     }
 }
Exemple #2
0
 public function getRoute()
 {
     $routeBroker = new RouteBroker();
     $routeBroker->getClassLoader()->registerPlugins(array('literal' => 'Zend\\Mvc\\Router\\Http\\Literal', 'regex' => 'Zend\\Mvc\\Router\\Http\\Regex', 'segment' => 'Zend\\Mvc\\Router\\Http\\Segment', 'wildcard' => 'Zend\\Mvc\\Router\\Http\\Wildcard', 'hostname' => 'Zend\\Mvc\\Router\\Http\\Hostname', 'scheme' => 'Zend\\Mvc\\Router\\Http\\Scheme', 'part' => 'Zend\\Mvc\\Router\\Http\\Part'));
     $route = Part::factory(array('route' => array('type' => 'literal', 'options' => array('route' => '/', 'defaults' => array('controller' => 'ItsHomePage'))), 'may_terminate' => true, 'route_broker' => $routeBroker, 'child_routes' => array('blog' => array('type' => 'literal', 'options' => array('route' => 'blog', 'defaults' => array('controller' => 'ItsBlog')), 'may_terminate' => true, 'child_routes' => array('rss' => array('type' => 'literal', 'options' => array('route' => '/rss', 'defaults' => array('controller' => 'ItsRssBlog')), 'child_routes' => array('sub' => array('type' => 'literal', 'options' => array('route' => '/sub', 'defaults' => array('action' => 'ItsSubRss'))))))), 'forum' => array('type' => 'literal', 'options' => array('route' => 'forum', 'defaults' => array('controller' => 'ItsForum'))), 'foo' => array('type' => 'segment', 'options' => array('route' => 'foo/:foo', 'defaults' => array('controller' => 'ItsFoo')), 'child_routes' => array('wildcard' => array('type' => 'wildcard'))))));
     return $route;
 }
Exemple #3
0
 /**
  * @param mixed $route
  * @param bool $mayTerminate
  * @param RoutePluginManager $routePlugins
  * @param array $childRoutes
  * @param ArrayObject $prototypes
  */
 public function __construct($route, $mayTerminate, RoutePluginManager $routePlugins, array $childRoutes = null, ArrayObject $prototypes = null)
 {
     parent::__construct($route, $mayTerminate, $routePlugins, $childRoutes, $prototypes);
     if ($this->childRoutes !== null) {
         $this->addRoutes($this->childRoutes);
         $this->childRoutes = null;
     }
 }
Exemple #4
0
 /**
  * @group 3711
  */
 public function testPartRouteMarkedAsMayTerminateButWithQueryRouteChildWillMatchChildRoute()
 {
     $options = array('route' => array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/resource', 'defaults' => array('controller' => 'ResourceController', 'action' => 'resource'))), 'route_plugins' => new RoutePluginManager(), 'may_terminate' => true, 'child_routes' => array('query' => array('type' => 'Zend\\Mvc\\Router\\Http\\Query', 'options' => array('defaults' => array('query' => 'string')))));
     $route = Part::factory($options);
     $request = new Request();
     $request->setUri('http://example.com/resource?foo=bar');
     $query = new Parameters(array('foo' => 'bar'));
     $request->setQuery($query);
     $query = $request->getQuery();
     $match = $route->match($request);
     $this->assertInstanceOf('Zend\\Mvc\\Router\\RouteMatch', $match);
     $this->assertEquals('string', $match->getParam('query'));
     $this->assertEquals('bar', $match->getParam('foo'));
 }
Exemple #5
0
 /**
  * @group ZF2-105
  */
 public function testFactoryShouldAcceptTraversableChildRoutes()
 {
     $children = new ArrayObject(array('create' => array('type' => 'Literal', 'options' => array('route' => 'create', 'defaults' => array('controller' => 'user-admin', 'action' => 'edit')))));
     $options = array('route' => array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/admin/users', 'defaults' => array('controller' => 'Admin\\UserController', 'action' => 'index'))), 'route_broker' => new RouteBroker(), 'may_terminate' => true, 'child_routes' => $children);
     $route = Part::factory($options);
     $this->assertInstanceOf('Zend\\Mvc\\Router\\Http\\Part', $route);
 }