CommonExtendedBackendTest.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. require_once 'PHPUnit/Util/Filter.php';
  3. PHPUnit_Util_Filter::addFileToFilter(__FILE__);
  4. /**
  5. * @package Zend_Cache
  6. * @subpackage UnitTests
  7. */
  8. /**
  9. * PHPUnit test case
  10. */
  11. require_once 'PHPUnit/Framework/TestCase.php';
  12. /**
  13. * @see Zend_Cache_CommonBackendTest
  14. */
  15. require_once 'CommonBackendTest.php';
  16. /**
  17. * @package Zend_Cache
  18. * @subpackage UnitTests
  19. */
  20. class Zend_Cache_CommonExtendedBackendTest extends Zend_Cache_CommonBackendTest {
  21. private $_capabilities;
  22. public function __construct($name = null, array $data = array(), $dataName = '')
  23. {
  24. parent::__construct($name);
  25. }
  26. public function setUp($notag = false)
  27. {
  28. parent::setUp($notag);
  29. $this->_capabilities = $this->_instance->getCapabilities();
  30. }
  31. public function testGetFillingPercentage()
  32. {
  33. $res = $this->_instance->getFillingPercentage();
  34. $this->assertTrue(is_integer($res));
  35. $this->assertTrue($res >= 0);
  36. $this->assertTrue($res <= 100);
  37. }
  38. public function testGetIds()
  39. {
  40. if (!($this->_capabilities['get_list'])) {
  41. # unsupported by this backend
  42. return;
  43. }
  44. $res = $this->_instance->getIds();
  45. $this->assertTrue(count($res) == 3);
  46. $this->assertTrue(in_array('bar', $res));
  47. $this->assertTrue(in_array('bar2', $res));
  48. $this->assertTrue(in_array('bar3', $res));
  49. }
  50. public function testGetTags()
  51. {
  52. if (!($this->_capabilities['tags'])) {
  53. # unsupported by this backend
  54. return;
  55. }
  56. $res = $this->_instance->getTags();
  57. $this->assertTrue(count($res) == 4);
  58. $this->assertTrue(in_array('tag1', $res));
  59. $this->assertTrue(in_array('tag2', $res));
  60. $this->assertTrue(in_array('tag3', $res));
  61. $this->assertTrue(in_array('tag4', $res));
  62. }
  63. public function testGetIdsMatchingTags()
  64. {
  65. if (!($this->_capabilities['tags'])) {
  66. # unsupported by this backend
  67. return;
  68. }
  69. $res = $this->_instance->getIdsMatchingTags(array('tag3'));
  70. $this->assertTrue(count($res) == 3);
  71. $this->assertTrue(in_array('bar', $res));
  72. $this->assertTrue(in_array('bar2', $res));
  73. $this->assertTrue(in_array('bar3', $res));
  74. }
  75. public function testGetIdsMatchingTags2()
  76. {
  77. if (!($this->_capabilities['tags'])) {
  78. # unsupported by this backend
  79. return;
  80. }
  81. $res = $this->_instance->getIdsMatchingTags(array('tag2'));
  82. $this->assertTrue(count($res) == 1);
  83. $this->assertTrue(in_array('bar3', $res));
  84. }
  85. public function testGetIdsMatchingTags3()
  86. {
  87. if (!($this->_capabilities['tags'])) {
  88. # unsupported by this backend
  89. return;
  90. }
  91. $res = $this->_instance->getIdsMatchingTags(array('tag9999'));
  92. $this->assertTrue(count($res) == 0);
  93. }
  94. public function testGetIdsMatchingTags4()
  95. {
  96. if (!($this->_capabilities['tags'])) {
  97. # unsupported by this backend
  98. return;
  99. }
  100. $res = $this->_instance->getIdsMatchingTags(array('tag3', 'tag4'));
  101. $this->assertTrue(count($res) == 1);
  102. $this->assertTrue(in_array('bar', $res));
  103. }
  104. public function testGetIdsNotMatchingTags()
  105. {
  106. if (!($this->_capabilities['tags'])) {
  107. # unsupported by this backend
  108. return;
  109. }
  110. $res = $this->_instance->getIdsNotMatchingTags(array('tag3'));
  111. $this->assertTrue(count($res) == 0);
  112. }
  113. public function testGetIdsNotMatchingTags2()
  114. {
  115. if (!($this->_capabilities['tags'])) {
  116. # unsupported by this backend
  117. return;
  118. }
  119. $res = $this->_instance->getIdsNotMatchingTags(array('tag1'));
  120. $this->assertTrue(count($res) == 2);
  121. $this->assertTrue(in_array('bar', $res));
  122. $this->assertTrue(in_array('bar3', $res));
  123. }
  124. public function testGetIdsNotMatchingTags3()
  125. {
  126. if (!($this->_capabilities['tags'])) {
  127. # unsupported by this backend
  128. return;
  129. }
  130. $res = $this->_instance->getIdsNotMatchingTags(array('tag1', 'tag4'));
  131. $this->assertTrue(count($res) == 1);
  132. $this->assertTrue(in_array('bar3', $res));
  133. }
  134. public function testGetMetadatas($notag = false)
  135. {
  136. $res = $this->_instance->getMetadatas('bar');
  137. $this->assertTrue(isset($res['tags']));
  138. $this->assertTrue(isset($res['mtime']));
  139. $this->assertTrue(isset($res['expire']));
  140. if ($notag) {
  141. $this->assertTrue(count($res['tags']) == 0);
  142. } else {
  143. $this->assertTrue(count($res['tags']) == 2);
  144. $this->assertTrue(in_array('tag3', $res['tags']));
  145. $this->assertTrue(in_array('tag4', $res['tags']));
  146. }
  147. $this->assertTrue($res['expire'] > time());
  148. $this->assertTrue($res['mtime'] <= time());
  149. }
  150. public function testTouch()
  151. {
  152. $res = $this->_instance->getMetadatas('bar');
  153. $bool = $this->_instance->touch('bar', 30);
  154. $this->assertTrue($bool);
  155. $res2 = $this->_instance->getMetadatas('bar');
  156. $this->assertTrue(($res2['expire'] - $res['expire']) == 30);
  157. $this->assertTrue(($res2['mtime'] >= $res['mtime']));
  158. }
  159. public function testGetCapabilities()
  160. {
  161. $res = $this->_instance->getCapabilities();
  162. $this->assertTrue(isset($res['tags']));
  163. $this->assertTrue(isset($res['automatic_cleaning']));
  164. $this->assertTrue(isset($res['expired_read']));
  165. $this->assertTrue(isset($res['priority']));
  166. $this->assertTrue(isset($res['infinite_lifetime']));
  167. $this->assertTrue(isset($res['get_list']));
  168. }
  169. }