PageRenderTime 42ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/hardsshah/bookmarks
PHP | 178 lines | 91 code | 14 blank | 73 comment | 3 complexity | d1f3b591c69d4ae307c116208fb8d64f MD5 | raw file
  1. <?php
  2. /* SVN FILE: $Id$ */
  3. /**
  4. * CacheTest 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
  21. * @since CakePHP(tm) v 1.2.0.5432
  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. * CacheTest class
  32. *
  33. * @package cake
  34. * @subpackage cake.tests.cases.libs
  35. */
  36. class CacheTest extends CakeTestCase {
  37. /**
  38. * setUp method
  39. *
  40. * @access public
  41. * @return void
  42. */
  43. function setUp() {
  44. if (!isset($this->config)) {
  45. $this->config = Cache::config('default');
  46. }
  47. Cache::config('default', array('engine'=> 'File', 'path' => CACHE));
  48. }
  49. /**
  50. * end method
  51. *
  52. * @access public
  53. * @return void
  54. */
  55. function end() {
  56. Cache::config('default', $this->config['settings']);
  57. }
  58. /**
  59. * testConfig method
  60. *
  61. * @access public
  62. * @return void
  63. */
  64. function testConfig() {
  65. $settings = array('engine' => 'File', 'path' => TMP . 'tests', 'prefix' => 'cake_test_');
  66. $results = Cache::config('new', $settings);
  67. $this->assertEqual($results, Cache::config('new'));
  68. }
  69. /**
  70. * testConfigChange method
  71. *
  72. * @access public
  73. * @return void
  74. */
  75. function testConfigChange() {
  76. $result = Cache::config('sessions', array('engine'=> 'File', 'path' => TMP . 'sessions'));
  77. $this->assertEqual($result['settings'], Cache::settings('File'));
  78. $result = Cache::config('tests', array('engine'=> 'File', 'path' => TMP . 'tests'));
  79. $this->assertEqual($result['settings'], Cache::settings('File'));
  80. }
  81. /**
  82. * testWritingWithConfig method
  83. *
  84. * @access public
  85. * @return void
  86. */
  87. function testWritingWithConfig() {
  88. Cache::config('sessions');
  89. Cache::write('test_somthing', 'this is the test data', 'tests');
  90. $expected = array(
  91. 'path' => TMP . 'sessions',
  92. 'prefix' => 'cake_',
  93. 'lock' => false,
  94. 'serialize' => true,
  95. 'duration' => 3600,
  96. 'probability' => 100,
  97. 'engine' => 'File',
  98. 'isWindows' => DIRECTORY_SEPARATOR == '\\'
  99. );
  100. $this->assertEqual($expected, Cache::settings('File'));
  101. }
  102. /**
  103. * testInitSettings method
  104. *
  105. * @access public
  106. * @return void
  107. */
  108. function testInitSettings() {
  109. Cache::engine('File', array('path' => TMP . 'tests'));
  110. $settings = Cache::settings();
  111. $expecting = array(
  112. 'engine' => 'File',
  113. 'duration'=> 3600,
  114. 'probability' => 100,
  115. 'path'=> TMP . 'tests',
  116. 'prefix'=> 'cake_',
  117. 'lock' => false,
  118. 'serialize'=> true,
  119. 'isWindows' => DIRECTORY_SEPARATOR == '\\'
  120. );
  121. $this->assertEqual($settings, $expecting);
  122. }
  123. /**
  124. * testWriteEmptyValues method
  125. *
  126. * @access public
  127. * @return void
  128. */
  129. function testWriteEmptyValues() {
  130. return;
  131. Cache::engine('File', array('path' => TMP . 'tests'));
  132. Cache::write('App.falseTest', false);
  133. $this->assertIdentical(Cache::read('App.falseTest'), false);
  134. Cache::write('App.trueTest', true);
  135. $this->assertIdentical(Cache::read('App.trueTest'), true);
  136. Cache::write('App.nullTest', null);
  137. $this->assertIdentical(Cache::read('App.nullTest'), null);
  138. Cache::write('App.zeroTest', 0);
  139. $this->assertIdentical(Cache::read('App.zeroTest'), 0);
  140. Cache::write('App.zeroTest2', '0');
  141. $this->assertIdentical(Cache::read('App.zeroTest2'), '0');
  142. }
  143. /**
  144. * testSet method
  145. *
  146. * @access public
  147. * @return void
  148. */
  149. function testSet() {
  150. $write = false;
  151. Cache::set(array('duration' => '+1 year'));
  152. $data = Cache::read('test_cache');
  153. $this->assertFalse($data);
  154. $data = 'this is just a simple test of the cache system';
  155. $write = Cache::write('test_cache', $data);
  156. $this->assertTrue($write);
  157. Cache::set(array('duration' => '+1 year'));
  158. $data = Cache::read('test_cache');
  159. $this->assertEqual($data, 'this is just a simple test of the cache system');
  160. Cache::delete('test_cache');
  161. $global = Cache::settings();
  162. }
  163. }
  164. ?>