PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/Zend/Cache/PageFrontendTest.php

https://bitbucket.org/ksekar/campus
PHP | 211 lines | 150 code | 19 blank | 42 comment | 4 complexity | 5d09b43c0215589b381a21308abad749 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_Cache
  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: PageFrontendTest.php 24594 2012-01-05 21:27:01Z matthew $
  21. */
  22. /**
  23. * Zend_Cache
  24. */
  25. require_once 'Zend/Cache.php';
  26. require_once 'Zend/Cache/Frontend/Page.php';
  27. require_once 'Zend/Cache/Backend/Test.php';
  28. /**
  29. * @category Zend
  30. * @package Zend_Cache
  31. * @subpackage UnitTests
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. * @group Zend_Cache
  35. */
  36. class Zend_Cache_PageFrontendTest extends PHPUnit_Framework_TestCase {
  37. private $_instance;
  38. public function setUp()
  39. {
  40. if (!$this->_instance) {
  41. $this->_instance = new Zend_Cache_Frontend_Page(array());
  42. $this->_backend = new Zend_Cache_Backend_Test();
  43. $this->_instance->setBackend($this->_backend);
  44. }
  45. }
  46. public function tearDown()
  47. {
  48. unset($this->_instance);
  49. }
  50. public function testConstructorCorrectCall()
  51. {
  52. $test = new Zend_Cache_Frontend_Page(array('lifetime' => 3600, 'caching' => true));
  53. }
  54. public function testConstructorUnimplementedOption()
  55. {
  56. try {
  57. $test = new Zend_Cache_Frontend_Page(array('http_conditional' => true));
  58. } catch (Exception $e) {
  59. return;
  60. }
  61. $this->fail('Zend_Cache_Exception was expected but not thrown');
  62. }
  63. public function testConstructorWithBadDefaultOptions()
  64. {
  65. try {
  66. $test = new Zend_Cache_Frontend_Page(array('default_options' => 'foo'));
  67. } catch (Exception $e) {
  68. return;
  69. }
  70. $this->fail('Zend_Cache_Exception was expected but not thrown');
  71. }
  72. /**
  73. * The only bad default options are non-string keys
  74. * @group ZF-5034
  75. */
  76. public function testConstructorWithBadDefaultOptions2()
  77. {
  78. try {
  79. $test = new Zend_Cache_Frontend_Page(array('default_options' => array('cache' => true, 1 => 'bar')));
  80. } catch (Exception $e) {
  81. return;
  82. }
  83. $this->fail('Zend_Cache_Exception was expected but not thrown');
  84. }
  85. public function testConstructorWithBadRegexps()
  86. {
  87. try {
  88. $test = new Zend_Cache_Frontend_Page(array('regexps' => 'foo'));
  89. } catch (Exception $e) {
  90. return;
  91. }
  92. $this->fail('Zend_Cache_Exception was expected but not thrown');
  93. }
  94. public function testConstructorWithBadRegexps2()
  95. {
  96. try {
  97. $test = new Zend_Cache_Frontend_Page(array('regexps' => array('foo', 'bar')));
  98. } catch (Exception $e) {
  99. return;
  100. }
  101. $this->fail('Zend_Cache_Exception was expected but not thrown');
  102. }
  103. /**
  104. * Only non-string keys should raise exceptions
  105. * @group ZF-5034
  106. */
  107. public function testConstructorWithBadRegexps3()
  108. {
  109. $array = array(
  110. '^/$' => array('cache' => true),
  111. '^/index/' => array('cache' => true),
  112. '^/article/' => array('cache' => false),
  113. '^/article/view/' => array(
  114. 1 => true,
  115. 'cache_with_post_variables' => true,
  116. 'make_id_with_post_variables' => true,
  117. )
  118. );
  119. try {
  120. $test = new Zend_Cache_Frontend_Page(array('regexps' => $array));
  121. } catch (Exception $e) {
  122. return;
  123. }
  124. $this->fail('Zend_Cache_Exception was expected but not thrown');
  125. }
  126. public function testConstructorWithGoodRegexps()
  127. {
  128. $array = array(
  129. '^/$' => array('cache' => true),
  130. '^/index/' => array('cache' => true),
  131. '^/article/' => array('cache' => false),
  132. '^/article/view/' => array(
  133. 'cache' => true,
  134. 'cache_with_post_variables' => true,
  135. 'make_id_with_post_variables' => true,
  136. )
  137. );
  138. $test = new Zend_Cache_Frontend_Page(array('regexps' => $array));
  139. }
  140. public function testConstructorWithGoodDefaultOptions()
  141. {
  142. $test = new Zend_Cache_Frontend_Page(array('default_options' => array('cache' => true)));
  143. }
  144. public function testStartEndCorrectCall1()
  145. {
  146. ob_start();
  147. ob_implicit_flush(false);
  148. if (!($this->_instance->start('serialized2', true))) {
  149. echo('foobar');
  150. ob_end_flush();
  151. }
  152. $data = ob_get_clean();
  153. ob_implicit_flush(true);
  154. $this->assertEquals('foo', $data);
  155. }
  156. public function testStartEndCorrectCall2()
  157. {
  158. ob_start();
  159. ob_implicit_flush(false);
  160. if (!($this->_instance->start('false', true))) {
  161. echo('foobar');
  162. ob_end_flush();
  163. }
  164. $data = ob_get_clean();
  165. ob_implicit_flush(true);
  166. $this->assertEquals('foobar', $data);
  167. }
  168. public function testStartEndCorrectCallWithDebug()
  169. {
  170. $this->_instance->setOption('debug_header', true);
  171. ob_start();
  172. ob_implicit_flush(false);
  173. if (!($this->_instance->start('serialized2', true))) {
  174. echo('foobar');
  175. ob_end_flush();
  176. }
  177. $data = ob_get_clean();
  178. ob_implicit_flush(true);
  179. $this->assertEquals('DEBUG HEADER : This is a cached page !foo', $data);
  180. }
  181. /**
  182. * @group ZF-10952
  183. */
  184. public function testNootice()
  185. {
  186. $regex = array('^/article/' => array('cache' => false));
  187. $this->_instance->setOption('regexps', $regex);
  188. $this->_instance->setOption('caching', false);
  189. $this->_instance->start('zf10952');
  190. ob_get_clean();
  191. }
  192. }