response.test.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. class ResponseTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Test the Response::make method.
  5. *
  6. * @group laravel
  7. */
  8. public function testMakeMethodProperlySetsContent()
  9. {
  10. $response = Response::make('foo', 201, array('bar' => 'baz'));
  11. $this->assertEquals('foo', $response->content);
  12. $this->assertEquals(201, $response->status());
  13. $this->assertArrayHasKey('bar', $response->headers()->all());
  14. $this->assertEquals('baz', $response->headers()->get('bar'));
  15. }
  16. /**
  17. * Test the Response::view method.
  18. *
  19. * @group laravel
  20. */
  21. public function testViewMethodSetsContentToView()
  22. {
  23. $response = Response::view('home.index', array('name' => 'Taylor'));
  24. $this->assertEquals('home.index', $response->content->view);
  25. $this->assertEquals('Taylor', $response->content->data['name']);
  26. }
  27. /**
  28. * Test the Response::error method.
  29. *
  30. * @group laravel
  31. */
  32. public function testErrorMethodSetsContentToErrorView()
  33. {
  34. $response = Response::error('404', array('name' => 'Taylor'));
  35. $this->assertEquals(404, $response->status());
  36. $this->assertEquals('error.404', $response->content->view);
  37. $this->assertEquals('Taylor', $response->content->data['name']);
  38. }
  39. /**
  40. * Test the Response::prepare method.
  41. *
  42. * @group laravel
  43. */
  44. public function testPrepareMethodCreatesAResponseInstanceFromGivenValue()
  45. {
  46. $response = Response::prepare('Taylor');
  47. $this->assertInstanceOf('Laravel\\Response', $response);
  48. $this->assertEquals('Taylor', $response->content);
  49. $response = Response::prepare(new Response('Taylor'));
  50. $this->assertInstanceOf('Laravel\\Response', $response);
  51. $this->assertEquals('Taylor', $response->content);
  52. }
  53. /**
  54. * Test the Response::header method.
  55. *
  56. * @group laravel
  57. */
  58. public function testHeaderMethodSetsValueInHeaderArray()
  59. {
  60. $response = Response::make('')->header('foo', 'bar');
  61. $this->assertEquals('bar', $response->headers()->get('foo'));
  62. }
  63. /**
  64. * Test the Response::status method.
  65. *
  66. * @group laravel
  67. */
  68. public function testStatusMethodSetsStatusCode()
  69. {
  70. $response = Response::make('')->status(404);
  71. $this->assertEquals(404, $response->status());
  72. }
  73. }