Beispiel #1
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  */
 protected function setUp()
 {
     $router = new Router();
     $router->addRoute('home', array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/')));
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller[/:action]')));
     $this->url = new UrlHelper();
     $this->url->setRouter($router);
 }
Beispiel #2
0
 public function setUp()
 {
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller[/:action]')));
     $this->router = $router;
     $event = new MvcEvent();
     $event->setRouter($router);
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->plugin = $this->controller->plugin('url');
 }
 protected function setUp()
 {
     $router = new Router();
     $router->addRoute('home', array('type' => 'Zend\\Mvc\\Router\\Http\\Literal', 'options' => array('route' => '/')));
     $router->addRoute('default', array('type' => 'Zend\\Mvc\\Router\\Http\\Segment', 'options' => array('route' => '/:controller[/:action]')));
     $this->request = new Request();
     $serviceManager = new ServiceManager();
     $serviceManager->setService('router', $router);
     $serviceManager->setService('request', $this->request);
     $pluginManager = new HelperPluginManager();
     $pluginManager->setServiceLocator($serviceManager);
     $this->pluginManager = $pluginManager;
 }
 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()
 {
     $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()
 {
     $this->globalFile = __DIR__ . '/TestAsset/Auth2/config/autoload/global.php';
     $this->localFile = __DIR__ . '/TestAsset/Auth2/config/autoload/local.php';
     copy($this->globalFile . '.dist', $this->globalFile);
     copy($this->localFile . '.dist', $this->localFile);
     $writer = new ConfigWriter();
     $global = new ConfigResource(require $this->globalFile, $this->globalFile, $writer);
     $local = new ConfigResource(require $this->localFile, $this->localFile, $writer);
     $moduleModel = $this->getMockBuilder('ZF\\Apigility\\Admin\\Model\\ModuleModel')->disableOriginalConstructor()->getMock();
     $model = new AuthenticationModel($global, $local, $moduleModel);
     $this->controller = new AuthenticationController($model);
     $this->plugins = new ControllerPluginManager();
     $this->plugins->setService('bodyParams', new BodyParams());
     $this->plugins->setService('bodyParam', new BodyParam());
     $this->plugins->setService('params', new Params());
     $this->controller->setPluginManager($this->plugins);
     $this->routeMatch = new RouteMatch([]);
     $this->routeMatch->setMatchedRouteName('zf-apigility/api/authentication');
     $this->event = new MvcEvent();
     $this->event->setRouteMatch($this->routeMatch);
     $config = (require __DIR__ . '/../../config/module.config.php');
     $router = new SimpleRouteStack();
     $router->addRoute('zf-apigility/api/authentication', $config['router']['routes']['zf-apigility']['child_routes']['api']['child_routes']['authentication']);
     $this->event->setRouter($router);
     $this->controller->setEvent($this->event);
 }
 /**
  * addRoute(): defined by RouteStackInterface interface.
  *
  * @see    RouteStackInterface::addRoute()
  * @param  string  $name
  * @param  mixed   $route
  * @param  integer $priority
  * @return TreeRouteStack
  */
 public function addRoute($name, $route, $priority = null)
 {
     if (!$route instanceof RouteInterface) {
         $route = $this->routeFromArray($route);
     }
     return parent::addRoute($name, $route, $priority);
 }
Beispiel #8
0
 public function setUp()
 {
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $router->addRoute('sub', SegmentRoute::factory(array('route' => '/foo/:param', 'defaults' => array('param' => 1))));
     $this->controller = new SampleController();
     $this->request = new Request();
     $this->event = new MvcEvent();
     $this->routeMatch = new RouteMatch(array('controller' => 'controller-sample', 'action' => 'postPage'));
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter($router);
     $this->sessionManager = new SessionManager();
     $this->sessionManager->destroy();
     $this->controller->setEvent($this->event);
     $this->controller->flashMessenger()->setSessionManager($this->sessionManager);
 }
 public function setUp()
 {
     $this->form = new Form();
     $this->collection = new Collection('links', array('count' => 1, 'allow_add' => true, 'target_element' => array('type' => 'ZendTest\\Mvc\\Controller\\Plugin\\TestAsset\\LinksFieldset')));
     $router = new SimpleRouteStack();
     $router->addRoute('home', LiteralRoute::factory(array('route' => '/', 'defaults' => array('controller' => 'ZendTest\\Mvc\\Controller\\TestAsset\\SampleController'))));
     $router->addRoute('sub', SegmentRoute::factory(array('route' => '/foo/:param', 'defaults' => array('param' => 1))));
     $router->addRoute('ctl', SegmentRoute::factory(array('route' => '/ctl/:controller', 'defaults' => array('__NAMESPACE__' => 'ZendTest\\Mvc\\Controller\\TestAsset'))));
     $this->controller = new SampleController();
     $this->request = new Request();
     $this->event = new MvcEvent();
     $this->routeMatch = new RouteMatch(array('controller' => 'controller-sample', 'action' => 'postPage'));
     $this->event->setRequest($this->request);
     $this->event->setRouteMatch($this->routeMatch);
     $this->event->setRouter($router);
     $this->sessionManager = new SessionManager();
     $this->sessionManager->destroy();
     $this->controller->setEvent($this->event);
     $this->controller->flashMessenger()->setSessionManager($this->sessionManager);
 }
 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 #11
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'))));
     $event = new MvcEvent();
     $event->setRouter($router);
     $event->setResponse($this->response);
     $this->controller = new SampleController();
     $this->controller->setEvent($event);
     $this->plugin = $this->controller->plugin('redirect');
 }
 /**
  * {@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;
     });
 }
Beispiel #13
0
    public function setUp()
    {
        $router = new SimpleRouteStack;
        $router->addRoute('home', new LiteralRoute(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()
 {
     StaticEventManager::resetInstance();
     $this->serviceManager = new ServiceManager();
     $this->request = new Request();
     $this->routeMatch = new RouteMatch(array('controller' => 'HtUserRegistration'));
     $this->event = new MvcEvent();
     $this->event->setRouteMatch($this->routeMatch);
     $this->zfcUserMapper = $this->getMock('ZfcUser\\Mapper\\User');
     $this->zfcUserEntity = $this->getMock('ZfcUser\\Entity\\UserInterface');
     $this->userRegistrationService = $this->getMock('HtUserRegistration\\Service\\UserRegistrationServiceInterface');
     $this->userRegistrationMapper = $this->getMock('HtUserRegistration\\Mapper\\UserRegistrationMapperInterface');
     $this->userRegistrationEntity = $this->getMock('HtUserRegistration\\Entity\\UserRegistrationInterface');
     $this->moduleOptions = $this->getMock('HtUserRegistration\\Options\\ModuleOptions');
     $this->moduleOptions->expects($this->any())->method('getPostVerificationRoute')->willReturn($this->redirectRoute);
     $routeStack = new SimpleRouteStack();
     $route = new Segment($this->redirectRoute);
     $routeStack->addRoute($this->redirectRoute, $route);
     $this->event->setRouter($routeStack);
     $this->serviceManager->setService('HtUserRegistration\\ModuleOptions', $this->moduleOptions);
     $this->controller = new UserRegistrationController($this->userRegistrationService);
     $this->controller->setServiceLocator($this->serviceManager);
     $this->controller->setEvent($this->event);
 }
 /**
  * {@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();
 }
Beispiel #16
0
 public function testDefaultParamDoesNotOverrideParamForAssembling()
 {
     $stack = new SimpleRouteStack();
     $stack->addRoute('foo', new TestAsset\DummyRouteWithParam());
     $stack->setDefaultParam('foo', 'baz');
     $this->assertEquals('bar', $stack->assemble(array('foo' => 'bar'), array('name' => 'foo')));
 }
Beispiel #17
0
 public function testHasRoute()
 {
     $stack = new SimpleRouteStack();
     $this->assertEquals(false, $stack->hasRoute('foo'));
     $stack->addRoute('foo', new TestAsset\DummyRoute());
     $this->assertEquals(true, $stack->hasRoute('foo'));
 }