mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-31 17:16:18 +00:00
adding test for viewClass mapping
This commit is contained in:
parent
21431cba64
commit
7ea1a59035
1 changed files with 40 additions and 1 deletions
|
@ -21,6 +21,7 @@ App::uses('RequestHandlerComponent', 'Controller/Component');
|
||||||
App::uses('CakeRequest', 'Network');
|
App::uses('CakeRequest', 'Network');
|
||||||
App::uses('CakeResponse', 'Network');
|
App::uses('CakeResponse', 'Network');
|
||||||
App::uses('Router', 'Routing');
|
App::uses('Router', 'Routing');
|
||||||
|
App::uses('JsonView', 'View');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RequestHandlerTestController class
|
* RequestHandlerTestController class
|
||||||
|
@ -70,6 +71,15 @@ class RequestHandlerTestController extends Controller {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class CustomJsonView extends JsonView {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test method for viewClassMap and overriding _serialize()
|
||||||
|
*/
|
||||||
|
protected function _serialize($serialize) {
|
||||||
|
return json_encode(array('return' => 'ok'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* RequestHandlerComponentTest class
|
* RequestHandlerComponentTest class
|
||||||
|
@ -137,12 +147,14 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
*/
|
*/
|
||||||
public function testConstructorSettings() {
|
public function testConstructorSettings() {
|
||||||
$settings = array(
|
$settings = array(
|
||||||
'ajaxLayout' => 'test_ajax'
|
'ajaxLayout' => 'test_ajax',
|
||||||
|
'viewClassMap' => array('json' => 'MyPlugin.MyJson')
|
||||||
);
|
);
|
||||||
$Collection = new ComponentCollection();
|
$Collection = new ComponentCollection();
|
||||||
$Collection->init($this->Controller);
|
$Collection->init($this->Controller);
|
||||||
$RequestHandler = new RequestHandlerComponent($Collection, $settings);
|
$RequestHandler = new RequestHandlerComponent($Collection, $settings);
|
||||||
$this->assertEquals('test_ajax', $RequestHandler->ajaxLayout);
|
$this->assertEquals('test_ajax', $RequestHandler->ajaxLayout);
|
||||||
|
$this->assertEquals(array('json' => 'MyPlugin.MyJson'), $RequestHandler->settings['viewClassMap']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -264,6 +276,33 @@ class RequestHandlerComponentTest extends CakeTestCase {
|
||||||
call_user_func_array(array('Router', 'parseExtensions'), $extensions);
|
call_user_func_array(array('Router', 'parseExtensions'), $extensions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* testViewClassMap method
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testViewClassMap() {
|
||||||
|
$settings = array('viewClassMap' => array('json' => 'CustomJson'));
|
||||||
|
$this->RequestHandler->initialize($this->Controller, $settings);
|
||||||
|
$result = $this->RequestHandler->viewClassMap();
|
||||||
|
$expected = array(
|
||||||
|
'json' => 'CustomJson',
|
||||||
|
'xml' => 'Xml'
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$result = $this->RequestHandler->viewClassMap('xls', 'Excel.Excel');
|
||||||
|
$expected = array(
|
||||||
|
'json' => 'CustomJson',
|
||||||
|
'xml' => 'Xml',
|
||||||
|
'xls' => 'Excel.Excel'
|
||||||
|
);
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
|
||||||
|
$this->RequestHandler->renderAs($this->Controller, 'json');
|
||||||
|
$this->assertEquals('CustomJson', $this->Controller->viewClass);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* testDisabling method
|
* testDisabling method
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Reference in a new issue