Exemple #1
0
 public function testMissingViewScriptDoesDoubleRender()
 {
     \Zend\Controller\Action\HelperBroker::getStack()->offsetSet(-91, new \Zend\Controller\Action\Helper\ViewRenderer());
     // go to the test controller for this funcitonal test
     $this->dispatch('/zend-layout-functional-test-test/missing-view-script');
     $this->assertEquals(trim($this->response->getBody()), "[DEFAULT_LAYOUT_START]\n[DEFAULT_LAYOUT_START]\n[DEFAULT_LAYOUT_END]\n(ErrorController::errorAction output)[DEFAULT_LAYOUT_END]");
 }
Exemple #2
0
 public function testInitializationInjectsViewIntoViewRenderer()
 {
     $resource = new ViewResource(array());
     $resource->init();
     $view = $resource->getView();
     $viewRenderer = HelperBroker::getStaticHelper('ViewRenderer');
     $this->assertSame($view, $viewRenderer->view);
 }
Exemple #3
0
 /**
  * Defined by Zend_Application_Resource_Resource
  *
  * @return \Zend\View\View
  */
 public function init()
 {
     $view = $this->getView();
     $viewRenderer = new \Zend\Controller\Action\Helper\ViewRenderer();
     $viewRenderer->setView($view);
     \Zend\Controller\Action\HelperBroker::addHelper($viewRenderer);
     return $view;
 }
Exemple #4
0
 /**
  * Create JSON response
  *
  * Encodes and returns data to JSON. Content-Type header set to
  * 'application/json', and disables layouts and viewRenderer (if being
  * used).
  *
  * @param  mixed   $data
  * @param  boolean $keepLayouts
  * @param  boolean|array $keepLayouts
  * NOTE:   if boolean, establish $keepLayouts to true|false
  *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
  *         if $keepLayouts and parmas for Zend_Json::encode are required
  *         then, the array can contains a 'keepLayout'=>true|false
  *         that will not be passed to Zend_Json::encode method but will be passed
  *         to Zend_View_Helper_Json
  * @throws \Zend\Controller\Action\Helper\Json
  * @return string
  */
 public function encodeJson($data, $keepLayouts = false)
 {
     $jsonHelper = new \Zend\View\Helper\Json();
     $data = $jsonHelper->direct($data, $keepLayouts);
     if (!$keepLayouts) {
         \Zend\Controller\Action\HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
     }
     return $data;
 }
Exemple #5
0
 public function setUp()
 {
     if (isset($this->error)) {
         unset($this->error);
     }
     $front = Controller\Front::getInstance();
     $front->resetInstance();
     \Zend\Controller\Action\HelperBroker::removeHelper('viewRenderer');
     $this->_dispatcher = new \Zend\Controller\Dispatcher\Standard();
     $this->_dispatcher->setControllerDirectory(array('default' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files', 'admin' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin'));
 }
Exemple #6
0
 public function setUp()
 {
     \Zend\Layout\Layout::resetMvcInstance();
     \Zend\Controller\Front::getInstance()->resetInstance();
     if (HelperBroker::hasHelper('Layout')) {
         HelperBroker::removeHelper('Layout');
     }
     if (HelperBroker::hasHelper('viewRenderer')) {
         HelperBroker::removeHelper('viewRenderer');
     }
 }
Exemple #7
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     \Zend\Layout\Layout::resetMvcInstance();
     $this->response = new \Zend\Controller\Response\Http();
     $this->response->headersSentThrowsException = false;
     $front = \Zend\Controller\Front::getInstance();
     $front->resetInstance();
     $front->setResponse($this->response);
     $this->viewRenderer = new \Zend\Controller\Action\Helper\ViewRenderer();
     \Zend\Controller\Action\HelperBroker::addHelper($this->viewRenderer);
     $this->helper = new \Zend\Controller\Action\Helper\Json();
     $this->helper->suppressExit = true;
 }
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     Layout::resetMvcInstance();
     HelperBroker::resetHelpers();
     HelperBroker::setPluginLoader(null);
     $this->request = new HTTPRequest();
     $this->response = new CLIResponse();
     $this->front = FrontController::getInstance();
     $this->front->resetInstance();
     $this->front->setRequest($this->request)->setResponse($this->response);
     $this->viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
     $this->layout = Layout::startMvc();
 }
Exemple #9
0
 /**
  * Set up redirector
  *
  * Creates request, response, and action controller objects; sets action
  * controller in redirector, and sets exit to false.
  *
  * Also resets the front controller instance.
  */
 public function setUp()
 {
     $front = Controller\Front::getInstance();
     $front->resetInstance();
     \Zend\Controller\Action\HelperBroker::removeHelper('viewRenderer');
     $this->redirector = new \Zend\Controller\Action\Helper\Redirector();
     $this->router = $front->getRouter();
     $this->request = new \Zend\Controller\Request\Http();
     $this->response = new \Zend\Controller\Response\Http();
     $this->controller = new TestController($this->request, $this->response, array());
     // Add default routes
     $this->router->addDefaultRoutes();
     // do this so setting headers does not throw exceptions
     $this->response->headersSentThrowsException = false;
     $this->redirector->setExit(false)->setActionController($this->controller);
     $this->_server = $_SERVER;
 }
Exemple #10
0
 /**
  * Prepare data for autocompletion
  *
  * @param  mixed   $data
  * @param  boolean $keepLayouts
  * @return string
  */
 public function prepareAutoCompletion($data, $keepLayouts = false)
 {
     if (!$data instanceof DojoData) {
         $items = array();
         foreach ($data as $key => $value) {
             $items[] = array('label' => $value, 'name' => $value);
         }
         $data = new DojoData('name', $items);
     }
     if (!$keepLayouts) {
         HelperBroker::getStaticHelper('viewRenderer')->setNoRender(true);
         $layout = Layout::getMvcInstance();
         if ($layout instanceof Layout) {
             $layout->disableLayout();
         }
     }
     $response = FrontController::getInstance()->getResponse();
     $response->setHeader('Content-Type', 'application/json');
     return $data->toJson();
 }
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     \Zend\Layout\Layout::resetMvcInstance();
     HelperBroker::resetHelpers();
     $this->front = Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->front->addModuleDirectory(__DIR__ . '/../../_files/modules');
     $this->layout = Layout\Layout::startMvc();
     $this->helper = new Helper\ContextSwitch();
     HelperBroker::addHelper($this->helper);
     $this->request = new \Zend\Controller\Request\Http();
     $this->response = new \Zend\Controller\Response\Cli();
     $this->front->setRequest($this->request)->setResponse($this->response)->addControllerDirectory(__DIR__);
     $this->view = new \Zend\View\View();
     $this->viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
     $this->viewRenderer->setView($this->view);
     $this->controller = new ContextSwitchTestController($this->request, $this->response, array());
     $this->controller->setupContexts();
     $this->helper->setActionController($this->controller);
 }
Exemple #12
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 public function setUp()
 {
     if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
         unset($_SERVER['HTTP_X_REQUESTED_WITH']);
     }
     \Zend\Layout\Layout::resetMvcInstance();
     HelperBroker::resetHelpers();
     HelperBroker::addPrefix('Zend\\Controller\\Action\\Helper');
     $this->front = \Zend\Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->front->addModuleDirectory(__DIR__ . '/../../_files/modules');
     $this->layout = Layout\Layout::startMvc();
     $this->helper = new \Zend\Controller\Action\Helper\AjaxContext();
     $this->request = new \Zend\Controller\Request\Http();
     $this->response = new \Zend\Controller\Response\Cli();
     $this->front->setRequest($this->request)->setResponse($this->response);
     $this->view = new \Zend\View\View();
     $this->view->addHelperPath(__DIR__ . '/../../../../../library/Zend/View/Helper/');
     $this->viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
     $this->viewRenderer->setView($this->view);
     $this->controller = new AjaxContextTestController($this->request, $this->response, array());
     $this->helper->setActionController($this->controller);
 }
Exemple #13
0
 /**
  * Gets content panel for the Debugbar
  *
  * @return string
  */
 public function getPanel()
 {
     $this->_request = FrontController::getInstance()->getRequest();
     $viewRenderer = \Zend\Controller\Action\HelperBroker::getStaticHelper('viewRenderer');
     if ($viewRenderer->view && method_exists($viewRenderer->view, 'getVars')) {
         $viewVars = $this->_cleanData($viewRenderer->view->getVars());
     } else {
         $viewVars = "No 'getVars()' method in view class";
     }
     $vars = '<div style="width:50%;float:left;">';
     $vars .= '<h4>View variables</h4>' . '<div id="ZFDebug_vars" style="margin-left:-22px">' . $viewVars . '</div>' . '<h4>Request parameters</h4>' . '<div id="ZFDebug_requests" style="margin-left:-22px">' . $this->_cleanData($this->_request->getParams()) . '</div>';
     $vars .= '</div><div style="width:45%;float:left;">';
     if ($this->_request->isPost()) {
         $vars .= '<h4>Post variables</h4>' . '<div id="ZFDebug_post" style="margin-left:-22px">' . $this->_cleanData($this->_request->getPost()) . '</div>';
     }
     $registry = \Zend\Registry::getInstance();
     $vars .= '<h4>Zend Registry</h4>';
     $registry->ksort();
     $vars .= '<div id="ZFDebug_registry" style="margin-left:-22px">' . $this->_cleanData($registry) . '</div>';
     $cookies = $this->_request->getCookie();
     $vars .= '<h4>Cookies</h4>' . '<div id="ZFDebug_cookie" style="margin-left:-22px">' . $this->_cleanData($cookies) . '</div>';
     $vars .= '</div><div style="clear:both">&nbsp;</div>';
     return $vars;
 }
 protected function _isXhtml()
 {
     $view = HelperBroker::getStaticHelper('viewRenderer')->view;
     $doctype = $view->doctype();
     return $doctype->isXhtml();
 }
Exemple #15
0
 /**
  * Future ViewRenderer State issues should be included in this test.
  *
  * @issue ZF-2846
  */
 public function testActionReturnsViewRendererToOriginalState()
 {
     /* Setup the VR as if we were inside an action controller */
     $viewRenderer = new \Zend\Controller\Action\Helper\ViewRenderer();
     $viewRenderer->init();
     HelperBroker::addHelper($viewRenderer);
     // make sure noRender is false
     $this->assertFalse($viewRenderer->getNoRender());
     $value = $this->helper->direct('bar', 'action-foo');
     $viewRendererPostAction = HelperBroker::getStaticHelper('viewRenderer');
     // ViewRenderer noRender should still be false
     $this->assertFalse($viewRendererPostAction->getNoRender());
     $this->assertSame($viewRenderer, $viewRendererPostAction);
 }
Exemple #16
0
 /**
  * Retrieve view object
  *
  * If none registered, attempts to pull from ViewRenderer.
  *
  * @return \Zend\View\ViewEngine|null
  */
 public function getView()
 {
     if (null === $this->_view) {
         $viewRenderer = ActionHelperBroker::getStaticHelper('viewRenderer');
         $this->setView($viewRenderer->view);
     }
     return $this->_view;
 }
 /**
  * Reset MVC state
  *
  * Creates new request/response objects, resets the front controller
  * instance, and resets the action helper broker.
  *
  * @todo   Need to update Zend_Layout to add a resetInstance() method
  * @return void
  */
 public function reset()
 {
     $_SESSION = array();
     $_GET = array();
     $_POST = array();
     $_COOKIE = array();
     $this->resetRequest();
     $this->resetResponse();
     \Zend\Layout\Layout::resetMvcInstance();
     HelperBroker::resetHelpers();
     $this->frontController->resetInstance();
     //\Zend\Session\Manager::$_unitTestEnabled = true;
 }
 /**
  * Encode data to JSON
  *
  * @param  mixed $data
  * @param  bool  $keepLayouts
  * @throws \Zend\Controller\Action\Exception
  * @return string
  */
 public function encodeJson($data, $keepLayouts = false)
 {
     if ($this->validateData($data)) {
         return HelperBroker::getStaticHelper('Json')->encodeJson($data, $keepLayouts);
     }
     throw new \Zend\Controller\Action\Exception('Invalid data passed for autocompletion');
 }
Exemple #19
0
 /**
  * Dispatch the requested action
  *
  * @param string $action Method name of action
  * @return void
  */
 public function dispatch($action)
 {
     // Notify helpers of action preDispatch state
     $this->_helper->notifyPreDispatch();
     $this->preDispatch();
     if ($this->getRequest()->isDispatched()) {
         if (null === $this->_classMethods) {
             $this->_classMethods = get_class_methods($this);
         }
         // preDispatch() didn't change the action, so we can continue
         if ($this->getInvokeArg('useCaseSensitiveActions') || in_array($action, $this->_classMethods)) {
             if ($this->getInvokeArg('useCaseSensitiveActions')) {
                 trigger_error('Using case sensitive actions without word separators is deprecated; please do not rely on this "feature"');
             }
             $this->{$action}();
         } else {
             $this->__call($action, array());
         }
         $this->postDispatch();
     }
     // whats actually important here is that this action controller is
     // shutting down, regardless of dispatching; notify the helpers of this
     // state
     $this->_helper->notifyPostDispatch();
 }
Exemple #20
0
 /**
  * Retrieves the view instance.  If none registered, attempts to pull f
  * rom ViewRenderer.
  *
  * @return \Zend\View\ViewEngine|null
  */
 public function getView()
 {
     if ($this->_view === null) {
         $viewRenderer = \Zend\Controller\Action\HelperBroker::getStaticHelper('viewRenderer');
         if ($viewRenderer->view === null) {
             $viewRenderer->initView();
         }
         $this->_view = $viewRenderer->view;
     }
     return $this->_view;
 }
Exemple #21
0
 /**
  * Retrieve ViewRenderer
  *
  * @return \Zend\Controller\Action\Helper\ViewRenderer Provides a fluent interface
  */
 protected function _getViewRenderer()
 {
     if (null === $this->_viewRenderer) {
         $this->_viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
     }
     return $this->_viewRenderer;
 }
Exemple #22
0
 /**
  * Retrieve rendered contents of a controller action
  *
  * If the action results in a forward or redirect, returns empty string.
  *
  * @param  string $action
  * @param  string $controller
  * @param  string $module Defaults to default module
  * @param  array $params
  * @return string
  */
 public function direct($action = null, $controller = null, $module = null, array $params = array())
 {
     if ($action == null || $controller == null) {
         throw new \InvalidArgumentException('Action: missing argument. $action and $controller are required in action($action, $controller, $module = null, array $params = array())');
     }
     $this->resetObjects();
     if (null === $module) {
         $module = $this->defaultModule;
     }
     // clone the view object to prevent over-writing of view variables
     $viewRendererObj = HelperBroker::getStaticHelper('viewRenderer');
     HelperBroker::addHelper(clone $viewRendererObj);
     $this->request->setParams($params)->setModuleName($module)->setControllerName($controller)->setActionName($action)->setDispatched(true);
     $this->dispatcher->dispatch($this->request, $this->response);
     // reset the viewRenderer object to it's original state
     HelperBroker::addHelper($viewRendererObj);
     if (!$this->request->isDispatched() || $this->response->isRedirect()) {
         // forwards and redirects render nothing
         return '';
     }
     $return = $this->response->getBody();
     $this->resetObjects();
     return $return;
 }
Exemple #23
0
 public function testGetsViewFromViewRenderer()
 {
     $viewRenderer = HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->setView(new View\View());
     $this->assertType('Zend\\View\\ViewEngine', $this->_paginator->getView());
 }
Exemple #24
0
 protected function _isXhtml()
 {
     if ($view = \Zend\Controller\Action\HelperBroker::getStaticHelper('viewRenderer')->view) {
         $doctype = $view->doctype();
         return $doctype->isXhtml();
     }
     return false;
 }
Exemple #25
0
 public function testGetViewRetrievesFromViewRendererByDefault()
 {
     $viewRenderer = ActionHelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->initView();
     $view = $viewRenderer->view;
     $test = $this->form->getView();
     $this->assertSame($view, $test);
 }
Exemple #26
0
 public function testRenderUsingViewRenderer()
 {
     HelperBroker::addHelper(new Helper\ViewRenderer());
     $request = new Request\Http();
     $request->setControllerName('view')->setActionName('script');
     $response = new Response\Cli();
     Controller\Front::getInstance()->setControllerDirectory(__DIR__ . DIRECTORY_SEPARATOR . '_files');
     $controller = new \ViewController($request, $response);
     $controller->scriptAction();
     $this->assertContains('Inside custom/renderScript.php', $response->getBody());
 }
Exemple #27
0
 /**
  * Dispatch an HTTP request to a controller/action.
  *
  * @param \Zend\Controller\Request\AbstractRequest|null $request
  * @param \Zend\Controller\Response\AbstractResponse|null $response
  * @return void|\Zend\Controller\Response\AbstractResponse Returns response object if returnResponse() is true
  */
 public function dispatch(Request\AbstractRequest $request = null, Response\AbstractResponse $response = null)
 {
     if (!$this->getParam('noErrorHandler') && !$this->_plugins->hasPlugin('\\Zend\\Controller\\Plugin\\ErrorHandler')) {
         // Register with stack index of 100
         $this->_plugins->registerPlugin(new Plugin\ErrorHandler(), 100);
     }
     if (!$this->getParam('noViewRenderer') && !Action\HelperBroker::hasHelper('viewRenderer')) {
         Action\HelperBroker::getStack()->offsetSet(-80, new Action\Helper\ViewRenderer());
     }
     /**
      * Instantiate default request object (HTTP version) if none provided
      */
     if (null !== $request) {
         $this->setRequest($request);
     } elseif (null === $request && null === ($request = $this->getRequest())) {
         $request = new Request\Http();
         $this->setRequest($request);
     }
     /**
      * Set base URL of request object, if available
      */
     if (is_callable(array($this->_request, 'setBaseUrl'))) {
         if (null !== $this->_baseUrl) {
             $this->_request->setBaseUrl($this->_baseUrl);
         }
     }
     /**
      * Instantiate default response object (HTTP version) if none provided
      */
     if (null !== $response) {
         $this->setResponse($response);
     } elseif (null === $this->_response && null === ($this->_response = $this->getResponse())) {
         $response = new Response\Http();
         $this->setResponse($response);
     }
     /**
      * Register request and response objects with plugin broker
      */
     $this->_plugins->setRequest($this->_request)->setResponse($this->_response);
     /**
      * Initialize router
      */
     $router = $this->getRouter();
     $router->setParams($this->getParams());
     /**
      * Initialize dispatcher
      */
     $dispatcher = $this->getDispatcher();
     $dispatcher->setParams($this->getParams())->setResponse($this->_response);
     // Begin dispatch
     try {
         /**
          * Route request to controller/action, if a router is provided
          */
         /**
          * Notify plugins of router startup
          */
         $this->_plugins->routeStartup($this->_request);
         try {
             $router->route($this->_request);
         } catch (\Exception $e) {
             if ($this->throwExceptions()) {
                 throw $e;
             }
             $this->_response->setException($e);
         }
         /**
          * Notify plugins of router completion
          */
         $this->_plugins->routeShutdown($this->_request);
         /**
          * Notify plugins of dispatch loop startup
          */
         $this->_plugins->dispatchLoopStartup($this->_request);
         /**
          *  Attempt to dispatch the controller/action. If the $this->_request
          *  indicates that it needs to be dispatched, move to the next
          *  action in the request.
          */
         do {
             $this->_request->setDispatched(true);
             /**
              * Notify plugins of dispatch startup
              */
             $this->_plugins->preDispatch($this->_request);
             /**
              * Skip requested action if preDispatch() has reset it
              */
             if (!$this->_request->isDispatched()) {
                 continue;
             }
             /**
              * Dispatch request
              */
             try {
                 $dispatcher->dispatch($this->_request, $this->_response);
             } catch (\Exception $e) {
                 if ($this->throwExceptions()) {
                     throw $e;
                 }
                 $this->_response->setException($e);
             }
             /**
              * Notify plugins of dispatch completion
              */
             $this->_plugins->postDispatch($this->_request);
         } while (!$this->_request->isDispatched());
     } catch (\Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     /**
      * Notify plugins of dispatch loop completion
      */
     try {
         $this->_plugins->dispatchLoopShutdown();
     } catch (\Exception $e) {
         if ($this->throwExceptions()) {
             throw $e;
         }
         $this->_response->setException($e);
     }
     if ($this->returnResponse()) {
         return $this->_response;
     }
     $this->_response->sendResponse();
 }
Exemple #28
0
 public function testResettingMvcInstanceUnregistersHelperAndPlugin()
 {
     $this->testGetMvcInstanceReturnsLayoutInstanceWhenStartMvcHasBeenCalled();
     Layout\Layout::resetMvcInstance();
     $front = Controller\Front::getInstance();
     $this->assertFalse($front->hasPlugin('Zend_Layout_Controller_Plugin_Layout'), 'Plugin not unregistered');
     $this->assertFalse(HelperBroker::hasHelper('Layout'), 'Helper not unregistered');
 }
Exemple #29
0
 /**
  * Tears down the fixture, for example, close a network connection.
  * This method is called after a test is executed.
  *
  * @access protected
  */
 protected function tearDown()
 {
     HelperBroker::resetHelpers();
 }
Exemple #30
0
 public function testViewRendererHelperNotRegisteredIfNoViewRendererSet()
 {
     $this->assertFalse(HelperBroker::hasHelper('viewRenderer'));
     $this->_controller->setParam('noViewRenderer', true);
     $request = new Request\Http('http://example.com/index/index');
     $this->_controller->setResponse(new Response\Cli());
     $response = $this->_controller->dispatch($request);
     $this->assertFalse(HelperBroker::hasHelper('viewRenderer'));
 }