CommonExtendedBackendTest.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id$
  21. */
  22. require_once 'PHPUnit/Util/Filter.php';
  23. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  24. /**
  25. * PHPUnit test case
  26. */
  27. require_once 'PHPUnit/Framework/TestCase.php';
  28. /**
  29. * @see Zend_Cache_CommonBackendTest
  30. */
  31. require_once 'CommonBackendTest.php';
  32. /**
  33. * @category Zend
  34. * @package Zend_Cache
  35. * @subpackage UnitTests
  36. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  37. * @license http://framework.zend.com/license/new-bsd New BSD License
  38. * @group Zend_Cache
  39. */
  40. class Zend_Cache_CommonExtendedBackendTest extends Zend_Cache_CommonBackendTest {
  41. private $_capabilities;
  42. public function __construct($name = null, array $data = array(), $dataName = '')
  43. {
  44. parent::__construct($name);
  45. }
  46. public function setUp($notag = false)
  47. {
  48. parent::setUp($notag);
  49. $this->_capabilities = $this->_instance->getCapabilities();
  50. }
  51. public function testGetFillingPercentage()
  52. {
  53. $res = $this->_instance->getFillingPercentage();
  54. $this->assertTrue(is_integer($res));
  55. $this->assertTrue($res >= 0);
  56. $this->assertTrue($res <= 100);
  57. }
  58. public function testGetFillingPercentageOnEmptyBackend()
  59. {
  60. $this->_instance->setDirectives(array('logging' => false)); // ???
  61. $this->_instance->clean(Zend_Cache::CLEANING_MODE_ALL);
  62. $res = $this->_instance->getFillingPercentage();
  63. $this->_instance->setDirectives(array('logging' => true)); // ???
  64. $this->assertTrue(is_integer($res));
  65. $this->assertTrue($res >= 0);
  66. $this->assertTrue($res <= 100);
  67. }
  68. public function testGetIds()
  69. {
  70. if (!($this->_capabilities['get_list'])) {
  71. # unsupported by this backend
  72. return;
  73. }
  74. $res = $this->_instance->getIds();
  75. $this->assertTrue(count($res) == 3);
  76. $this->assertTrue(in_array('bar', $res));
  77. $this->assertTrue(in_array('bar2', $res));
  78. $this->assertTrue(in_array('bar3', $res));
  79. }
  80. public function testGetTags()
  81. {
  82. if (!($this->_capabilities['tags'])) {
  83. # unsupported by this backend
  84. return;
  85. }
  86. $res = $this->_instance->getTags();
  87. $this->assertTrue(count($res) == 4);
  88. $this->assertTrue(in_array('tag1', $res));
  89. $this->assertTrue(in_array('tag2', $res));
  90. $this->assertTrue(in_array('tag3', $res));
  91. $this->assertTrue(in_array('tag4', $res));
  92. }
  93. public function testGetIdsMatchingTags()
  94. {
  95. if (!($this->_capabilities['tags'])) {
  96. # unsupported by this backend
  97. return;
  98. }
  99. $res = $this->_instance->getIdsMatchingTags(array('tag3'));
  100. $this->assertTrue(count($res) == 3);
  101. $this->assertTrue(in_array('bar', $res));
  102. $this->assertTrue(in_array('bar2', $res));
  103. $this->assertTrue(in_array('bar3', $res));
  104. }
  105. public function testGetIdsMatchingTags2()
  106. {
  107. if (!($this->_capabilities['tags'])) {
  108. # unsupported by this backend
  109. return;
  110. }
  111. $res = $this->_instance->getIdsMatchingTags(array('tag2'));
  112. $this->assertTrue(count($res) == 1);
  113. $this->assertTrue(in_array('bar3', $res));
  114. }
  115. public function testGetIdsMatchingTags3()
  116. {
  117. if (!($this->_capabilities['tags'])) {
  118. # unsupported by this backend
  119. return;
  120. }
  121. $res = $this->_instance->getIdsMatchingTags(array('tag9999'));
  122. $this->assertTrue(count($res) == 0);
  123. }
  124. public function testGetIdsMatchingTags4()
  125. {
  126. if (!($this->_capabilities['tags'])) {
  127. # unsupported by this backend
  128. return;
  129. }
  130. $res = $this->_instance->getIdsMatchingTags(array('tag3', 'tag4'));
  131. $this->assertTrue(count($res) == 1);
  132. $this->assertTrue(in_array('bar', $res));
  133. }
  134. public function testGetIdsNotMatchingTags()
  135. {
  136. if (!($this->_capabilities['tags'])) {
  137. # unsupported by this backend
  138. return;
  139. }
  140. $res = $this->_instance->getIdsNotMatchingTags(array('tag3'));
  141. $this->assertTrue(count($res) == 0);
  142. }
  143. public function testGetIdsNotMatchingTags2()
  144. {
  145. if (!($this->_capabilities['tags'])) {
  146. # unsupported by this backend
  147. return;
  148. }
  149. $res = $this->_instance->getIdsNotMatchingTags(array('tag1'));
  150. $this->assertTrue(count($res) == 2);
  151. $this->assertTrue(in_array('bar', $res));
  152. $this->assertTrue(in_array('bar3', $res));
  153. }
  154. public function testGetIdsNotMatchingTags3()
  155. {
  156. if (!($this->_capabilities['tags'])) {
  157. # unsupported by this backend
  158. return;
  159. }
  160. $res = $this->_instance->getIdsNotMatchingTags(array('tag1', 'tag4'));
  161. $this->assertTrue(count($res) == 1);
  162. $this->assertTrue(in_array('bar3', $res));
  163. }
  164. public function testGetMetadatas($notag = false)
  165. {
  166. $res = $this->_instance->getMetadatas('bar');
  167. $this->assertTrue(isset($res['tags']));
  168. $this->assertTrue(isset($res['mtime']));
  169. $this->assertTrue(isset($res['expire']));
  170. if ($notag) {
  171. $this->assertTrue(count($res['tags']) == 0);
  172. } else {
  173. $this->assertTrue(count($res['tags']) == 2);
  174. $this->assertTrue(in_array('tag3', $res['tags']));
  175. $this->assertTrue(in_array('tag4', $res['tags']));
  176. }
  177. $this->assertTrue($res['expire'] > time());
  178. $this->assertTrue($res['mtime'] <= time());
  179. }
  180. public function testTouch()
  181. {
  182. $res = $this->_instance->getMetadatas('bar');
  183. $bool = $this->_instance->touch('bar', 30);
  184. $this->assertTrue($bool);
  185. $res2 = $this->_instance->getMetadatas('bar');
  186. $this->assertTrue(($res2['expire'] - $res['expire']) == 30);
  187. $this->assertTrue(($res2['mtime'] >= $res['mtime']));
  188. }
  189. public function testGetCapabilities()
  190. {
  191. $res = $this->_instance->getCapabilities();
  192. $this->assertTrue(isset($res['tags']));
  193. $this->assertTrue(isset($res['automatic_cleaning']));
  194. $this->assertTrue(isset($res['expired_read']));
  195. $this->assertTrue(isset($res['priority']));
  196. $this->assertTrue(isset($res['infinite_lifetime']));
  197. $this->assertTrue(isset($res['get_list']));
  198. }
  199. }