response.test.php 2.11 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?php

class ResponseTest extends PHPUnit_Framework_TestCase {

	/**
	 * Test the Response::make method.
	 *
	 * @group laravel
	 */
	public function testMakeMethodProperlySetsContent()
	{
		$response = Response::make('foo', 201, array('bar' => 'baz'));

		$this->assertEquals('foo', $response->content);
15 16 17
		$this->assertEquals(201, $response->status());
		$this->assertArrayHasKey('bar', $response->headers()->all());
		$this->assertEquals('baz', $response->headers()->get('bar'));
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
	}

	/**
	 * Test the Response::view method.
	 *
	 * @group laravel
	 */
	public function testViewMethodSetsContentToView()
	{
		$response = Response::view('home.index', array('name' => 'Taylor'));

		$this->assertEquals('home.index', $response->content->view);
		$this->assertEquals('Taylor', $response->content->data['name']);
	}

	/**
	 * Test the Response::error method.
	 *
	 * @group laravel
	 */
	public function testErrorMethodSetsContentToErrorView()
	{
		$response = Response::error('404', array('name' => 'Taylor'));

42
		$this->assertEquals(404, $response->status());
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
		$this->assertEquals('error.404', $response->content->view);
		$this->assertEquals('Taylor', $response->content->data['name']);
	}

	/**
	 * Test the Response::prepare method.
	 *
	 * @group laravel
	 */
	public function testPrepareMethodCreatesAResponseInstanceFromGivenValue()
	{
		$response = Response::prepare('Taylor');

		$this->assertInstanceOf('Laravel\\Response', $response);
		$this->assertEquals('Taylor', $response->content);

		$response = Response::prepare(new Response('Taylor'));

		$this->assertInstanceOf('Laravel\\Response', $response);
		$this->assertEquals('Taylor', $response->content);
	}

	/**
	 * Test the Response::header method.
	 *
	 * @group laravel
	 */
	public function testHeaderMethodSetsValueInHeaderArray()
	{
		$response = Response::make('')->header('foo', 'bar');

74
		$this->assertEquals('bar', $response->headers()->get('foo'));
75 76 77 78 79 80 81 82 83 84 85
	}

	/**
	 * Test the Response::status method.
	 *
	 * @group laravel
	 */
	public function testStatusMethodSetsStatusCode()
	{
		$response = Response::make('')->status(404);

86
		$this->assertEquals(404, $response->status());
87 88 89
	}

}