diff --git a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php index fa8174a846b..cb9a0ed23ca 100644 --- a/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php +++ b/tests/TestCase/Controller/Component/RequestHandlerComponentTest.php @@ -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); @@ -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 *