File indexing completed on 2025-01-26 05:24:54
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Controller 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Controller_Response_Http 0024 */ 0025 // require_once 'Zend/Controller/Response/Http.php'; 0026 0027 /** 0028 * Zend_Controller_Response_HttpTestCase 0029 * 0030 * @uses Zend_Controller_Response_Http 0031 * @package Zend_Controller 0032 * @subpackage Response 0033 */ 0034 class Zend_Controller_Response_HttpTestCase extends Zend_Controller_Response_Http 0035 { 0036 /** 0037 * "send" headers by returning array of all headers that would be sent 0038 * 0039 * @return array 0040 */ 0041 public function sendHeaders() 0042 { 0043 $headers = array(); 0044 foreach ($this->_headersRaw as $header) { 0045 $headers[] = $header; 0046 } 0047 foreach ($this->_headers as $header) { 0048 $name = $header['name']; 0049 $key = strtolower($name); 0050 if (array_key_exists($name, $headers)) { 0051 if ($header['replace']) { 0052 $headers[$key] = $header['name'] . ': ' . $header['value']; 0053 } 0054 } else { 0055 $headers[$key] = $header['name'] . ': ' . $header['value']; 0056 } 0057 } 0058 return $headers; 0059 } 0060 0061 /** 0062 * Can we send headers? 0063 * 0064 * @param bool $throw 0065 * @return void 0066 */ 0067 public function canSendHeaders($throw = false) 0068 { 0069 return true; 0070 } 0071 0072 /** 0073 * Return the concatenated body segments 0074 * 0075 * @return string 0076 */ 0077 public function outputBody() 0078 { 0079 $fullContent = ''; 0080 foreach ($this->_body as $content) { 0081 $fullContent .= $content; 0082 } 0083 return $fullContent; 0084 } 0085 0086 /** 0087 * Get body and/or body segments 0088 * 0089 * @param bool|string $spec 0090 * @return string|array|null 0091 */ 0092 public function getBody($spec = false) 0093 { 0094 if (false === $spec) { 0095 return $this->outputBody(); 0096 } elseif (true === $spec) { 0097 return $this->_body; 0098 } elseif (is_string($spec) && isset($this->_body[$spec])) { 0099 return $this->_body[$spec]; 0100 } 0101 0102 return null; 0103 } 0104 0105 /** 0106 * "send" Response 0107 * 0108 * Concats all response headers, and then final body (separated by two 0109 * newlines) 0110 * 0111 * @return string 0112 */ 0113 public function sendResponse() 0114 { 0115 $headers = $this->sendHeaders(); 0116 $content = implode("\n", $headers) . "\n\n"; 0117 0118 if ($this->isException() && $this->renderExceptions()) { 0119 $exceptions = ''; 0120 foreach ($this->getException() as $e) { 0121 $exceptions .= $e->__toString() . "\n"; 0122 } 0123 $content .= $exceptions; 0124 } else { 0125 $content .= $this->outputBody(); 0126 } 0127 0128 return $content; 0129 } 0130 }