PageRenderTime 42ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/DevApp/library/ServerLibraries/ZendFramework/1.7/tests/Zend/Controller/Response/HttpTestCaseTest.php

http://firephp.googlecode.com/
PHP | 104 lines | 70 code | 11 blank | 23 comment | 3 complexity | 627d9032b086ddaec8668f406f8c875a MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT, Apache-2.0
  1. <?php
  2. // Call Zend_Controller_Response_HttpTestCaseTest::main() if this source file is executed directly.
  3. if (!defined("PHPUnit_MAIN_METHOD")) {
  4. define("PHPUnit_MAIN_METHOD", "Zend_Controller_Response_HttpTestCaseTest::main");
  5. }
  6. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  7. /** Zend_Controller_Response_HttpTestCase */
  8. require_once 'Zend/Controller/Response/HttpTestCase.php';
  9. /**
  10. * Test class for Zend_Controller_Response_HttpTestCase.
  11. */
  12. class Zend_Controller_Response_HttpTestCaseTest extends PHPUnit_Framework_TestCase
  13. {
  14. /**
  15. * Runs the test methods of this class.
  16. *
  17. * @return void
  18. */
  19. public static function main()
  20. {
  21. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Response_HttpTestCaseTest");
  22. $result = PHPUnit_TextUI_TestRunner::run($suite);
  23. }
  24. /**
  25. * Sets up the fixture, for example, open a network connection.
  26. * This method is called before a test is executed.
  27. *
  28. * @return void
  29. */
  30. public function setUp()
  31. {
  32. $this->response = new Zend_Controller_Response_HttpTestCase();
  33. }
  34. /**
  35. * Tears down the fixture, for example, close a network connection.
  36. * This method is called after a test is executed.
  37. *
  38. * @return void
  39. */
  40. public function tearDown()
  41. {
  42. }
  43. public function testToStringAndSendResponseShouldNotEchoOutput()
  44. {
  45. $this->response->setHeader('X-Foo-Bar', 'baz')
  46. ->setBody('Body to emit');
  47. ob_start();
  48. $this->response->sendResponse();
  49. $test = ob_get_clean();
  50. $this->assertTrue(empty($test));
  51. }
  52. public function testSendResponseShouldRenderHeaders()
  53. {
  54. $this->response->setHeader('X-Foo-Bar', 'baz')
  55. ->setBody('Body to emit');
  56. $test = $this->response->sendResponse();
  57. $this->assertContains("X-Foo-Bar: baz\n\nBody to emit", $test);
  58. }
  59. public function testOutputBodyShouldReturnStringInsteadOfEchoingOutput()
  60. {
  61. $this->response->append('foo', "Foo Content\n")
  62. ->append('bar', "Bar Content\n")
  63. ->prepend('baz', "Baz Content\n");
  64. ob_start();
  65. $content = $this->response->outputBody();
  66. $test = ob_get_clean();
  67. $this->assertTrue(empty($test));
  68. $this->assertFalse(empty($content));
  69. $this->assertContains("Baz Content\nFoo Content\nBar Content\n", $content, $content);
  70. }
  71. public function testSendHeadersShouldReturnArrayOfHeadersInsteadOfSendingHeaders()
  72. {
  73. $this->response->setRawHeader('200 OK')
  74. ->setHeader('Content-Type', 'text/xml')
  75. ->setHeader('Content-Type', 'text/html', true)
  76. ->setHeader('X-Foo-Bar', 'baz');
  77. $test = $this->response->sendHeaders();
  78. $this->assertTrue(is_array($test));
  79. $this->assertEquals(3, count($test));
  80. $this->assertNotContains('Content-Type: text/xml', $test);
  81. $this->assertContains('Content-Type: text/html', $test);
  82. $this->assertContains('X-Foo-Bar: baz', $test);
  83. $this->assertContains('200 OK', $test);
  84. }
  85. public function testCanSendHeadersShouldAlwaysReturnTrue()
  86. {
  87. $this->assertTrue($this->response->canSendHeaders());
  88. }
  89. }
  90. // Call Zend_Controller_Response_HttpTestCaseTest::main() if this source file is executed directly.
  91. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Response_HttpTestCaseTest::main") {
  92. Zend_Controller_Response_HttpTestCaseTest::main();
  93. }