Пример #1
0
    public function setUp()
    {
        date_default_timezone_set('America/Los_Angeles');

        // Reset front controller to reset registered plugins and
        // registered request/response objects
        \Zend\Controller\Front::getInstance()->resetInstance();

        $this->_request = new FirePhpHeader();
        $this->_response = new MockHttpResponse();

        $channel = Channel\HttpHeaders::getInstance();
        $channel->setRequest($this->_request);
        $channel->setResponse($this->_response);

        $this->_writer = new FirebugWriter();

        // Explicitly enable writer as it is disabled by default
        // when running from the command line.
        $this->_writer->setEnabled(true);

        $this->_logger = new Logger($this->_writer);

        FirePhp::getInstance()->setOption('includeLineNumbers', false);
    }
Пример #2
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()
 {
     $this->front = \Zend\Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->request = new Request\Http();
     $this->front->setRequest($this->request);
 }
Пример #3
0
 public function setUp()
 {
     $this->controller = \Zend\Controller\Front::getInstance();
     $this->controller->resetInstance();
     $this->controller->setParam('noViewRenderer', true)
                      ->setParam('noErrorHandler', true);
 }
Пример #4
0
    protected function setUp()
    {
        if (!extension_loaded('pdo_sqlite')) {
           $this->markTestSkipped('Pdo_Sqlite extension is not loaded');
        }

        $this->_adapter = new \Zend\Db\Adapter\Pdo\Sqlite(array(
            'dbname' => __DIR__ . '/_files/test.sqlite'
        ));

        $this->_query = $this->_adapter->select()->from('test');

        $this->_testCollection = range(1, 101);
        $this->_paginator = Paginator\Paginator::factory($this->_testCollection);

        $this->_config = new Config\Xml(__DIR__ . '/_files/config.xml');
        // get a fresh new copy of ViewRenderer in each tests
        $this->front = FrontController::getInstance();
        $this->front->resetInstance();
        $this->broker = $this->front->getHelperBroker();

        $fO = array('lifetime' => 3600, 'automatic_serialization' => true);
        $bO = array('cache_dir'=> $this->_getTmpDir());

        $this->_cache = \Zend\Cache\Cache::factory('Core', 'File', $fO, $bO);

        Paginator\Paginator::setCache($this->_cache);

        $this->_restorePaginatorDefaults();
    }
Пример #5
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 __invoke($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
        $broker = $this->front->getHelperBroker();
        $viewRenderer = $broker->load('viewRenderer');
        $viewRendererClone = clone $viewRenderer;
        $broker->register('viewRenderer', $viewRendererClone);

        $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
        $broker->register('viewRenderer', $viewRenderer);

        if (!$this->request->isDispatched()
            || $this->response->isRedirect())
        {
            // forwards and redirects render nothing
            return '';
        }

        $return = $this->response->getBody();
        $this->resetObjects();
        return $return;
    }
Пример #6
0
 public function init()
 {
     $this->_front = \Zend\Controller\Front::getInstance();
     if ($this->_front->hasPlugin('Zend\\Layout\\Controller\\Plugin\\Layout')) {
         $this->_layout = $this->_front->getPlugin('Zend\\Layout\\Controller\\Plugin\\Layout')->getLayout();
     }
 }
Пример #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()
    {
        if (isset($_SERVER['HTTP_X_REQUESTED_WITH'])) {
            unset($_SERVER['HTTP_X_REQUESTED_WITH']);
        }

        \Zend\Layout\Layout::resetMvcInstance();

        $this->front = \Zend\Controller\Front::getInstance();
        $this->front->resetInstance();
        $this->front->addModuleDirectory(__DIR__ . '/../../_files/modules');
        $this->broker = $this->front->getHelperBroker();

        $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\PhpRenderer();
        $this->viewRenderer = $this->broker->load('viewRenderer');
        $this->viewRenderer->setView($this->view);

        $this->controller = new AjaxContextTestController(
            $this->request,
            $this->response,
            array()
        );
        $this->helper->setActionController($this->controller);
    }
Пример #8
0
 protected function setUp()
 {
     $this->_originaltimezone = date_default_timezone_get();
     date_default_timezone_set('Europe/Berlin');
     if (isset($_SERVER['SERVER_NAME'])) {
         $this->_oldServer['SERVER_NAME'] = $_SERVER['SERVER_NAME'];
     }
     if (isset($_SERVER['SERVER_PORT'])) {
         $this->_oldServer['SERVER_PORT'] = $_SERVER['SERVER_PORT'];
     }
     if (isset($_SERVER['REQUEST_URI'])) {
         $this->_oldServer['REQUEST_URI'] = $_SERVER['REQUEST_URI'];
     }
     $_SERVER['SERVER_NAME'] = 'localhost';
     $_SERVER['SERVER_PORT'] = 80;
     $_SERVER['REQUEST_URI'] = '/';
     $this->_front = \Zend\Controller\Front::getInstance();
     $this->_oldRequest = $this->_front->getRequest();
     $this->_oldRouter = $this->_front->getRouter();
     $this->_front->resetInstance();
     $this->_front->setRequest(new Request\Http());
     $this->_front->getRouter()->addDefaultRoutes();
     parent::setUp();
     $this->_helper->setFormatOutput(true);
 }
Пример #9
0
    /**
     * Encode data as JSON, disable layouts, and set response header
     *
     * If $keepLayouts is true, does not disable layouts.
     *
     * @param  mixed $data
     * @param  bool $keepLayouts
     * NOTE:   if boolean, establish $keepLayouts to true|false
     *         if array, admit params for Zend_Json::encode as enableJsonExprFinder=>true|false
     *         this array can contains a 'keepLayout'=>true|false
     *         that will not be passed to Zend_Json::encode method but will be used here
     * @return string|void
     */
    public function direct($data = null, $keepLayouts = false)
    {
        if ($data == null) {
            throw new \InvalidArgumentException('JSON: missing argument. $data is required in json($data, $keepLayouts = false)');
        }
        
        $options = array();
        if (is_array($keepLayouts))
        {
            $options     = $keepLayouts;
            $keepLayouts = (array_key_exists('keepLayouts', $keepLayouts))
                            ? $keepLayouts['keepLayouts']
                            : false;
            unset($options['keepLayouts']);
        }

        $data = \Zend\Json\Json::encode($data, null, $options);
        if (!$keepLayouts) {
            $layout = LayoutManager::getMvcInstance();
            if ($layout instanceof LayoutManager) {
                $layout->disableLayout();
            }
        }

        $response = \Zend\Controller\Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json');
        return $data;
    }
Пример #10
0
    public function setUp()
    {
        $front = \Zend\Controller\Front::getInstance();
        $front->resetInstance();
        $front->setParam('noErrorHandler', true)
              ->setParam('noViewRenderer', true);

        $this->_dispatcher = $front->getDispatcher();

        $this->_dispatcher->setControllerDirectory(array(
            'default' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files',
            'mod'     => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin',
        ));

        $defaults = array(
            'controller' => 'defctrl',
            'action'     => 'defact',
            'module'     => 'default'
        );

        $this->_request = new \Zend\Controller\Request\Http();
        $front->setRequest($this->_request);

        $this->route = new Route\Module($defaults, $this->_dispatcher, $this->_request);
    }
Пример #11
0
 /**
  * Renders a template fragment within a variable scope distinct from the
  * calling View object.
  *
  * If no arguments are passed, returns the helper instance.
  *
  * If the $model is an array, it is passed to the view object's assign()
  * method.
  *
  * If the $model is an object, it first checks to see if the object
  * implements a 'toArray' method; if so, it passes the result of that
  * method to to the view object's assign() method. Otherwise, the result of
  * get_object_vars() is passed.
  *
  * @param  string $name Name of view script
  * @param  string|array $module If $model is empty, and $module is an array,
  *                              these are the variables to populate in the
  *                              view. Otherwise, the module in which the
  *                              partial resides
  * @param  array $model Variables to populate in the view
  * @return string|\Zend\View\Helper\Partial\Partial
  * @throws Exception\RuntimeException
  */
 public function __invoke($name = null, $module = null, $model = null)
 {
     if (0 == func_num_args()) {
         return $this;
     }
     $view = $this->cloneView();
     if (isset($this->partialCounter)) {
         $view->partialCounter = $this->partialCounter;
     }
     if (null !== $module && is_string($module)) {
         $moduleDir = \Zend\Controller\Front::getInstance()->getControllerDirectory($module);
         if (null === $moduleDir) {
             throw new Exception\RuntimeException('Cannot render partial; module does not exist');
         }
         $viewsDir = dirname($moduleDir) . '/views';
         $view->resolver()->addPath($viewsDir . '/scripts');
     } elseif (null == $model && null !== $module && (is_array($module) || is_object($module))) {
         $model = $module;
     }
     if (!empty($model)) {
         if (is_array($model)) {
             $view->vars()->assign($model);
         } elseif (is_object($model)) {
             if (null !== ($objectKey = $this->getObjectKey())) {
                 $view->vars()->offsetSet($objectKey, $model);
             } elseif (method_exists($model, 'toArray')) {
                 $view->vars()->assign($model->toArray());
             } else {
                 $view->vars()->assign(get_object_vars($model));
             }
         }
     }
     return $view->render($name);
 }
Пример #12
0
 public function setUp()
 {
     $this->application = new Application('testing');
     $this->bootstrap = new ZfAppBootstrap($this->application);
     $this->front = FrontController::getInstance();
     $this->front->resetInstance();
 }
Пример #13
0
    public function setUp()
    {
        $savePath = ini_get('session.save_path');
        if (strpos($savePath, ';')) {
            $savePath = explode(';', $savePath);
            $savePath = array_pop($savePath);
        }
        if (empty($savePath)) {
            $this->markTestSkipped('Cannot test FlashMessenger due to unavailable session save path');
        }

        if (headers_sent()) {
            $this->markTestSkipped('Cannot test FlashMessenger: cannot start session because headers already sent');
        }
        \Zend\Session\Manager::start();

        $this->front      = \Zend\Controller\Front::getInstance();
        $this->front->resetInstance();
        $this->front->setControllerDirectory(dirname(dirname(__DIR__)) . DIRECTORY_SEPARATOR . '_files');
        $this->front->returnResponse(true);
        $this->request    = new \Zend\Controller\Request\Http();
        $this->request->setControllerName('helper-flash-messenger');
        $this->response   = new \Zend\Controller\Response\Cli();
        $this->controller = new \HelperFlashMessengerController($this->request, $this->response, array());
        $this->helper     = new \Zend\Controller\Action\Helper\FlashMessenger($this->controller);
    }
Пример #14
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->front = Controller\Front::getInstance();
        $this->front->resetInstance();
        $this->front->addModuleDirectory(__DIR__ . '/../../_files/modules');
        $this->broker = $this->front->getHelperBroker();

        $this->layout = Layout\Layout::startMvc();

        $this->helper = new Helper\ContextSwitch();
        $this->broker->register('contextswitch', $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\PhpRenderer();
        $this->viewRenderer = $this->broker->load('viewRenderer');
        $this->viewRenderer->setView($this->view);

        $this->controller = new ContextSwitchTestController(
            $this->request,
            $this->response,
            array()
        );
        $this->controller->setHelperBroker($this->broker);
        $this->controller->setupContexts();
        $this->helper->setActionController($this->controller);
    }
Пример #15
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()
 {
     $this->front = \Zend\Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->front->setRequest(new \Zend\Controller\Request\Http());
     $this->helper = new \Zend\Controller\Action\Helper\Url();
 }
Пример #16
0
 public function setUp()
 {
     $this->application = new Application\Application('testing');
     $this->bootstrap = new Application\Bootstrap($this->application);
     $this->bootstrap->getBroker()->registerSpec('view');
     FrontController::getInstance()->resetInstance();
 }
Пример #17
0
 /**
  * Sets up the fixture, for example, open a network connection.
  * This method is called before a test is executed.
  *
  * @access protected
  */
 protected function setUp()
 {
     \Zend\Controller\Front::getInstance()->resetInstance();
     $this->request = new \Zend\Controller\Request\HttpTestCase();
     $this->plugin = new \Zend\Controller\Plugin\PutHandler();
     $this->plugin->setRequest($this->request);
 }
Пример #18
0
 public function setUp()
 {
     $this->_front = FrontController::getInstance();
     $this->_front->resetInstance();
     $this->_front->setParam('noErrorHandler', true)->setParam('noViewRenderer', true);
     $this->_dispatcher = $this->_front->getDispatcher();
     $this->_dispatcher->setControllerDirectory(array('default' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . '_files', 'mod' => __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'Controller' . DIRECTORY_SEPARATOR . '_files' . DIRECTORY_SEPARATOR . 'Admin'));
 }
Пример #19
0
 public function setUp()
 {
     $this->application = new Application('testing', array('resources' => array('frontcontroller' => array())));
     $this->bootstrap = new ZfAppBootstrap($this->application);
     $this->front = FrontController::getInstance();
     $this->front->resetInstance();
     $this->broker = $this->front->getHelperBroker();
 }
Пример #20
0
 /**
  * Test Function for replaceAction
  *
  * @return void
  */
 public function replaceAction()
 {
     $request = new \Zend\Controller\Request\Http();
     $request->setControllerName('index')->setActionName('reset')->setDispatched(false);
     $response = new \Zend\Controller\Response\Http();
     $front = \Zend\Controller\Front::getInstance();
     $front->setRequest($request)->setResponse($response);
 }
Пример #21
0
 public function _initRoutes()
 {
     $this->bootstrap('FrontController');
     $front = Front::getInstance();
     $router = new RouterRewrite();
     $router->addRoute('game-view', new Route('game/view/:game_id/:game_name', array('module' => 'default', 'controller' => 'game', 'action' => 'view')));
     $front->setRouter($router);
 }
Пример #22
0
 /**
  * Instantiates route based on passed Zend_Config structure
  */
 public static function getInstance(Config\Config $config)
 {
     $frontController = \Zend\Controller\Front::getInstance();
     $defs = $config->defaults instanceof Config\Config ? $config->defaults->toArray() : array();
     $dispatcher = $frontController->getDispatcher();
     $request = $frontController->getRequest();
     return new self($defs, $dispatcher, $request);
 }
Пример #23
0
 /**
  * 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->front = \Zend\Controller\Front::getInstance();
     $this->front->getRouter()->addDefaultRoutes();
     // $this->view = new Zend_View();
     $this->helper = new \Zend\View\Helper\Url();
     // $this->helper->setView($this->view);
 }
Пример #24
0
 /**
  * Get the ZFDebug logger
  *
  * @return Zend_Log
  */
 public function getLogger()
 {
     if (!$this->_logger) {
         $this->_logger = FrontController::getInstance()->getPlugin('\\ZFDebug\\Controller\\Plugin\\Debug')->getPlugin('Log');
         $this->_logger->getLog()->addPriority('Memory', 8);
     }
     return $this->_logger;
 }
Пример #25
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'));
 }
Пример #26
0
 protected function setUp()
 {
     $this->_front = \Zend\Controller\Front::getInstance();
     $this->_oldRequest = $this->_front->getRequest();
     $this->_oldRouter = $this->_front->getRouter();
     $this->_front->resetInstance();
     $this->_front->setRequest(new Request\HTTP());
     $this->_front->getRouter()->addDefaultRoutes();
 }
Пример #27
0
 public function setUp()
 {
     $this->front = \Zend\Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->front->setParam('noViewRenderer', true)->setParam('noErrorHandler', true)->throwExceptions(true);
     HelperBroker\HelperBroker::resetHelpers();
     $viewRenderer = HelperBroker\HelperBroker::getStaticHelper('viewRenderer');
     $viewRenderer->setActionController();
 }
Пример #28
0
 /**
  * Constructor
  *
  * Register action stack plugin
  *
  * @return void
  */
 public function __construct()
 {
     $front = \Zend\Controller\Front::getInstance();
     if (!$front->hasPlugin('Zend\\Controller\\Plugin\\ActionStack')) {
         $this->_actionStack = new \Zend\Controller\Plugin\ActionStack();
         $front->registerPlugin($this->_actionStack, 97);
     } else {
         $this->_actionStack = $front->getPlugin('Zend\\Controller\\Plugin\\ActionStack');
     }
 }
Пример #29
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->helper = new \Zend\View\Helper\Json();
 }
Пример #30
0
 public function setUp()
 {
     $this->_requestUriOld = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : null;
     $_SERVER['REQUEST_URI'] = '/foo';
     $this->front = \Zend\Controller\Front::getInstance();
     $this->front->resetInstance();
     $this->request = new \Zend\Controller\Request\Http();
     $this->request->setModuleName('foo')->setControllerName('bar')->setActionName('baz');
     $this->front->setRequest($this->request);
 }