PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Controller/Response/HttpTestCaseTest.php

https://bitbucket.org/ksekar/campus
PHP | 131 lines | 69 code | 11 blank | 51 comment | 3 complexity | 043fdd203554826145c227a45db6b794 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.0, MIT
  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-2012 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: HttpTestCaseTest.php 24594 2012-01-05 21:27:01Z matthew $
  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. /** Zend_Controller_Response_HttpTestCase */
  27. require_once 'Zend/Controller/Response/HttpTestCase.php';
  28. /**
  29. * Test class for Zend_Controller_Response_HttpTestCase.
  30. *
  31. * @category Zend
  32. * @package Zend_Controller
  33. * @subpackage UnitTests
  34. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  35. * @license http://framework.zend.com/license/new-bsd New BSD License
  36. * @group Zend_Controller
  37. * @group Zend_Controller_Response
  38. */
  39. class Zend_Controller_Response_HttpTestCaseTest extends PHPUnit_Framework_TestCase
  40. {
  41. /**
  42. * Runs the test methods of this class.
  43. *
  44. * @return void
  45. */
  46. public static function main()
  47. {
  48. $suite = new PHPUnit_Framework_TestSuite("Zend_Controller_Response_HttpTestCaseTest");
  49. $result = PHPUnit_TextUI_TestRunner::run($suite);
  50. }
  51. /**
  52. * Sets up the fixture, for example, open a network connection.
  53. * This method is called before a test is executed.
  54. *
  55. * @return void
  56. */
  57. public function setUp()
  58. {
  59. $this->response = new Zend_Controller_Response_HttpTestCase();
  60. }
  61. /**
  62. * Tears down the fixture, for example, close a network connection.
  63. * This method is called after a test is executed.
  64. *
  65. * @return void
  66. */
  67. public function tearDown()
  68. {
  69. }
  70. public function testToStringAndSendResponseShouldNotEchoOutput()
  71. {
  72. $this->response->setHeader('X-Foo-Bar', 'baz')
  73. ->setBody('Body to emit');
  74. ob_start();
  75. $this->response->sendResponse();
  76. $test = ob_get_clean();
  77. $this->assertTrue(empty($test));
  78. }
  79. public function testSendResponseShouldRenderHeaders()
  80. {
  81. $this->response->setHeader('X-Foo-Bar', 'baz')
  82. ->setBody('Body to emit');
  83. $test = $this->response->sendResponse();
  84. $this->assertContains("X-Foo-Bar: baz\n\nBody to emit", $test);
  85. }
  86. public function testOutputBodyShouldReturnStringInsteadOfEchoingOutput()
  87. {
  88. $this->response->append('foo', "Foo Content\n")
  89. ->append('bar', "Bar Content\n")
  90. ->prepend('baz', "Baz Content\n");
  91. ob_start();
  92. $content = $this->response->outputBody();
  93. $test = ob_get_clean();
  94. $this->assertTrue(empty($test));
  95. $this->assertFalse(empty($content));
  96. $this->assertContains("Baz Content\nFoo Content\nBar Content\n", $content, $content);
  97. }
  98. public function testSendHeadersShouldReturnArrayOfHeadersInsteadOfSendingHeaders()
  99. {
  100. $this->response->setRawHeader('200 OK')
  101. ->setHeader('Content-Type', 'text/xml')
  102. ->setHeader('Content-Type', 'text/html', true)
  103. ->setHeader('X-Foo-Bar', 'baz');
  104. $test = $this->response->sendHeaders();
  105. $this->assertTrue(is_array($test));
  106. $this->assertEquals(3, count($test));
  107. $this->assertNotContains('Content-Type: text/xml', $test);
  108. $this->assertContains('Content-Type: text/html', $test);
  109. $this->assertContains('X-Foo-Bar: baz', $test);
  110. $this->assertContains('200 OK', $test);
  111. }
  112. public function testCanSendHeadersShouldAlwaysReturnTrue()
  113. {
  114. $this->assertTrue($this->response->canSendHeaders());
  115. }
  116. }
  117. // Call Zend_Controller_Response_HttpTestCaseTest::main() if this source file is executed directly.
  118. if (PHPUnit_MAIN_METHOD == "Zend_Controller_Response_HttpTestCaseTest::main") {
  119. Zend_Controller_Response_HttpTestCaseTest::main();
  120. }