CommonExtendedBackendTest.php 6.9 KB

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