/** * @group ZF-3145 */ public function testResetInstanceShouldResetHelperBroker() { HelperBroker\HelperBroker::addHelper(new \Zend\Controller\Action\Helper\ViewRenderer()); HelperBroker\HelperBroker::addHelper(new \Zend\Controller\Action\Helper\Url()); $helpers = HelperBroker\HelperBroker::getExistingHelpers(); $this->assertTrue(is_array($helpers)); $this->assertFalse(empty($helpers)); $this->_controller->resetInstance(); $helpers = HelperBroker\HelperBroker::getExistingHelpers(); $this->assertTrue(is_array($helpers)); $this->assertTrue(empty($helpers)); }
/** * 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\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() { \Zend\Layout\Layout::resetMvcInstance(); HelperBroker\HelperBroker::resetHelpers(); $this->front = Controller\Front::getInstance(); $this->front->resetInstance(); $this->front->addModuleDirectory(dirname(__FILE__) . '/../../_files/modules'); $this->layout = Layout\Layout::startMvc(); $this->helper = new Helper\ContextSwitch(); HelperBroker\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(dirname(__FILE__)); $this->view = new \Zend\View\View(); $this->viewRenderer = HelperBroker\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); }
/** * 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\HelperBroker::getStaticHelper('viewRenderer'); HelperBroker\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\HelperBroker::addHelper($viewRendererObj); if (!$this->request->isDispatched() || $this->response->isRedirect()) { // forwards and redirects render nothing return ''; } $return = $this->response->getBody(); $this->resetObjects(); return $return; }
public function testGetExistingHelpers() { HelperBroker\HelperBroker::addHelper(new Helper\Redirector()); // already included in setup, techinically we shouldnt be able to do this, but until 2.0 - its allowed HelperBroker\HelperBroker::addHelper(new Helper\ViewRenderer()); // @todo in future this should throw an exception $helpers = HelperBroker\HelperBroker::getExistingHelpers(); $this->assertTrue(is_array($helpers)); $this->assertEquals(2, count($helpers)); $this->assertContains('ViewRenderer', array_keys($helpers)); $this->assertContains('Redirector', array_keys($helpers)); }
/** * Sets up the fixture, for example, open a network connection. * This method is called before a test is executed. * * @access protected */ protected function setUp() { $this->basePath = realpath(dirname(__FILE__) . str_repeat(DIRECTORY_SEPARATOR . '..', 2)); $this->request = new \Zend\Controller\Request\HTTP(); $this->response = new \Zend\Controller\Response\HTTP(); $this->front = \Zend\Controller\Front::getInstance(); $this->front->resetInstance(); $this->front->addModuleDirectory($this->basePath . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'modules')->setRequest($this->request)->setResponse($this->response); $this->helper = new Helper\ViewRenderer(); HelperBroker\HelperBroker::addHelper($this->helper); }
/** * 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\HelperBroker::addHelper($viewRenderer); // make sure noRender is false $this->assertFalse($viewRenderer->getNoRender()); $value = $this->helper->direct('bar', 'action-foo'); $viewRendererPostAction = HelperBroker\HelperBroker::getStaticHelper('viewRenderer'); // ViewRenderer noRender should still be false $this->assertFalse($viewRendererPostAction->getNoRender()); $this->assertSame($viewRenderer, $viewRendererPostAction); }
public function testRenderUsingViewRenderer() { HelperBroker\HelperBroker::addHelper(new Helper\ViewRenderer()); $request = new Request\HTTP(); $request->setControllerName('view')->setActionName('script'); $response = new Response\Cli(); Controller\Front::getInstance()->setControllerDirectory(dirname(__FILE__) . DIRECTORY_SEPARATOR . '_files'); $controller = new \ViewController($request, $response); $controller->scriptAction(); $this->assertContains('Inside custom/renderScript.php', $response->getBody()); }