setRouter() public method

Set router
public setRouter ( Zend\Router\RouteStackInterface $router ) : MvcEvent
$router Zend\Router\RouteStackInterface
return MvcEvent
 public function init($controllerName, $actionName = 'index')
 {
     $this->routeMatch = new RouteMatch(['controller' => $controllerName, 'action' => $actionName]);
     $this->event = new MvcEvent();
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter((new RouterFactory())->createService(Bootstrap::getServiceManager()));
     $this->prepareAuthenticateMock();
 }
 public function init($controllerName, $actionName = 'index', $lang = 'en')
 {
     $this->routeMatch = new RouteMatch(array('controller' => $controllerName, 'action' => $actionName, 'lang' => $lang));
     $this->event = new MvcEvent();
     $this->event->setRouteMatch($this->routeMatch);
     /** @var SimpleRouteStack $router */
     $routerFactory = new RouterFactory();
     $router = $routerFactory->createService(clone Bootstrap::getServiceManager());
     $router->setDefaultParam('lang', $lang);
     $this->event->setRouter($router);
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->setApplicationConfig(include __DIR__ . '/../../../../../../tests/config/application.config.php');
     parent::setUp();
     $this->controller = new IdeaController();
     $this->request = new Request();
     $this->response = null;
     $this->routeMatch = new RouteMatch(['controller' => 'project-idea']);
     $this->event = new MvcEvent();
     $router = new SimpleRouteStack();
     $router->addRoute('idea/idea', ['type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => ['route' => "project/idea.html"]]);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     //Get the serviceLocation and inject it into the controller
     $serviceLocator = $this->getApplicationServiceLocator();
     $this->controller->setServiceLocator($serviceLocator);
     $formService = $serviceLocator->get(FormService::class);
     $this->controller->setFormService($formService);
     $ideaServiceMock = $this->getMockBuilder('Project\\Service\\IdeaService')->disableOriginalConstructor()->getMock();
     $newEntityResult = new Idea();
     $newEntityResult->setId(1);
     $ideaServiceMock->expects($this->any())->method('newEntity')->will($this->returnValue($newEntityResult));
     $ideaServiceMock->expects($this->any())->method('findAll')->will($this->returnValue([]));
     $this->controller->setIdeaService($serviceLocator->get(IdeaService::class));
     $serviceManager = $this->getApplicationServiceLocator();
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService(IdeaService::class, $ideaServiceMock);
     $authorizeServiceMock = $this->getMockBuilder('BjyAuthorize\\View\\Helper\\IsAllowed')->disableOriginalConstructor()->getMock();
     $authorizeServiceMock->expects($this->any())->method('__invoke')->will($this->returnValue(true));
     $serviceManager = $this->getApplicationServiceLocator()->get('viewhelpermanager');
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('isAllowed', $authorizeServiceMock);
     $this->controller->getPluginManager()->setFactory('zfcUserAuthentication', function ($sm) {
         $serviceLocator = $sm->getController()->getServiceLocator();
         $authService = new AuthenticationService();
         $nonPersistent = new NonPersistent();
         /**
          * Store a reference if the contact in the session
          */
         $entityManager = $serviceLocator->get('doctrine.entitymanager.orm_default');
         $contact = $entityManager->getReference("Contact\\Entity\\Contact", 1);
         $nonPersistent->write($contact);
         $authService->setStorage($nonPersistent);
         $authAdapter = $serviceLocator->get('ZfcUser\\Authentication\\Adapter\\AdapterChain');
         $controllerPlugin = new \ZfcUser\Controller\Plugin\ZfcUserAuthentication();
         $controllerPlugin->setAuthService($authService);
         $controllerPlugin->setAuthAdapter($authAdapter);
         return $controllerPlugin;
     });
 }
 protected function setUp()
 {
     $serviceManager = Bootstrap::getServiceManager();
     $this->controller = new HotelController();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->event = new MvcEvent();
     $config = $serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($serviceManager);
 }
Beispiel #5
0
 protected function setUp()
 {
     $serviceManagerGrabber = new ServiceManagerGrabber();
     $this->serviceManager = $serviceManagerGrabber->getServiceManager();
     $this->serviceManager->setAllowOverride(true);
     $this->serviceManager->setService('doctrine.entitymanager.orm_default', $this->getEntityManagerMock());
     $config = $this->serviceManager->get('Config');
     $this->request = new PhpEnviromentRequest();
     $this->router = HttpRouter::factory(isset($config['router']) ? $config['router'] : array());
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->routeMatch->setParam('lang', 'it');
     $this->event = new MvcEvent();
     $this->event->setRouter($this->router);
     $this->event->setRouteMatch($this->routeMatch);
 }
Beispiel #6
0
 /**
  * Setup for tests
  *
  * @return null
  */
 public function setUp()
 {
     $this->mockPageRepo = $this->getMockBuilder('\\Rcm\\Repository\\Page')->disableOriginalConstructor()->getMock();
     $this->mockPageRepo->expects($this->any())->method('getPageByName')->will($this->returnCallback([$this, 'pageRepoMockCallback']));
     $mockLayoutManager = $this->getMockBuilder('\\Rcm\\Service\\LayoutManager')->disableOriginalConstructor()->getMock();
     $mockLayoutManager->expects($this->any())->method('getSiteLayout')->will($this->returnCallback([$this, 'layoutManagerMockCallback']));
     $this->mockUserServicePlugin = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RcmIsAllowed')->disableOriginalConstructor()->getMock();
     $this->mockIsPageAllowed = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RcmIsPageAllowed')->disableOriginalConstructor()->getMock();
     $this->mockShouldShowRevisions = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\ShouldShowRevisions')->disableOriginalConstructor()->getMock();
     $this->mockRedirectToPage = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\RedirectToPage')->disableOriginalConstructor()->getMock();
     $this->mockIsSiteAdmin = $this->getMockBuilder('\\Rcm\\Controller\\Plugin\\IsSiteAdmin')->disableOriginalConstructor()->getMock();
     $this->currentSite = new Site();
     $this->currentSite->setSiteId(1);
     $this->currentSite->setNotFoundPage('not-found');
     $config = ['contentManager' => ['type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => ['route' => '/rcm[/:page][/:revision]', 'defaults' => ['controller' => 'Rcm\\Controller\\IndexController', 'action' => 'index']]], 'contentManagerWithPageType' => ['type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => ['route' => '/rcm/:pageType/:page[/:revision]', 'constraints' => ['pageType' => '[a-z]'], 'defaults' => ['controller' => 'Rcm\\Controller\\IndexController', 'action' => 'index']]]];
     /** @var \Rcm\Service\LayoutManager $mockLayoutManager */
     $this->controller = new IndexController($mockLayoutManager, $this->currentSite, $this->mockPageRepo);
     $this->controller->getPluginManager()->setService('rcmIsAllowed', $this->mockUserServicePlugin)->setService('shouldShowRevisions', $this->mockShouldShowRevisions)->setService('redirectToPage', $this->mockRedirectToPage)->setService('rcmIsSiteAdmin', $this->mockIsSiteAdmin)->setService('rcmIsPageAllowed', $this->mockIsPageAllowed);
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(['controller' => 'index']);
     $this->event = new MvcEvent();
     $routerConfig = $config;
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
 }
Beispiel #7
0
 public function setUp()
 {
     $this->router = $router = new TreeRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $route2 = new Segment('/help');
     $router->addRoute('docs', $route2);
     $router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]'], 'may_terminate' => true, 'child_routes' => ['children' => ['type' => 'literal', 'options' => ['route' => '/children']]]], 'users' => ['type' => 'segment', 'options' => ['route' => '/users[/:id]']], 'contacts' => ['type' => 'segment', 'options' => ['route' => '/contacts[/:id]']], 'embedded' => ['type' => 'segment', 'options' => ['route' => '/embedded[/:id]']], 'embedded_custom' => ['type' => 'segment', 'options' => ['route' => '/embedded_custom[/:custom_id]']]]]);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $router->setRequestUri(new Http('http://localhost.localdomain/resource'));
     $controller = $this->controller = $this->getMock('Zend\\Mvc\\Controller\\AbstractRestfulController');
     $controller->expects($this->any())->method('getEvent')->will($this->returnValue($event));
     $this->urlHelper = $urlHelper = new UrlHelper();
     $urlHelper->setRouter($router);
     $this->serverUrlHelper = $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $this->plugin = $plugin = new HalHelper();
     $plugin->setController($controller);
     $plugin->setUrlHelper($urlHelper);
     $plugin->setServerUrlHelper($serverUrlHelper);
     $linkExtractor = new LinkExtractor($serverUrlHelper, $urlHelper);
     $linkCollectionExtractor = new LinkCollectionExtractor($linkExtractor);
     $plugin->setLinkCollectionExtractor($linkCollectionExtractor);
 }
 public function setUp()
 {
     $this->controller = $controller = new RestController();
     $this->router = $router = new SimpleRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $event->setRouteMatch(new RouteMatch([]));
     $controller->setEvent($event);
     $controller->setRoute('resource');
     $pluginManager = new PluginManager();
     $pluginManager->setService('bodyParams', new BodyParams());
     $controller->setPluginManager($pluginManager);
     $urlHelper = new UrlHelper();
     $urlHelper->setRouter($this->router);
     $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $linksHelper = new HalHelper();
     $linksHelper->setUrlHelper($urlHelper);
     $linksHelper->setServerUrlHelper($serverUrlHelper);
     $linkExtractor = new LinkExtractor($serverUrlHelper, $urlHelper);
     $linkCollectionExtractor = new LinkCollectionExtractor($linkExtractor);
     $linksHelper->setLinkCollectionExtractor($linkCollectionExtractor);
     $pluginManager->setService('Hal', $linksHelper);
     $linksHelper->setController($controller);
     $this->resource = $resource = new Resource();
     $controller->setResource($resource);
 }
Beispiel #9
0
 public function setUp()
 {
     parent::setUp();
     $this->_serviceManager = \Bootstrap::getServiceManager();
     $this->controller = new GridController();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array());
     $this->event = new MvcEvent();
     $config = $this->_serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($this->_serviceManager);
 }
Beispiel #10
0
 public function setUp()
 {
     $routerClass = class_exists(V2TreeRouteStack::class) ? V2TreeRouteStack::class : TreeRouteStack::class;
     $routeClass = class_exists(V2Segment::class) ? V2Segment::class : Segment::class;
     $this->router = $router = new $routerClass();
     $route = new $routeClass('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $route2 = new $routeClass('/help');
     $router->addRoute('docs', $route2);
     $router->addRoute('hostname', ['type' => 'hostname', 'options' => ['route' => 'localhost.localdomain'], 'child_routes' => ['resource' => ['type' => 'segment', 'options' => ['route' => '/resource[/:id]'], 'may_terminate' => true, 'child_routes' => ['children' => ['type' => 'literal', 'options' => ['route' => '/children']]]], 'users' => ['type' => 'segment', 'options' => ['route' => '/users[/:id]']], 'contacts' => ['type' => 'segment', 'options' => ['route' => '/contacts[/:id]']], 'embedded' => ['type' => 'segment', 'options' => ['route' => '/embedded[/:id]']], 'embedded_custom' => ['type' => 'segment', 'options' => ['route' => '/embedded_custom[/:custom_id]']]]]);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $router->setRequestUri(new Http('http://localhost.localdomain/resource'));
     $controller = $this->controller = $this->prophesize(AbstractRestfulController::class);
     $controller->getEvent()->willReturn($event);
     $this->urlHelper = $urlHelper = new UrlHelper();
     $urlHelper->setRouter($router);
     $this->serverUrlHelper = $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $this->plugin = $plugin = new HalHelper();
     $plugin->setController($controller->reveal());
     $linkUrlBuilder = new LinkUrlBuilder($serverUrlHelper, $urlHelper);
     $plugin->setLinkUrlBuilder($linkUrlBuilder);
     $linkExtractor = new LinkExtractor($linkUrlBuilder);
     $linkCollectionExtractor = new LinkCollectionExtractor($linkExtractor);
     $plugin->setLinkCollectionExtractor($linkCollectionExtractor);
 }
 public function setUp()
 {
     $this->controller = $controller = new ResourceController();
     $this->router = $router = new SimpleRouteStack();
     $route = new Segment('/resource[/[:id]]');
     $router->addRoute('resource', $route);
     $this->event = $event = new MvcEvent();
     $event->setRouter($router);
     $event->setRouteMatch(new RouteMatch(array()));
     $controller->setEvent($event);
     $controller->setRoute('resource');
     $pluginManager = new PluginManager();
     $controller->setPluginManager($pluginManager);
     $urlHelper = new UrlHelper();
     $urlHelper->setRouter($this->router);
     $serverUrlHelper = new ServerUrlHelper();
     $serverUrlHelper->setScheme('http');
     $serverUrlHelper->setHost('localhost.localdomain');
     $linksHelper = new Plugin\HalLinks();
     $linksHelper->setUrlHelper($urlHelper);
     $linksHelper->setServerUrlHelper($serverUrlHelper);
     $pluginManager->setService('HalLinks', $linksHelper);
     $linksHelper->setController($controller);
     $this->resource = $resource = new Resource();
     $controller->setResource($resource);
 }
 public function setUp()
 {
     parent::setUp();
     $this->controller = new $this->controllerStringName();
     $this->request = $this->controller->getRequest();
     $this->response = $this->controller->getResponse();
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->event = new MvcEvent();
     $config = $this->getService('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($this->serviceManager);
 }
Beispiel #13
0
 public function onBootstrap(MvcEvent $e)
 {
     $callback = function ($e) {
         $e->setRouter(new ConsoleRouter());
     };
     $events = $e->getApplication()->getEventManager();
     $events->attach('route', $callback, 10000);
 }
 /**
  * @see PHPUnit_Framework_TestCase::setUp()
  */
 protected function setUp()
 {
     $oServiceManager = \TranslatorToolsTest\Bootstrap::getServiceManager();
     $this->configuration = \Zend\Stdlib\ArrayUtils::merge($oServiceManager->get('Config'), include __DIR__ . '/../configuration.php');
     $bAllowOverride = $oServiceManager->getAllowOverride();
     if (!$bAllowOverride) {
         $oServiceManager->setAllowOverride(true);
     }
     $oServiceManager->setService('Config', $this->configuration)->setAllowOverride($bAllowOverride);
     $this->controller = new \TranslatorTools\Controller\ToolsController();
     $this->request = new \Zend\Http\Request();
     $this->routeMatch = new \Zend\Mvc\Router\RouteMatch(array('controller' => 'tools'));
     $this->event = new \Zend\Mvc\MvcEvent();
     $this->event->setRouter(\Zend\Mvc\Router\Http\TreeRouteStack::factory(isset($this->configuration['router']) ? $this->configuration['router'] : array()))->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($oServiceManager);
 }
 protected function setUp()
 {
     $serviceManager = Bootstrap::getServiceManager();
     $this->fileSystem = vfsStream::setup('public', null, array('img' => array('test.jpg' => file_get_contents(__DIR__ . '/../../_files/test.jpg')), 'processed' => array()));
     /** @var \TckImageResizer\Service\ImageProcessing $imageProcessing */
     $imageProcessing = $serviceManager->get('TckImageResizer\\Service\\ImageProcessing');
     $this->controller = new IndexController($imageProcessing, vfsStream::url('public'));
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->event = new MvcEvent();
     $config = $serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($serviceManager);
 }
Beispiel #16
0
 public function setUp()
 {
     $serviceManager = Bootstrap::getServiceManager();
     $this->setApplicationConfig($serviceManager->get('ApplicationConfig'));
     $this->controller = new LogController($this->getApplicationServiceLocator());
     $this->controller->setTranslator($serviceManager->get('Translator'));
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'log'));
     $this->event = new MvcEvent();
     $config = $serviceManager->get('config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->entityManager = $this->controller->getServiceLocator()->get('entity-manager');
     parent::setUp();
 }
Beispiel #17
0
 /**
  * Setup for tests
  *
  * @return null
  */
 public function setUp()
 {
     $config = ['Rcm\\Api\\Page\\Check' => ['type' => 'Segment', 'options' => ['route' => '/rcm/page/check[/:pageType]/:pageId', 'defaults' => ['controller' => 'Rcm\\Controller\\PageCheckController']]]];
     $this->mockPageValidator = $this->getMockBuilder('\\Rcm\\Validator\\Page')->disableOriginalConstructor()->getMock();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('Rcm\\Validator\\Page', $this->mockPageValidator);
     /** @var \Rcm\Service\LayoutManager $mockLayoutManager */
     $this->controller = new PageCheckController($serviceManager);
     $this->request = new Request();
     $this->request->setMethod('GET');
     $this->routeMatch = new RouteMatch(['controller' => 'Rcm\\Controller\\PageCheckController']);
     $this->event = new MvcEvent();
     $routerConfig = $config;
     $router = HttpRouter::factory($routerConfig);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
 }
Beispiel #18
0
 public function setUp()
 {
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $event = new MvcEvent();
     $event->setRouter($router);
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->plugin = $this->controller->plugin('url');
 }
 protected function setUp()
 {
     Bootstrap::setUpAclDatabase();
     // Gather variables
     $serviceManager = Bootstrap::getServiceManager();
     $this->controller = new AuthorizedController();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array());
     $this->event = new MvcEvent();
     $config = $serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     // Setup the actual testcase.
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($serviceManager);
     // Arranging the zfc-user services.
     $authMock = $this->getMock('ZfcUser\\Controller\\Plugin\\ZfcUserAuthentication');
     $this->controller->getPluginManager()->setService('zfcUserAuthentication', $authMock);
 }
 protected function setUp()
 {
     $serviceManager = Bootstrap::getServiceManager();
     $this->controller = new IndexController();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'index'));
     $this->event = new MvcEvent();
     $config = $serviceManager->get('Config');
     $routerConfig = isset($config['router']) ? $config['router'] : array();
     $router = HttpRouter::factory($routerConfig);
     $serviceManager->setAllowOverride(true);
     $serviceManager->setService('AuthService', new AuthenticationService(new Storage\NonPersistent(), new TestAdapter()));
     $albumTableMock = $this->getMockBuilder('Zend\\Mvc\\Controller\\ControllerManager')->disableOriginalConstructor()->getMock();
     $albumTableMock->expects($this->any())->method('get')->will($this->returnValue($this->controller));
     $serviceManager->setService('ControllerManager', $albumTableMock);
     $this->event->setApplication(new Application($config, $serviceManager));
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     $this->controller->setServiceLocator($serviceManager);
 }
 public function getController($controllerClass, $controllerName, $action, $params = [])
 {
     $config = $this->getConfig();
     $controller = $this->getServiceManager()->get('ControllerLoader')->get($controllerClass);
     $event = new MvcEvent();
     $routerConfig = isset($config['router']) ? $config['router'] : [];
     $router = TreeRouteStack::factory($routerConfig);
     $event->setRouter($router);
     $event->setRouteMatch(new RouteMatch(['controller' => $controllerName, 'action' => $action] + $params));
     $controller->setEvent($event);
     return $controller;
 }
 /**
  * {@inheritDoc}
  */
 public function setUp()
 {
     $this->setApplicationConfig(include __DIR__ . '/../../../../../../tests/config/application.config.php');
     parent::setUp();
     $this->controller = new ProjectController();
     $this->request = new Request();
     $this->response = null;
     $this->routeMatch = new RouteMatch(['controller' => 'project-index']);
     $this->event = new MvcEvent();
     $router = new SimpleRouteStack();
     $router->addRoute('route-project_entity_project', ['type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => ['route' => "project/test.html"]]);
     $this->event->setRouter($router);
     $this->event->setRouteMatch($this->routeMatch);
     $this->controller->setEvent($this->event);
     //Get the serviceLocation and inject it into the controller
     $serviceLocator = $this->getApplicationServiceLocator();
     $this->controller->setServiceLocator($serviceLocator);
     $this->controller->setProjectService($serviceLocator->get(ProjectService::class));
     /**
              * Bootstrap the application to have the other information available
     //         */
     //        $application = $serviceLocator->get('application');
     //        $application->bootstrap();
 }
 public function testRouteMatchIsTransformedToProperControllerClassName()
 {
     $moduleListener = new ModuleRouteListener();
     $this->events->attach($moduleListener);
     $this->router->addRoute('foo', array('type' => 'Literal', 'options' => array('route' => '/foo', 'defaults' => array(ModuleRouteListener::MODULE_NAMESPACE => 'Foo', 'controller' => 'some-index'))));
     $this->request->setUri('/foo');
     $event = new MvcEvent();
     $event->setRouter($this->router);
     $event->setRequest($this->request);
     $this->events->trigger('route', $event);
     $matches = $event->getRouteMatch();
     $this->assertInstanceOf('Zend\\Mvc\\Router\\RouteMatch', $matches);
     $this->assertEquals('Foo\\SomeIndex', $matches->getParam('controller'));
     $this->assertEquals('some-index', $matches->getParam(ModuleRouteListener::ORIGINAL_CONTROLLER));
 }
 public function testMultipleRegistrationShouldNotResultInMultiplePrefixingOfControllerName()
 {
     $moduleListener = new ModuleRouteListener();
     $this->events->attach($moduleListener);
     $this->router->addRoute('foo', array('type' => 'Literal', 'options' => array('route' => '/foo', 'defaults' => array(ModuleRouteListener::MODULE_NAMESPACE => 'Foo', 'controller' => 'Index'))));
     $this->request->setUri('/foo');
     $event = new MvcEvent();
     $event->setRouter($this->router);
     $event->setRequest($this->request);
     $this->events->trigger('route', $event);
     $matches = $event->getRouteMatch();
     $this->assertInstanceOf('Zend\\Mvc\\Router\\RouteMatch', $matches);
     $this->assertEquals('Foo\\Index', $matches->getParam('controller'));
     $this->assertEquals('Index', $matches->getParam(ModuleRouteListener::ORIGINAL_CONTROLLER));
 }
Beispiel #25
0
 public function testIsActiveReturnsTrueWhenMatchingRouteWhileUsingModuleRouteListener()
 {
     $page = new Page\Mvc(array('label' => 'mpinkstonwashere', 'route' => 'roflcopter', 'controller' => 'index'));
     $route = new LiteralRoute('/roflcopter');
     $router = new TreeRouteStack();
     $router->addRoute('roflcopter', $route);
     $routeMatch = new RouteMatch(array(ModuleRouteListener::MODULE_NAMESPACE => 'Application\\Controller', 'controller' => 'index'));
     $routeMatch->setMatchedRouteName('roflcopter');
     $event = new MvcEvent();
     $event->setRouter($router)->setRouteMatch($routeMatch);
     $moduleRouteListener = new ModuleRouteListener();
     $moduleRouteListener->onRoute($event);
     $page->setRouter($event->getRouter());
     $page->setRouteMatch($event->getRouteMatch());
     $this->assertEquals(true, $page->isActive());
 }
Beispiel #26
0
 public function setUp()
 {
     $this->response = new Response();
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $this->router = $router;
     $routeMatch = new RouteMatch(array());
     $routeMatch->setMatchedRouteName('home');
     $this->routeMatch = $routeMatch;
     $event = new MvcEvent();
     $event->setRouter($router);
     $event->setResponse($this->response);
     $this->event = $event;
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->plugin = $this->controller->plugin('redirect');
 }
 public function configureControllerForAGivenRoute($controller, $routeName)
 {
     //CONFIGURE ROUTING
     $event = new MvcEvent();
     //build the router and set it as event's router.
     $routeStack = new SimpleRouteStack();
     $route = new Literal('/' . $routeName);
     $routeStack->addRoute($routeName, $route);
     //so that "route >home< not found" error did not show up - add home route.
     $routeHome = new Literal('/');
     $routeStack->addRoute('home', $routeHome);
     $event->setRouter($routeStack);
     //set route match for the event
     $routeMatch = new RouteMatch(['controller' => 'Index', 'action' => $routeName]);
     $routeMatch->setMatchedRouteName($routeName);
     $event->setRouteMatch($routeMatch);
     //finish configuring controller
     $controller->setEvent($event);
     return $controller;
 }
Beispiel #28
0
    public function setUp()
    {
        $this->response = new Response();

        $router = new SimpleRouteStack;
        $router->addRoute('home', new LiteralRoute(array(
            'route'    => '/',
            'defaults' => array(
                'controller' => 'ZendTest\Mvc\Controller\TestAsset\SampleController',
            ),
        )));

        $event = new MvcEvent();
        $event->setRouter($router);
        $event->setResponse($this->response);

        $this->controller = new SampleController();
        $this->controller->setEvent($event);

        $this->plugin = $this->controller->plugin('redirect');
    }
Beispiel #29
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);
 }
Beispiel #30
0
 private function prepareEvent($forApi = false)
 {
     if ($forApi) {
         $controllerMock = $this->getMock(AbstractApiActionController::class);
     } else {
         $controllerMock = $this->getMock(AbstractActionController::class);
     }
     $routerFactory = new RouterFactory();
     $router = $routerFactory->createService(Bootstrap::getServiceManager());
     $event = new MvcEvent();
     $event->setTarget($controllerMock);
     $event->setRouter($router);
     $event->setResponse(new Response());
     return $event;
 }