Skip to content
This repository
Browse code

adding test for viewClass mapping

  • Loading branch information...
commit 7ea1a590354617d13f31d644e09fbddf7e667271 1 parent 21431cb
ceeram authored August 10, 2012
41  lib/Cake/Test/Case/Controller/Component/RequestHandlerComponentTest.php
@@ -21,6 +21,7 @@
21 21
 App::uses('CakeRequest', 'Network');
22 22
 App::uses('CakeResponse', 'Network');
23 23
 App::uses('Router', 'Routing');
  24
+App::uses('JsonView', 'View');
24 25
 
25 26
 /**
26 27
  * RequestHandlerTestController class
@@ -70,6 +71,15 @@ public function ajax2_layout() {
70 71
 
71 72
 }
72 73
 
  74
+class CustomJsonView extends JsonView {
  75
+
  76
+/**
  77
+ * Test method for viewClassMap and overriding _serialize()
  78
+ */
  79
+	protected function _serialize($serialize) {
  80
+		return json_encode(array('return' => 'ok'));
  81
+	}
  82
+}
73 83
 
74 84
 /**
75 85
  * RequestHandlerComponentTest class
@@ -137,12 +147,14 @@ public function tearDown() {
137 147
  */
138 148
 	public function testConstructorSettings() {
139 149
 		$settings = array(
140  
-			'ajaxLayout' => 'test_ajax'
  150
+			'ajaxLayout' => 'test_ajax',
  151
+			'viewClassMap' => array('json' => 'MyPlugin.MyJson')
141 152
 		);
142 153
 		$Collection = new ComponentCollection();
143 154
 		$Collection->init($this->Controller);
144 155
 		$RequestHandler = new RequestHandlerComponent($Collection, $settings);
145 156
 		$this->assertEquals('test_ajax', $RequestHandler->ajaxLayout);
  157
+		$this->assertEquals(array('json' => 'MyPlugin.MyJson'), $RequestHandler->settings['viewClassMap']);
146 158
 	}
147 159
 
148 160
 /**
@@ -265,6 +277,33 @@ public function testInitializeContentTypeAndExtensionMismatch() {
265 277
 	}
266 278
 
267 279
 /**
  280
+ * testViewClassMap method
  281
+ *
  282
+ * @return void
  283
+ */
  284
+	public function testViewClassMap() {
  285
+		$settings = array('viewClassMap' => array('json' => 'CustomJson'));
  286
+		$this->RequestHandler->initialize($this->Controller, $settings);
  287
+		$result = $this->RequestHandler->viewClassMap();
  288
+		$expected = array(
  289
+			'json' => 'CustomJson',
  290
+			'xml' => 'Xml'
  291
+		);
  292
+		$this->assertEquals($expected, $result);
  293
+
  294
+		$result = $this->RequestHandler->viewClassMap('xls', 'Excel.Excel');
  295
+		$expected = array(
  296
+			'json' => 'CustomJson',
  297
+			'xml' => 'Xml',
  298
+			'xls' => 'Excel.Excel'
  299
+		);
  300
+		$this->assertEquals($expected, $result);
  301
+
  302
+		$this->RequestHandler->renderAs($this->Controller, 'json');
  303
+		$this->assertEquals('CustomJson', $this->Controller->viewClass);
  304
+	}
  305
+
  306
+/**
268 307
  * testDisabling method
269 308
  *
270 309
  * @return void

0 notes on commit 7ea1a59

Please sign in to comment.
Something went wrong with that request. Please try again.