~chroot64bit/zivios/gentoo-experimental

« back to all changes in this revision

Viewing changes to application/library/Zend/Controller/Response/HttpTestCase.php

  • Committer: Mustafa A. Hashmi
  • Date: 2008-12-04 13:32:21 UTC
  • Revision ID: mhashmi@zivios.org-20081204133221-0nd1trunwevijj38
Inclusion of new installation framework with ties to zend layout and dojo layout

Show diffs side-by-side

added added

removed removed

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