/cake/tests/cases/libs/cache/xcache.test.php

https://github.com/hardsshah/bookmarks · PHP · 169 lines · 78 code · 12 blank · 79 comment · 2 complexity · 4eaabce905e8d618a0c31f8724f9b026 MD5 · raw file

  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * XcacheEngineTest file
  5. *
  6. * Long description for file
  7. *
  8. * PHP versions 4 and 5
  9. *
  10. * CakePHP(tm) Tests <https://trac.cakephp.org/wiki/Developement/TestSuite>
  11. * Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  12. *
  13. * Licensed under The Open Group Test Suite License
  14. * Redistributions of files must retain the above copyright notice.
  15. *
  16. * @filesource
  17. * @copyright Copyright 2005-2008, Cake Software Foundation, Inc. (http://www.cakefoundation.org)
  18. * @link https://trac.cakephp.org/wiki/Developement/TestSuite CakePHP(tm) Tests
  19. * @package cake
  20. * @subpackage cake.tests.cases.libs.cache
  21. * @since CakePHP(tm) v 1.2.0.5434
  22. * @version $Revision$
  23. * @modifiedby $LastChangedBy$
  24. * @lastmodified $Date$
  25. * @license http://www.opensource.org/licenses/opengroup.php The Open Group Test Suite License
  26. */
  27. if (!class_exists('Cache')) {
  28. require LIBS . 'cache.php';
  29. }
  30. /**
  31. * XcacheEngineTest class
  32. *
  33. * @package cake
  34. * @subpackage cake.tests.cases.libs.cache
  35. */
  36. class XcacheEngineTest extends UnitTestCase {
  37. /**
  38. * skip method
  39. *
  40. * @access public
  41. * @return void
  42. */
  43. function skip() {
  44. $skip = true;
  45. if ($result = Cache::engine('Xcache')) {
  46. $skip = false;
  47. }
  48. $this->skipif($skip, 'Xcache is not installed or configured properly');
  49. }
  50. /**
  51. * setUp method
  52. *
  53. * @access public
  54. * @return void
  55. */
  56. function setUp() {
  57. Cache::config('xcache', array('engine'=>'Xcache', 'prefix' => 'cake_'));
  58. }
  59. /**
  60. * tearDown method
  61. *
  62. * @access public
  63. * @return void
  64. */
  65. function tearDown() {
  66. Cache::config('default');
  67. }
  68. /**
  69. * testSettings method
  70. *
  71. * @access public
  72. * @return void
  73. */
  74. function testSettings() {
  75. $settings = Cache::settings();
  76. $expecting = array('prefix' => 'cake_',
  77. 'duration'=> 3600,
  78. 'probability' => 100,
  79. 'engine' => 'Xcache',
  80. 'PHP_AUTH_USER' => 'user',
  81. 'PHP_AUTH_PW' => 'password',
  82. );
  83. $this->assertEqual($settings, $expecting);
  84. }
  85. /**
  86. * testReadAndWriteCache method
  87. *
  88. * @access public
  89. * @return void
  90. */
  91. function testReadAndWriteCache() {
  92. Cache::set(array('duration' => 1));
  93. $result = Cache::read('test');
  94. $expecting = '';
  95. $this->assertEqual($result, $expecting);
  96. $data = 'this is a test of the emergency broadcasting system';
  97. $result = Cache::write('test', $data);
  98. $this->assertTrue($result);
  99. $result = Cache::read('test');
  100. $expecting = $data;
  101. $this->assertEqual($result, $expecting);
  102. Cache::delete('test');
  103. }
  104. /**
  105. * testExpiry method
  106. *
  107. * @access public
  108. * @return void
  109. */
  110. function testExpiry() {
  111. Cache::set(array('duration' => 1));
  112. $result = Cache::read('test');
  113. $this->assertFalse($result);
  114. $data = 'this is a test of the emergency broadcasting system';
  115. $result = Cache::write('other_test', $data);
  116. $this->assertTrue($result);
  117. sleep(2);
  118. $result = Cache::read('other_test');
  119. $this->assertFalse($result);
  120. Cache::set(array('duration' => "+1 second"));
  121. $data = 'this is a test of the emergency broadcasting system';
  122. $result = Cache::write('other_test', $data);
  123. $this->assertTrue($result);
  124. sleep(2);
  125. $result = Cache::read('other_test');
  126. $this->assertFalse($result);
  127. }
  128. /**
  129. * testDeleteCache method
  130. *
  131. * @access public
  132. * @return void
  133. */
  134. function testDeleteCache() {
  135. $data = 'this is a test of the emergency broadcasting system';
  136. $result = Cache::write('delete_test', $data);
  137. $this->assertTrue($result);
  138. $result = Cache::delete('delete_test');
  139. $this->assertTrue($result);
  140. }
  141. /**
  142. * testClearCache method
  143. *
  144. * @access public
  145. * @return void
  146. */
  147. function testClearCache() {
  148. $data = 'this is a test of the emergency broadcasting system';
  149. $result = Cache::write('clear_test_1', $data);
  150. $this->assertTrue($result);
  151. $result = Cache::write('clear_test_2', $data);
  152. $this->assertTrue($result);
  153. $result = Cache::clear();
  154. $this->assertTrue($result);
  155. }
  156. }
  157. ?>