HttpTestCaseTest.php 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Controller
  17. * @subpackage UnitTests
  18. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. // Call Zend_Controller_Response_HttpTestCaseTest::main() if this source file is executed directly.
  23. if (!defined("PHPUnit_MAIN_METHOD")) {
  24. define("PHPUnit_MAIN_METHOD", "Zend_Controller_Response_HttpTestCaseTest::main");
  25. }
  26. require_once dirname(__FILE__) . '/../../../TestHelper.php';
  27. /** Zend_Controller_Response_HttpTestCase */
  28. require_once 'Zend/Controller/Response/HttpTestCase.php';
  29. /**
  30. * Test class for Zend_Controller_Response_HttpTestCase.
  31. *
  32. * @category Zend
  33. * @package Zend_Controller
  34. * @subpackage UnitTests
  35. * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
  36. * @license http://framework.zend.com/license/new-bsd New BSD License
  37. * @group Zend_Controller
  38. * @group Zend_Controller_Response
  39. */
  40. class Zend_Controller_Response_HttpTestCaseTest extends PHPUnit_Framework_TestCase
  41. {
  42. /**
  43. * Runs the test methods of this class.
  44. *
  45. * @return void
  46. */
  47. public static function main()
  48. {
  49. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Response_HttpTestCaseTest");
  50. $result = PHPUnit_TextUI_TestRunner::run($suite);
  51. }
  52. /**
  53. * Sets up the fixture, for example, open a network connection.
  54. * This method is called before a test is executed.
  55. *
  56. * @return void
  57. */
  58. public function setUp()
  59. {
  60. $this->response = new Zend_Controller_Response_HttpTestCase();
  61. }
  62. /**
  63. * Tears down the fixture, for example, close a network connection.
  64. * This method is called after a test is executed.
  65. *
  66. * @return void
  67. */
  68. public function tearDown()
  69. {
  70. }
  71. public function testToStringAndSendResponseShouldNotEchoOutput()
  72. {
  73. $this->response->setHeader('X-Foo-Bar', 'baz')
  74. ->setBody('Body to emit');
  75. ob_start();
  76. $this->response->sendResponse();
  77. $test = ob_get_clean();
  78. $this->assertTrue(empty($test));
  79. }
  80. public function testSendResponseShouldRenderHeaders()
  81. {
  82. $this->response->setHeader('X-Foo-Bar', 'baz')
  83. ->setBody('Body to emit');
  84. $test = $this->response->sendResponse();
  85. $this->assertContains("X-Foo-Bar: baz\n\nBody to emit", $test);
  86. }
  87. public function testOutputBodyShouldReturnStringInsteadOfEchoingOutput()
  88. {
  89. $this->response->append('foo', "Foo Content\n")
  90. ->append('bar', "Bar Content\n")
  91. ->prepend('baz', "Baz Content\n");
  92. ob_start();
  93. $content = $this->response->outputBody();
  94. $test = ob_get_clean();
  95. $this->assertTrue(empty($test));
  96. $this->assertFalse(empty($content));
  97. $this->assertContains("Baz Content\nFoo Content\nBar Content\n", $content, $content);
  98. }
  99. public function testSendHeadersShouldReturnArrayOfHeadersInsteadOfSendingHeaders()
  100. {
  101. $this->response->setRawHeader('200 OK')
  102. ->setHeader('Content-Type', 'text/xml')
  103. ->setHeader('Content-Type', 'text/html', true)
  104. ->setHeader('X-Foo-Bar', 'baz');
  105. $test = $this->response->sendHeaders();
  106. $this->assertTrue(is_array($test));
  107. $this->assertEquals(3, count($test));
  108. $this->assertNotContains('Content-Type: text/xml', $test);
  109. $this->assertContains('Content-Type: text/html', $test);
  110. $this->assertContains('X-Foo-Bar: baz', $test);
  111. $this->assertContains('200 OK', $test);
  112. }
  113. public function testCanSendHeadersShouldAlwaysReturnTrue()
  114. {
  115. $this->assertTrue($this->response->canSendHeaders());
  116. }
  117. }
  118. // Call Zend_Controller_Response_HttpTestCaseTest::main() if this source file is executed directly.
  119. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Response_HttpTestCaseTest::main") {
  120. Zend_Controller_Response_HttpTestCaseTest::main();
  121. }