web/lib/Zend/Controller/Response/HttpTestCase.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     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  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: HttpTestCase.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Controller_Response_Http
       
    24  */
       
    25 require_once 'Zend/Controller/Response/Http.php';
       
    26 
       
    27 /**
       
    28  * Zend_Controller_Response_HttpTestCase
       
    29  *
       
    30  * @uses Zend_Controller_Response_Http
       
    31  * @package Zend_Controller
       
    32  * @subpackage Response
       
    33  */
       
    34 class Zend_Controller_Response_HttpTestCase extends Zend_Controller_Response_Http
       
    35 {
       
    36     /**
       
    37      * "send" headers by returning array of all headers that would be sent
       
    38      *
       
    39      * @return array
       
    40      */
       
    41     public function sendHeaders()
       
    42     {
       
    43         $headers = array();
       
    44         foreach ($this->_headersRaw as $header) {
       
    45             $headers[] = $header;
       
    46         }
       
    47         foreach ($this->_headers as $header) {
       
    48             $name = $header['name'];
       
    49             $key  = strtolower($name);
       
    50             if (array_key_exists($name, $headers)) {
       
    51                 if ($header['replace']) {
       
    52                     $headers[$key] = $header['name'] . ': ' . $header['value'];
       
    53                 }
       
    54             } else {
       
    55                 $headers[$key] = $header['name'] . ': ' . $header['value'];
       
    56             }
       
    57         }
       
    58         return $headers;
       
    59     }
       
    60 
       
    61     /**
       
    62      * Can we send headers?
       
    63      *
       
    64      * @param  bool $throw
       
    65      * @return void
       
    66      */
       
    67     public function canSendHeaders($throw = false)
       
    68     {
       
    69         return true;
       
    70     }
       
    71 
       
    72     /**
       
    73      * Return the concatenated body segments
       
    74      *
       
    75      * @return string
       
    76      */
       
    77     public function outputBody()
       
    78     {
       
    79         $fullContent = '';
       
    80         foreach ($this->_body as $content) {
       
    81             $fullContent .= $content;
       
    82         }
       
    83         return $fullContent;
       
    84     }
       
    85 
       
    86     /**
       
    87      * Get body and/or body segments
       
    88      *
       
    89      * @param  bool|string $spec
       
    90      * @return string|array|null
       
    91      */
       
    92     public function getBody($spec = false)
       
    93     {
       
    94         if (false === $spec) {
       
    95             return $this->outputBody();
       
    96         } elseif (true === $spec) {
       
    97             return $this->_body;
       
    98         } elseif (is_string($spec) && isset($this->_body[$spec])) {
       
    99             return $this->_body[$spec];
       
   100         }
       
   101 
       
   102         return null;
       
   103     }
       
   104 
       
   105     /**
       
   106      * "send" Response
       
   107      *
       
   108      * Concats all response headers, and then final body (separated by two
       
   109      * newlines)
       
   110      *
       
   111      * @return string
       
   112      */
       
   113     public function sendResponse()
       
   114     {
       
   115         $headers = $this->sendHeaders();
       
   116         $content = implode("\n", $headers) . "\n\n";
       
   117 
       
   118         if ($this->isException() && $this->renderExceptions()) {
       
   119             $exceptions = '';
       
   120             foreach ($this->getException() as $e) {
       
   121                 $exceptions .= $e->__toString() . "\n";
       
   122             }
       
   123             $content .= $exceptions;
       
   124         } else {
       
   125             $content .= $this->outputBody();
       
   126         }
       
   127 
       
   128         return $content;
       
   129     }
       
   130 }