protected function _getView($viewVars = [])
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $builder = $Controller->viewBuilder();
     $builder->className('JsonApi\\View\\JsonApiView');
     if ($viewVars) {
         $Controller->set($viewVars);
     }
     return $Controller->createView();
 }
Example #2
1
 /**
  * Test render with a View file specified.
  *
  * @return void
  */
 public function testRenderWithView()
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $Controller->name = 'Posts';
     $data = ['User' => ['username' => 'fake'], 'Item' => [['name' => 'item1'], ['name' => 'item2']]];
     $Controller->set('user', $data);
     $Controller->viewClass = 'Json';
     $View = $Controller->createView();
     $View->viewPath = $Controller->name;
     $output = $View->render('index');
     $expected = json_encode(['user' => 'fake', 'list' => ['item1', 'item2'], 'paging' => null]);
     $this->assertSame($expected, $output);
     $this->assertSame('application/json', $Response->type());
 }
Example #3
1
 /**
  * testRenderWithView method
  *
  * @return void
  */
 public function testRenderWithView()
 {
     $Request = new Request();
     $Response = new Response();
     $Controller = new Controller($Request, $Response);
     $Controller->name = 'Posts';
     $Controller->viewPath = 'Posts';
     $data = array(array('User' => array('username' => 'user1')), array('User' => array('username' => 'user2')));
     $Controller->set('users', $data);
     $Controller->viewClass = 'Xml';
     $View = $Controller->createView();
     $output = $View->render('index');
     $expected = array('users' => array('user' => array('user1', 'user2')));
     $expected = Xml::build($expected)->asXML();
     $this->assertSame($expected, $output);
     $this->assertSame('application/xml', $Response->type());
     $this->assertInstanceOf('Cake\\View\\HelperRegistry', $View->helpers());
 }
 /**
  * A safer way to render error messages, replaces all helpers, with basics
  * and doesn't call component methods.
  *
  * @param string $template The template to render.
  * @return \Cake\Network\Response A response object that can be sent.
  */
 protected function _outputMessageSafe($template)
 {
     $helpers = ['Form', 'Html'];
     $this->controller->helpers = $helpers;
     $builder = $this->controller->viewBuilder();
     $builder->helpers($helpers, false)->layoutPath('')->templatePath('Error');
     $view = $this->controller->createView();
     $this->controller->response->body($view->render($template, 'error'));
     $this->controller->response->type('html');
     return $this->controller->response;
 }
 /**
  * A safer way to render error messages, replaces all helpers, with basics
  * and doesn't call component methods.
  *
  * @param string $template The template to render
  * @return \Cake\Network\Response A response object that can be sent.
  */
 protected function _outputMessageSafe($template)
 {
     $this->controller->layoutPath = null;
     $this->controller->subDir = null;
     $this->controller->viewPath = 'Error';
     $this->controller->layout = 'error';
     $this->controller->helpers = array('Form', 'Html', 'Session');
     $view = $this->controller->createView();
     $this->controller->response->body($view->render($template, 'error'));
     $this->controller->response->type('html');
     return $this->controller->response;
 }
    /**
     * testExportVar method
     *
     * @return void
     */
    public function testExportVar()
    {
        $Controller = new Controller();
        $Controller->helpers = ['Html', 'Form'];
        $View = $Controller->createView();
        $View->int = 2;
        $View->float = 1.333;
        $result = Debugger::exportVar($View);
        $expected = <<<TEXT
object(Cake\\View\\View) {
\tBlocks => object(Cake\\View\\ViewBlock) {}
\tplugin => null
\tname => ''
\tpassedArgs => []
\thelpers => [
\t\t(int) 0 => 'Html',
\t\t(int) 1 => 'Form'
\t]
\tviewPath => ''
\tview => null
\tlayout => 'default'
\tlayoutPath => null
\tautoLayout => true
\tsubDir => null
\ttheme => null
\thasRendered => false
\tuuids => []
\trequest => object(Cake\\Network\\Request) {}
\tresponse => object(Cake\\Network\\Response) {}
\telementCache => 'default'
\tviewVars => []
\tHtml => object(Cake\\View\\Helper\\HtmlHelper) {}
\tForm => object(Cake\\View\\Helper\\FormHelper) {}
\tint => (int) 2
\tfloat => (float) 1.333
\t[protected] _helpers => object(Cake\\View\\HelperRegistry) {}
\t[protected] _ext => '.ctp'
\t[protected] _passedVars => [
\t\t(int) 0 => 'viewVars',
\t\t(int) 1 => 'autoLayout',
\t\t(int) 2 => 'helpers',
\t\t(int) 3 => 'view',
\t\t(int) 4 => 'layout',
\t\t(int) 5 => 'name',
\t\t(int) 6 => 'theme',
\t\t(int) 7 => 'layoutPath',
\t\t(int) 8 => 'viewPath',
\t\t(int) 9 => 'plugin',
\t\t(int) 10 => 'passedArgs'
\t]
\t[protected] _paths => []
\t[protected] _pathsForPlugin => []
\t[protected] _parents => []
\t[protected] _current => null
\t[protected] _currentType => ''
\t[protected] _stack => []
\t[protected] _eventManager => object(Cake\\Event\\EventManager) {}
\t[protected] _eventClass => '\\Cake\\Event\\Event'
}
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = [1 => 'Index one', 5 => 'Index five'];
        $result = Debugger::exportVar($data);
        $expected = <<<TEXT
[
\t(int) 1 => 'Index one',
\t(int) 5 => 'Index five'
]
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = ['key' => ['value']];
        $result = Debugger::exportVar($data, 1);
        $expected = <<<TEXT
[
\t'key' => [
\t\t[maximum depth reached]
\t]
]
TEXT;
        $this->assertTextEquals($expected, $result);
        $data = false;
        $result = Debugger::exportVar($data);
        $expected = <<<TEXT
false
TEXT;
        $this->assertTextEquals($expected, $result);
        $file = fopen('php://output', 'w');
        fclose($file);
        $result = Debugger::exportVar($file);
        $this->assertTextEquals('unknown', $result);
    }
Example #7
-1
 protected function _render($name, $view, $layout, $viewVars)
 {
     $request = new Request();
     $response = new Response();
     $controller = new Controller($request, $response);
     $controller->name = $name;
     $controller->layout = $layout;
     $controller->viewPath = $name;
     $controller->viewClass = 'Gourmet\\Liquid\\View\\View';
     $controller->set($viewVars);
     return $controller->createView()->render($view);
 }