2
0

CommonExtendedBackendTest.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 testGetIds()
  59. {
  60. if (!($this->_capabilities['get_list'])) {
  61. # unsupported by this backend
  62. return;
  63. }
  64. $res = $this->_instance->getIds();
  65. $this->assertTrue(count($res) == 3);
  66. $this->assertTrue(in_array('bar', $res));
  67. $this->assertTrue(in_array('bar2', $res));
  68. $this->assertTrue(in_array('bar3', $res));
  69. }
  70. public function testGetTags()
  71. {
  72. if (!($this->_capabilities['tags'])) {
  73. # unsupported by this backend
  74. return;
  75. }
  76. $res = $this->_instance->getTags();
  77. $this->assertTrue(count($res) == 4);
  78. $this->assertTrue(in_array('tag1', $res));
  79. $this->assertTrue(in_array('tag2', $res));
  80. $this->assertTrue(in_array('tag3', $res));
  81. $this->assertTrue(in_array('tag4', $res));
  82. }
  83. public function testGetIdsMatchingTags()
  84. {
  85. if (!($this->_capabilities['tags'])) {
  86. # unsupported by this backend
  87. return;
  88. }
  89. $res = $this->_instance->getIdsMatchingTags(array('tag3'));
  90. $this->assertTrue(count($res) == 3);
  91. $this->assertTrue(in_array('bar', $res));
  92. $this->assertTrue(in_array('bar2', $res));
  93. $this->assertTrue(in_array('bar3', $res));
  94. }
  95. public function testGetIdsMatchingTags2()
  96. {
  97. if (!($this->_capabilities['tags'])) {
  98. # unsupported by this backend
  99. return;
  100. }
  101. $res = $this->_instance->getIdsMatchingTags(array('tag2'));
  102. $this->assertTrue(count($res) == 1);
  103. $this->assertTrue(in_array('bar3', $res));
  104. }
  105. public function testGetIdsMatchingTags3()
  106. {
  107. if (!($this->_capabilities['tags'])) {
  108. # unsupported by this backend
  109. return;
  110. }
  111. $res = $this->_instance->getIdsMatchingTags(array('tag9999'));
  112. $this->assertTrue(count($res) == 0);
  113. }
  114. public function testGetIdsMatchingTags4()
  115. {
  116. if (!($this->_capabilities['tags'])) {
  117. # unsupported by this backend
  118. return;
  119. }
  120. $res = $this->_instance->getIdsMatchingTags(array('tag3', 'tag4'));
  121. $this->assertTrue(count($res) == 1);
  122. $this->assertTrue(in_array('bar', $res));
  123. }
  124. public function testGetIdsNotMatchingTags()
  125. {
  126. if (!($this->_capabilities['tags'])) {
  127. # unsupported by this backend
  128. return;
  129. }
  130. $res = $this->_instance->getIdsNotMatchingTags(array('tag3'));
  131. $this->assertTrue(count($res) == 0);
  132. }
  133. public function testGetIdsNotMatchingTags2()
  134. {
  135. if (!($this->_capabilities['tags'])) {
  136. # unsupported by this backend
  137. return;
  138. }
  139. $res = $this->_instance->getIdsNotMatchingTags(array('tag1'));
  140. $this->assertTrue(count($res) == 2);
  141. $this->assertTrue(in_array('bar', $res));
  142. $this->assertTrue(in_array('bar3', $res));
  143. }
  144. public function testGetIdsNotMatchingTags3()
  145. {
  146. if (!($this->_capabilities['tags'])) {
  147. # unsupported by this backend
  148. return;
  149. }
  150. $res = $this->_instance->getIdsNotMatchingTags(array('tag1', 'tag4'));
  151. $this->assertTrue(count($res) == 1);
  152. $this->assertTrue(in_array('bar3', $res));
  153. }
  154. public function testGetMetadatas($notag = false)
  155. {
  156. $res = $this->_instance->getMetadatas('bar');
  157. $this->assertTrue(isset($res['tags']));
  158. $this->assertTrue(isset($res['mtime']));
  159. $this->assertTrue(isset($res['expire']));
  160. if ($notag) {
  161. $this->assertTrue(count($res['tags']) == 0);
  162. } else {
  163. $this->assertTrue(count($res['tags']) == 2);
  164. $this->assertTrue(in_array('tag3', $res['tags']));
  165. $this->assertTrue(in_array('tag4', $res['tags']));
  166. }
  167. $this->assertTrue($res['expire'] > time());
  168. $this->assertTrue($res['mtime'] <= time());
  169. }
  170. public function testTouch()
  171. {
  172. $res = $this->_instance->getMetadatas('bar');
  173. $bool = $this->_instance->touch('bar', 30);
  174. $this->assertTrue($bool);
  175. $res2 = $this->_instance->getMetadatas('bar');
  176. $this->assertTrue(($res2['expire'] - $res['expire']) == 30);
  177. $this->assertTrue(($res2['mtime'] >= $res['mtime']));
  178. }
  179. public function testGetCapabilities()
  180. {
  181. $res = $this->_instance->getCapabilities();
  182. $this->assertTrue(isset($res['tags']));
  183. $this->assertTrue(isset($res['automatic_cleaning']));
  184. $this->assertTrue(isset($res['expired_read']));
  185. $this->assertTrue(isset($res['priority']));
  186. $this->assertTrue(isset($res['infinite_lifetime']));
  187. $this->assertTrue(isset($res['get_list']));
  188. }
  189. }