Skip to content

Commit

Permalink
Added three new test cases for RequestHandlerComponent rel View classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
sgpinkus committed Apr 16, 2014
1 parent 39e4ab0 commit 001c41d
Showing 1 changed file with 47 additions and 1 deletion.
Expand Up @@ -337,7 +337,9 @@ public function testAutoAjaxLayout() {
$this->RequestHandler->initialize($event);
$this->RequestHandler->startup($event);
$this->assertEquals($this->Controller->viewClass, 'Cake\View\AjaxView');

$view = $this->Controller->createView();
$this->assertEquals('ajax', $view->layout);

$this->_init();
$this->Controller->request->params['_ext'] = 'js';
$this->RequestHandler->initialize($event);
Expand All @@ -347,6 +349,50 @@ public function testAutoAjaxLayout() {
unset($_SERVER['HTTP_X_REQUESTED_WITH']);
}

/**
* test custom JsonView class is loaded and correct.
*/
public function testJsonViewLoaded() {
Router::parseExtensions('json', 'xml', 'ajax');
$this->Controller->request->params['_ext'] = 'json';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
$this->RequestHandler->startup($event);
$this->assertEquals('Cake\View\JsonView', $this->Controller->viewClass);
$view = $this->Controller->createView();
$this->assertEquals('json', $view->layoutPath);
$this->assertEquals('json', $view->subDir);
}

/**
* test custom XmlView class is loaded and correct.
*/
public function testXmlViewLoaded() {
Router::parseExtensions('json', 'xml', 'ajax');
$this->Controller->request->params['_ext'] = 'xml';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
$this->RequestHandler->startup($event);
$this->assertEquals('Cake\View\XmlView', $this->Controller->viewClass);
$view = $this->Controller->createView();
$this->assertEquals('xml', $view->layoutPath);
$this->assertEquals('xml', $view->subDir);
}

/**
* test custom AjaxView class is loaded and correct.
*/
public function testAjaxViewLoaded() {
Router::parseExtensions('json', 'xml', 'ajax');
$this->Controller->request->params['_ext'] = 'ajax';
$event = new Event('Controller.startup', $this->Controller);
$this->RequestHandler->initialize($event);
$this->RequestHandler->startup($event);
$this->assertEquals('Cake\View\AjaxView', $this->Controller->viewClass);
$view = $this->Controller->createView();
$this->assertEquals('ajax', $view->layout);
}

/**
* testStartupCallback method
*
Expand Down

0 comments on commit 001c41d

Please sign in to comment.