Example #1
0
 public function setUp()
 {
     $this->request = new \Zend\Http\PhpEnvironment\Request();
     $this->events = new \Zend\EventManager\EventManager();
     $this->router = new \Zend\Mvc\Router\Http\TreeRouteStack();
     foreach ($this->routeConfig as $name => $route) {
         $this->router->addRoute($name, $route);
     }
     $this->events->attach(new \Zend\Mvc\RouteListener());
     $this->events->attach(new \Zend\Mvc\ModuleRouteListener(), -1);
 }
 /**
  * Get an initialized instance of the controller plugin
  *
  * If controller setup is requested, the controller will be a
  * \Library\Test\Mvc\Controller\TestController. Its MvcEvent will be
  * initialized with a standard route 'test' (/module/controller/action/)
  * with defaults of "defaultcontroller" and "defaultaction".
  * The RouteMatch is initialized with "currentcontroller" and
  * "currentaction". An empty response is created.
  *
  * @param bool $setController Initialize the helper with a working controller (default: TRUE)
  * @return \Zend\Mvc\Controller\Plugin\PluginInterface Plugin instance
  */
 protected function _getPlugin($setController = true)
 {
     if ($setController) {
         $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
         $router->addRoute('test', \Zend\Mvc\Router\Http\Segment::factory(array('route' => '/[module[/]][:controller[/][:action[/]]]', 'defaults' => array('controller' => 'defaultcontroller', 'action' => 'defaultaction'))));
         $routeMatch = new \Zend\Mvc\Router\RouteMatch(array('controller' => 'currentcontroller', 'action' => 'currentaction'));
         $routeMatch->setMatchedRouteName('test');
         $event = new \Zend\Mvc\MvcEvent();
         $event->setRouter($router);
         $event->setRouteMatch($routeMatch);
         $event->setResponse(new \Zend\Http\Response());
         // Register TestController with the service manager because this is
         // not done in the module setup
         $manager = Application::getService('ControllerManager');
         $manager->setInvokableClass('test', 'Library\\Test\\Mvc\\Controller\\TestController');
         $this->_controller = $manager->get('test');
         $this->_controller->setEvent($event);
         return $this->_controller->plugin($this->_getPluginName());
     } else {
         return $this->_getPluginManager()->get($this->_getPluginName());
     }
 }
Example #3
0
 public function testRemovesModuleRouteListenerParamsWhenReusingMatchedParameters()
 {
     $router = new \Zend\Mvc\Router\Http\TreeRouteStack();
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller/:action', 'defaults' => array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'SampleController', 'action' => 'Dash')), 'child_routes' => array('wildcard' => array('type' => 'Zend\\Mvc\\Router\\Http\\Wildcard', 'options' => array('param_delimiter' => '=', 'key_value_delimiter' => '%')))));
     $routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'ZendTest\\Mvc\\Controller\\TestAsset', 'controller' => 'Rainbow'));
     $routeMatch->setMatchedRouteName('default/wildcard');
     $event = new MvcEvent();
     $event->setRouter($router)->setRouteMatch($routeMatch);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->onRoute($event);
     $controller = new SampleController();
     $controller->setEvent($event);
     $url = $controller->plugin('url')->fromRoute('default/wildcard', array('Twenty' => 'Cooler'), true);
     $this->assertEquals('/Rainbow/Dash=Twenty%Cooler', $url);
 }
<?php

/**
 * This reproduction script shall accompany the issue reported at
 * http://framework.zend.com/issues/browse/ZF-143
 *
 * Assumptions:
 *   ZF2 beta 2
 *
 * Result:
 *   This script should exit without throwing an exception or output
 */
// Ensure ZF is on the include path
set_include_path(implode(PATH_SEPARATOR, array(realpath(__DIR__ . '/../vendor/Zend/library'), get_include_path())));
// Setup autoloader
require_once 'Zend/Loader/AutoloaderFactory.php';
Zend\Loader\AutoloaderFactory::factory(array('Zend\\Loader\\StandardAutoloader' => array('fallback_autoloader' => true)));
// Create a TreeRouteStack with a parent & child route
$router = new Zend\Mvc\Router\Http\TreeRouteStack();
$router->addRoutes(array('core' => array('type' => 'segment', 'options' => array('route' => '/root/:param1', 'defaults' => array('controller' => 'Contents\\Controller\\ContentsController', 'schemas' => array('contents/1' => 'Contents\\View\\Contents1'))), 'may_terminate' => true, 'child_routes' => array('optional-segment' => array('type' => 'segment', 'options' => array('route' => '/child[/:param2]', 'defaults' => array('controller' => 'MyModule\\Controllers\\MyControllerController', 'action' => 'index')))))));
// Setup parameters with one param defined and the other set to NULL (does not exist)
$routeParams = array('param1' => 'unique-identifier', 'param2' => NULL);
// Attempt to assemble a path that would match the child route without the optional parameter
$assembledRoute = $router->assemble($routeParams, array('name' => 'core/optional-segment')) . "\n";
// Expected: $assembledRoute = '/root/unique-identifier/child'