Пример #1
0
 /**
  * Sets/Gets the content type. If `'type'` is null, the method will attempt to determine the
  * type from the params, then from the environment setting
  *
  * @param string $type a full content type i.e. `'application/json'` or simple name `'json'`
  * @return string A simple content type name, i.e. `'html'`, `'xml'`, `'json'`, etc., depending
  *         on the content type of the request.
  */
 public function type($type = null)
 {
     if ($type === null && $this->_type === null) {
         $type = 'html';
     }
     return parent::type($type);
 }
Пример #2
0
 /**
  * This tests that setting custom paths and disabling layout
  * via `\lithium\net\http\Media::type()` is handled properly
  * by the default `\lithium\template\View` class and `File`
  * rendered adapter.
  */
 public function testMediaTypeViewRender()
 {
     Media::type('view-integration-test', 'lithium/viewtest', array('view' => 'lithium\\template\\View', 'paths' => array('layout' => false, 'template' => array('{:library}/tests/mocks/template/view/adapters/{:template}.{:type}.php', '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'))));
     // testing no layout with a custom type template
     $response = new Response();
     $response->type('view-integration-test');
     Media::render($response, array(), array('layout' => true, 'library' => 'lithium', 'template' => 'testTypeFile'));
     $this->assertEqual('This is a type test.', $response->body());
     // testing the template falls back to the html template
     $response = new Response();
     $response->type('view-integration-test');
     Media::render($response, array(), array('layout' => true, 'library' => 'lithium', 'template' => 'testFile'));
     $this->assertEqual('This is a test.', $response->body());
     // testing with a layout
     Media::type('view-integration-test', 'lithium/viewtest', array('view' => 'lithium\\template\\View', 'paths' => array('layout' => '{:library}/tests/mocks/template/view/adapters/testLayoutFile.html.php', 'template' => array('{:library}/tests/mocks/template/view/adapters/{:template}.{:type}.php', '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'))));
     $response = new Response();
     $response->type('view-integration-test');
     Media::render($response, array(), array('layout' => true, 'library' => 'lithium', 'template' => 'testTypeFile'));
     $this->assertEqual("Layout top.\nThis is a type test.Layout bottom.", $response->body());
 }
Пример #3
0
 public function testTypePriority()
 {
     /* Decide what to do with this */
     return "Is this test correct?";
     $response = new Response(array('message' => "Content-type: text/x-test-a\r\n\r\nfoo", 'type' => 'text/x-test-b', 'headers' => array('Content-Type' => 'text/x-test-c')));
     $this->assertEqual('text/x-test-c', $response->type());
     $response = new Response(array('message' => "Content-type: text/x-test-a\r\n\r\nfoo", 'type' => 'text/x-test-b'));
     $this->assertEqual('text/x-test-b', $response->type());
 }