campus /tests/Zend/Cache/PageFrontendTest.php

Language PHP Lines 212
MD5 Hash 5d09b43c0215589b381a21308abad749 Estimated Cost $3,660 (why?)
Repository https://bitbucket.org/ksekar/campus.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/**
 * Zend Framework
 *
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://framework.zend.com/license/new-bsd
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@zend.com so we can send you a copy immediately.
 *
 * @category   Zend
 * @package    Zend_Cache
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @version    $Id: PageFrontendTest.php 24594 2012-01-05 21:27:01Z matthew $
 */

/**
 * Zend_Cache
 */
require_once 'Zend/Cache.php';
require_once 'Zend/Cache/Frontend/Page.php';
require_once 'Zend/Cache/Backend/Test.php';

/**
 * @category   Zend
 * @package    Zend_Cache
 * @subpackage UnitTests
 * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 * @group      Zend_Cache
 */
class Zend_Cache_PageFrontendTest extends PHPUnit_Framework_TestCase {

    private $_instance;

    public function setUp()
    {
        if (!$this->_instance) {
            $this->_instance = new Zend_Cache_Frontend_Page(array());
            $this->_backend = new Zend_Cache_Backend_Test();
            $this->_instance->setBackend($this->_backend);
        }
    }

    public function tearDown()
    {
        unset($this->_instance);
    }

    public function testConstructorCorrectCall()
    {
        $test = new Zend_Cache_Frontend_Page(array('lifetime' => 3600, 'caching' => true));
    }

    public function testConstructorUnimplementedOption()
    {
        try {
            $test = new Zend_Cache_Frontend_Page(array('http_conditional' => true));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    public function testConstructorWithBadDefaultOptions()
    {
        try {
            $test = new Zend_Cache_Frontend_Page(array('default_options' => 'foo'));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    /**
     * The only bad default options are non-string keys
     * @group ZF-5034
     */
    public function testConstructorWithBadDefaultOptions2()
    {
        try {
            $test = new Zend_Cache_Frontend_Page(array('default_options' => array('cache' => true, 1 => 'bar')));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    public function testConstructorWithBadRegexps()
    {
        try {
            $test = new Zend_Cache_Frontend_Page(array('regexps' => 'foo'));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    public function testConstructorWithBadRegexps2()
    {
        try {
            $test = new Zend_Cache_Frontend_Page(array('regexps' => array('foo', 'bar')));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    /**
     * Only non-string keys should raise exceptions
     * @group ZF-5034
     */
    public function testConstructorWithBadRegexps3()
    {
        $array = array(
           '^/$' => array('cache' => true),
           '^/index/' => array('cache' => true),
           '^/article/' => array('cache' => false),
           '^/article/view/' => array(
               1 => true,
               'cache_with_post_variables' => true,
               'make_id_with_post_variables' => true,
           )
        );
        try {
            $test = new Zend_Cache_Frontend_Page(array('regexps' => $array));
        } catch (Exception $e) {
            return;
        }
        $this->fail('Zend_Cache_Exception was expected but not thrown');
    }

    public function testConstructorWithGoodRegexps()
    {
        $array = array(
           '^/$' => array('cache' => true),
           '^/index/' => array('cache' => true),
           '^/article/' => array('cache' => false),
           '^/article/view/' => array(
               'cache' => true,
               'cache_with_post_variables' => true,
               'make_id_with_post_variables' => true,
           )
        );
        $test = new Zend_Cache_Frontend_Page(array('regexps' => $array));
    }

    public function testConstructorWithGoodDefaultOptions()
    {
        $test = new Zend_Cache_Frontend_Page(array('default_options' => array('cache' => true)));
    }

    public function testStartEndCorrectCall1()
    {
        ob_start();
        ob_implicit_flush(false);
        if (!($this->_instance->start('serialized2', true))) {
            echo('foobar');
            ob_end_flush();
        }
        $data = ob_get_clean();
        ob_implicit_flush(true);
        $this->assertEquals('foo', $data);
    }

    public function testStartEndCorrectCall2()
    {
        ob_start();
        ob_implicit_flush(false);
        if (!($this->_instance->start('false', true))) {
            echo('foobar');
            ob_end_flush();
        }
        $data = ob_get_clean();
        ob_implicit_flush(true);
        $this->assertEquals('foobar', $data);
    }

    public function testStartEndCorrectCallWithDebug()
    {
        $this->_instance->setOption('debug_header', true);
        ob_start();
        ob_implicit_flush(false);
        if (!($this->_instance->start('serialized2', true))) {
            echo('foobar');
            ob_end_flush();
        }
        $data = ob_get_clean();
        ob_implicit_flush(true);
        $this->assertEquals('DEBUG HEADER : This is a cached page !foo', $data);
    }

    /**
     * @group ZF-10952
     */
    public function testNootice()
    {
        $regex = array('^/article/' => array('cache' => false));
        $this->_instance->setOption('regexps', $regex);
        $this->_instance->setOption('caching', false);
        $this->_instance->start('zf10952');
        ob_get_clean();
    }
}
Back to Top