Set route match
public setRouteMatch ( Zend\Router\RouteMatch $matches ) : |
||
$matches | Zend\Router\RouteMatch | |
return |
public function testAppNameNotSetWhenMissingInConfig() { $this->moduleOptions->setApplicationName(''); $this->client->expects($this->never())->method('setAppName'); $routeMatch = class_exists(RouteMatch::class) ? new RouteMatch([]) : new RouteMatchV2([]); $this->event->setRouteMatch($routeMatch); $this->listener->onRequest($this->event); }
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 testAppNameNotSetWhenMissingInConfig() { $this->moduleOptions->setApplicationName(""); $this->client->expects($this->never())->method('setAppName'); $routeMatch = new \Zend\Mvc\Router\RouteMatch(array()); $this->event->setRouteMatch($routeMatch); $this->listener->onRequest($this->event); }
/** * Retrieve the composed event * * @return Event */ public function getEvent() { if (!isset($this->event)) { $this->setEvent(new MvcEvent()); $this->event->setRouteMatch(new RouteMatch($this->routeParams)); } return $this->event; }
public function setup() { parent::setup(); $this->controller = $this->serviceManager->get($this->controllerFQDN); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('router' => array('routes' => array($this->controllerRoute => $this->routes[$this->controllerRoute])))); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->controller->setServiceLocator($this->serviceManager); }
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); }
/** * Setup */ public function setUp() { $this->setFormManager(new \StrokerForm\FormManager()); $this->controller = new AjaxController($this->getFormManager()); $this->request = new Request(); $this->response = new Response(); $controllerName = strtolower(str_replace('Controller', '', get_class($this->controller))); $this->routeMatch = new RouteMatch(array('controller' => $controllerName)); $this->event = new MvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); }
/** * {@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() { $this->console = $this->getMockOfConsole(); $this->controller = new IndexController(); $this->event = new MvcEvent(); $this->request = new Request(); $this->response = new Response(); $this->routeMatch = new RouteMatch(array('controller' => 'index')); $this->controller->setConsole($this->console); $this->controller->setEvent($this->event); $this->event->setRequest($this->request); $this->event->setResponse($this->response); $this->event->setRouteMatch($this->routeMatch); }
/** * Faz o setup dos testes. Executado antes de cada teste * @return void */ public function setup() { parent::setup(); //instancia o controller $this->controller = new $this->controllerFQDN(); //cria um novo request $this->request = new Request(); //cria o routeMatch baseado nas configurações do módulo/aplicação $this->routeMatch = new RouteMatch(array('router' => array('routes' => array($this->controllerRoute => $this->routes[$this->controllerRoute])))); //configura a rota para o evento de MVC corrente $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); $this->controller->setServiceLocator($this->serviceManager); }
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); }
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); }
public function setUp() { $this->eventManager = new EventManager(); $this->event = new MvcEvent(); $this->object = new TestObject(); $this->serviceLocator = new ServiceManager(); $this->docs = $this->getMockBuilder('WidRestApiDocumentator\\Service\\Docs')->disableOriginalConstructor()->getMock(); $this->serviceLocator->setService('WidRestApiDocumentator\\Service\\Docs', $this->docs); $this->routeMatch = new RouteMatch(array('controller' => 'WidRestApiDocumentator\\Controller\\Docs')); $this->event->setRouteMatch($this->routeMatch); $this->request = new Request(); $this->response = new Response(); $this->object->setServiceLocator($this->serviceLocator); $this->object->setEventManager($this->eventManager); $this->object->setEvent($this->event); }
/** * 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); }
public function setUp() { // Used by \KJSencha\Service\ApiFactory::createService \Zend\Console\Console::overrideIsConsole(false); $sl = ServiceManagerFactory::getServiceManager(); /* @var $manager DirectManager */ $manager = $sl->get('kjsencha.direct.manager'); /* @var $apiFactory \KJSencha\Direct\Remoting\Api\Api */ $api = $sl->get('kjsencha.api'); $this->controller = new DirectController($manager, $api); $this->request = new Request(); $this->routeMatch = new RouteMatch(array('controller' => 'kjsencha_direct')); $this->event = new MvcEvent(); $this->event->setRouteMatch($this->routeMatch); $this->controller->setEvent($this->event); }
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); }
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); }
public function testOnDispatch() { // Create MvcEvent $e = new MvcEvent(); $e->setViewModel(new ViewModel()); $rm = new RouteMatch([]); $rm->setParam('controller', 'Application\\Controller\\Download'); $e->setRouteMatch($rm); $e->setTarget(new DownloadController([])); // Create EntityManager and EntityRepository $moduleDetail = new ModuleList(); $moduleDetail->setModuleDesc('Pretty description'); $repo = $this->prophesize('Doctrine\\ORM\\EntityRepository'); $repo->findOneBy(['moduleName' => 'Application'])->willReturn($moduleDetail); $em = $this->prophesize('Doctrine\\ORM\\EntityManager'); $em->getRepository('Application\\Entity\\ModuleList')->willReturn($repo); $this->sm->setService('Doctrine\\ORM\\EntityManager', $em->reveal()); // Create ViewHelperManager $headTitle = new HeadTitle(); $vhm = new HelperPluginManager(); $vhm->setService('headTitle', $headTitle); $this->sm->setService('ViewHelperManager', $vhm); $this->module->onDispatch($e); $fbMeta = $e->getViewModel()->getVariable('fbMeta'); $this->assertEquals(sprintf('%s-Real Live Learn ZF2', $moduleDetail->getModuleDesc()), $fbMeta['title']); $this->assertEquals(sprintf('%s-', $moduleDetail->getModuleDesc()), $fbMeta['description']); }
public function setUp() { StaticEventManager::resetInstance(); $mockSharedEventManager = $this->getMock('Zend\EventManager\SharedEventManagerInterface'); $mockSharedEventManager->expects($this->any())->method('getListeners')->will($this->returnValue(array())); $mockEventManager = $this->getMock('Zend\EventManager\EventManagerInterface'); $mockEventManager->expects($this->any())->method('getSharedManager')->will($this->returnValue($mockSharedEventManager)); $mockApplication = $this->getMock('Zend\Mvc\ApplicationInterface'); $mockApplication->expects($this->any())->method('getEventManager')->will($this->returnValue($mockEventManager)); $event = new MvcEvent(); $event->setApplication($mockApplication); $event->setRequest(new Request()); $event->setResponse(new Response()); $routeMatch = new RouteMatch(array('action' => 'test')); $routeMatch->setMatchedRouteName('some-route'); $event->setRouteMatch($routeMatch); $locator = new Locator; $locator->add('forward', function () { return new ForwardController(); }); $this->controller = new SampleController(); $this->controller->setEvent($event); $this->controller->setServiceLocator($locator); $this->plugin = $this->controller->plugin('forward'); }
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); }
public function testCreateServiceWithRouteMatch() { $e = new MvcEvent(); $e->setRouteMatch(new RouteMatch([])); $helper = $this->factory->createService($this->createServiceLocator()); $this->assertInstanceOf('LearnZF2Pagination\\View\\Helper\\QueryUrl', $helper); }
public function onBootstrap(\Zend\Mvc\MvcEvent $e) { $evm = $e->getApplication()->getEventManager(); $evm->attach(\Zend\Mvc\MvcEvent::EVENT_ROUTE, function (\Zend\Mvc\MvcEvent $e) { $evm = $e->getApplication()->getEventManager(); $rm = $e->getRouteMatch(); if ($rm->getParam('cronLock')) { //Work out the filename of the lock file $config = $e->getApplication()->getServiceManager()->get('Config'); $dir = isset($config['cronLockDir']) ? $config['cronLockDir'] : '/tmp'; $filename = preg_replace("([^\\w\\s\\d\\-_~,;:\\[\\]\\(\\).])", '', $rm->getMatchedRouteName()); $file = "{$dir}/{$filename}"; $this->fp = fopen($file, "w"); if (flock($this->fp, LOCK_EX | LOCK_NB)) { //The cron action is not locked $evm->attach(MvcEvent::EVENT_DISPATCH, function ($e) { flock($this->fp, LOCK_UN); }); } else { //This cron action is locked, so redirect and terminate $rm->setMatchedRouteName('lock-cron')->setParam('controller', 'CronLock\\Controller\\CronLock')->setParam('action', 'lockCron'); $e->setRouteMatch($rm); } } return $e; }); }
public function setupServiceManager() { $options = array('service_manager' => array('factories' => array('ViewHelperManager' => 'Zend\\Mvc\\Service\\ViewHelperManagerFactory', 'ControllerPluginManager' => 'Zend\\Mvc\\Service\\ControllerPluginManagerFactory'))); $config = ArrayUtils::merge($options['service_manager'], $this->module->getServiceConfig()); $config['view_helpers'] = $this->module->getViewHelperConfig(); $config['controller_plugins'] = $this->module->getControllerPluginConfig(); $services = new ServiceManager(); $servicesConfig = new Config($config); $servicesConfig->configureServiceManager($services); $services->setService('Config', $config); $event = new MvcEvent(); $event->setRouteMatch(new RouteMatch(array())); $router = $this->getMock('Zend\\Mvc\\Router\\RouteStackInterface'); $services->setService('HttpRouter', $router); $app = $this->getMockBuilder('Zend\\Mvc\\Application')->disableOriginalConstructor()->getMock(); $app->expects($this->once())->method('getMvcEvent')->will($this->returnValue($event)); $services->setService('application', $app); $helpers = $services->get('ViewHelperManager'); $helpersConfig = new Config($config['view_helpers']); $helpersConfig->configureServiceManager($helpers); $plugins = $services->get('ControllerPluginManager'); $pluginsConfig = new Config($config['controller_plugins']); $pluginsConfig->configureServiceManager($plugins); return $services; }
public function setUp() { $this->controller = new TestAsset\ConsoleController(); $routeMatch = new RouteMatch(array('controller' => 'controller-sample')); $event = new MvcEvent(); $event->setRouteMatch($routeMatch); $this->controller->setEvent($event); }
/** * @param array $controllers * @param string $requestedController * @param boolean $expectedResult * @dataProvider shouldCacheProvider */ public function testShouldCache($controllers, $requestedController, $expectedResult) { $this->strategy->setControllers($controllers); $mvcEvent = new MvcEvent(); $mvcEvent->setControllerClass($requestedController); $mvcEvent->setRouteMatch(new RouteMatch(array('controller' => $requestedController))); $this->assertEquals($expectedResult, $this->strategy->shouldCache($mvcEvent)); }
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(); }
/** * @return MvcEvent */ protected function getMvcEvent() { if ($this->mvcEvent === null) { $this->mvcEvent = new MvcEvent(); $this->mvcEvent->setRouteMatch(new \Zend\Mvc\Router\Http\RouteMatch(array())); $this->mvcEvent->setResponse(new \Zend\Http\Response()); } return $this->mvcEvent; }
function it_traps_unauthorized(MvcEvent $event, Response $response, Application $application) { unset($_SERVER['HTTP_X_REQUESTED_WITH']); $event->getTarget()->willReturn($application); $event->setRouteMatch(new RouteMatch(['controller' => 'Controller', 'action' => 'Action']))->shouldBeCalled(); $response->setStatusCode(403)->shouldBeCalled(); $event->getResponse()->willReturn($response); $this->handle($event, AccessService::ACCESS_UNAUTHORIZED)->shouldBe(true); }
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); }