Inheritance: extends lithium\action\Controller
 public function testResponseTypeBasedOnRequestHeaderType()
 {
     $request = new MockControllerRequest(array('env' => array('Content-type' => 'json')));
     $postsController = new MockPostsController(array('request' => $request, 'classes' => array('response' => '\\lithium\\tests\\mocks\\action\\MockControllerResponse')));
     $this->assertFalse($postsController->stopped);
     $postsController->__invoke($request, array('action' => 'type'));
     $expected = array('type' => 'json', 'data' => array('data' => 'test'), 'auto' => true, 'layout' => 'default', 'template' => 'type', 'hasRendered' => true);
     $result = $postsController->access('_render');
     $this->assertEqual($expected, $result);
     $expected = 'application/json';
     $result = $postsController->response->headers('Content-type');
     $this->assertEqual($expected, $result);
     $expected = array('data' => 'test');
     $result = json_decode($postsController->response->body(), true);
     $this->assertEqual($expected, $result);
 }
Exemple #2
0
	/**
	 * Tests that requests which are dispotched with the controller route parameter specified as
	 * a fully-qualified class name are able to locate their templates correctly.
	 *
	 * @return void
	 */
	public function testDispatchingWithExplicitControllerName() {
		$request = new Request(array('url' => '/'));
		$request->params = array(
			'controller' => 'lithium\tests\mocks\action\MockPostsController',
			'action' => 'index'
		);

		$postsController = new MockPostsController(compact('request'));
		$postsController->__invoke($request, $request->params);
	}
 /**
  * Tests that the library of the controller is automatically added to the default rendering
  * options.
  */
 public function testLibraryScoping()
 {
     $request = new Request();
     $request->params['controller'] = 'lithium\\tests\\mocks\\action\\MockPostsController';
     $controller = new MockPostsController(compact('request') + array('classes' => array('media' => 'lithium\\tests\\mocks\\action\\MockMediaClass')));
     $controller->render();
     $this->assertEqual('lithium', $controller->response->options['library']);
 }