type() public method

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
public type ( string $type = null ) : string
$type string 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.
Exemplo n.º 1
0
 /**
  * Tests that attempts to render a media type with no handler registered produces an
  * 'unhandled media type' exception, even if the type itself is a registered content type.
  *
  * @return void
  */
 public function testUnregisteredContentHandler()
 {
     $response = new Response();
     $response->type('xml');
     $this->expectException("Unhandled media type `xml`.");
     Media::render($response, array('foo' => 'bar'));
     $result = $response->body;
     $this->assertNull($result);
 }
Exemplo n.º 2
0
 public function testDefaultTypeInitialization()
 {
     $response = new Response(array('request' => new MockRequestType()));
     $this->assertEqual('foo', $response->type());
 }
Exemplo n.º 3
0
 public function testRenderWithOptionsMerging()
 {
     $base = Libraries::get(true, 'resources') . '/tmp';
     $this->skipIf(!is_writable($base), "Path `{$base}` is not writable.");
     $request = new Request();
     $request->params['controller'] = 'pages';
     $response = new Response();
     $response->type('html');
     $this->assertException("/Template not found/", function () use($response) {
         Media::render($response, null, compact('request'));
     });
     $this->_cleanUp();
 }
Exemplo n.º 4
0
 public function testRender()
 {
     $response = new Response();
     $response->type('json');
     $data = array('something');
     Media::render($response, $data);
     $expected = array('Content-type: application/json');
     $result = $response->headers();
     $this->assertEqual($expected, $result);
     $expected = json_encode($data);
     $result = $response->body();
     $this->assertEqual($expected, $result);
 }