function testInitSettings() { Cache::engine('File', array('path' => TMP . 'tests')); $settings = Cache::settings(); $expecting = array('duration' => 3600, 'probability' => 100, 'path' => TMP . 'tests', 'prefix' => 'cake_', 'lock' => false, 'serialize' => true); $this->assertEqual($settings, $expecting); }
function skip() { $skip = true; if ($result = Cache::engine('Apc')) { $skip = false; } $this->skipif($skip, 'APCEngineTest not implemented'); }
/** * skip method * * @access public * @return void */ function skip() { $skip = true; if (Cache::engine('Apc')) { $skip = false; } $this->skipif($skip, 'Apc is not installed or configured properly'); }
/** * skip method * * @access public * @return void */ function skip() { $skip = true; if ($result = Cache::engine('Xcache')) { $skip = false; } $this->skipIf($skip, '%s Xcache is not installed or configured properly'); }
function skip() { $skip = true; if ($result = Cache::engine('Memcache')) { $skip = false; } $this->skipif($skip, 'Memcache not available'); }
/** * testWriteQuotedString method * * @access public * @return void */ function testWriteQuotedString() { Cache::engine('File', array('path' => TMP . 'tests')); Cache::write('App.doubleQuoteTest', '"this is a quoted string"'); $this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"'); Cache::write('App.singleQuoteTest', "'this is a quoted string'"); $this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'"); Cache::engine('File', array('isWindows' => true, 'path' => TMP . 'tests')); $this->assertIdentical(Cache::read('App.doubleQuoteTest'), '"this is a quoted string"'); Cache::write('App.singleQuoteTest', "'this is a quoted string'"); $this->assertIdentical(Cache::read('App.singleQuoteTest'), "'this is a quoted string'"); }
/** * testExpiry method * * @access public * @return void */ function testExpiry() { sleep(2); $result = Cache::read('test'); $this->assertFalse($result); $data = 'this is a test of the emergency broadcasting system'; $result = Cache::write('other_test', $data, 1); $this->assertTrue($result); sleep(2); $result = Cache::read('other_test'); $this->assertFalse($result); $data = 'this is a test of the emergency broadcasting system'; $result = Cache::write('other_test', $data, "+1 second"); $this->assertTrue($result); sleep(2); $result = Cache::read('other_test'); $this->assertFalse($result); $data = 'this is a test of the emergency broadcasting system'; $result = Cache::write('other_test', $data); $this->assertTrue($result); $result = Cache::read('other_test'); $this->assertEqual($result, $data); Cache::engine('Memcache', array('duration' => '+1 second')); sleep(2); $result = Cache::read('other_test'); $this->assertFalse($result); Cache::engine('Memcache', array('duration' => 3600)); }
/** * testInitSettings method * * @access public * @return void */ function testInitSettings() { Cache::engine('File', array('path' => TMP . 'tests')); $settings = Cache::settings(); $expecting = array('engine' => 'File', 'duration' => 3600, 'probability' => 100, 'path' => TMP . 'tests', 'prefix' => 'cake_', 'lock' => false, 'serialize' => true, 'isWindows' => DIRECTORY_SEPARATOR == '\\'); $this->assertEqual($settings, $expecting); Cache::engine('File'); }
/** Load and configure backend; Auto-detect if argument is FALSE @return string|void @param $dsn string|FALSE **/ static function load($dsn = FALSE) { if (is_bool($dsn)) { // Auto-detect backend $ext = array_map('strtolower', get_loaded_extensions()); $grep = preg_grep('/^(apc|xcache|shmop)/', $ext); $dsn = $grep ? current($grep) : 'folder=cache/'; } $parts = explode('=', $dsn); if (!preg_match('/apc|xcache|shmop|folder|memcache/', $parts[0])) { return; } self::$engine = array('type' => $parts[0], 'data' => NULL); self::$ref = NULL; if ($parts[0] == 'shmop') { $self = __CLASS__; self::$ref = self::mutex(function () use($self) { $ref = @shmop_open($ftok = ftok(__FILE__, 'C'), 'c', 0644, $self::bytes(ini_get('memory_limit'))); if ($ref && !unserialize(trim(shmop_read($ref, 0, 0xffff)))) { shmop_write($ref, serialize(array()) . chr(0), 0); } return $ref; }, self::$vars['TEMP'] . $_SERVER['SERVER_NAME']); if (!self::$ref) { return self::load('folder=cache/'); } } elseif (isset($parts[1])) { if ($parts[0] == 'memcache') { if (extension_loaded('memcache')) { foreach (self::split($parts[1]) as $server) { $parts = explode(':', $server); if (count($parts) < 2) { $host = $parts[0]; $port = 11211; } else { list($host, $port) = $parts; } if (!self::$ref) { self::$ref = @memcache_connect($host, $port); } else { memcache_add_server(self::$ref, $host, $port); } } } else { return self::$engine = NULL; } } elseif ($parts[0] == 'folder') { if (!is_dir($parts[1]) && !@mkdir($parts[1], 0755, TRUE)) { return self::$engine = NULL; } self::$ref = $parts[1]; } } return $dsn; }
/** * testWriteEmptyValues method * * @access public * @return void */ function testWriteEmptyValues() { return; Cache::engine('File', array('path' => TMP . 'tests')); Cache::write('App.falseTest', false); $this->assertIdentical(Cache::read('App.falseTest'), false); Cache::write('App.trueTest', true); $this->assertIdentical(Cache::read('App.trueTest'), true); Cache::write('App.nullTest', null); $this->assertIdentical(Cache::read('App.nullTest'), null); Cache::write('App.zeroTest', 0); $this->assertIdentical(Cache::read('App.zeroTest'), 0); Cache::write('App.zeroTest2', '0'); $this->assertIdentical(Cache::read('App.zeroTest2'), '0'); }
/** * Test engine method. * * Failure. * * @return void */ public function testEngineFailure() { $actual = Cache::engine('some_config_that_does_not_exist'); $this->assertNull($actual); Configure::write('Cache.disable', true); $actual = Cache::engine(); $this->assertNull($actual); }
function testClear() { $data = 'this is a test of the emergency broadcasting system'; $write = Cache::write('seriailze_test1', $data, 1); $write = Cache::write('seriailze_test2', $data, 1); $write = Cache::write('seriailze_test3', $data, 1); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1')); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2')); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3')); Cache::engine('File', array('duration' => 1)); sleep(4); $result = Cache::clear(true); $this->assertTrue($result); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1')); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2')); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3')); $data = 'this is a test of the emergency broadcasting system'; $write = Cache::write('seriailze_test1', $data, 1); $write = Cache::write('seriailze_test2', $data, 1); $write = Cache::write('seriailze_test3', $data, 1); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test1')); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test2')); $this->assertTrue(file_exists(CACHE . 'cake_seriailze_test3')); $result = Cache::clear(); $this->assertTrue($result); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test1')); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test2')); $this->assertFalse(file_exists(CACHE . 'cake_seriailze_test3')); }