CommonExtendedBackendTest.php 6.9 KB

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