2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FileEngineTest file
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2010-10-03 16:31:21 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Cache.Engine
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5434
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2011-03-06 04:56:31 +00:00
|
|
|
|
|
|
|
App::uses('Cache', 'Cache');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* FileEngineTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Cache.Engine
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
|
|
|
class FileEngineTest extends CakeTestCase {
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* config property
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @var array
|
|
|
|
*/
|
2010-04-04 07:14:00 +00:00
|
|
|
public $config = array();
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2010-09-22 02:16:33 +00:00
|
|
|
* setUp method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2011-03-12 17:06:10 +00:00
|
|
|
parent::setUp();
|
2009-03-21 23:55:39 +00:00
|
|
|
Configure::write('Cache.disable', false);
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::config('file_test', array('engine' => 'File', 'path' => CACHE));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
2011-12-04 21:27:51 +00:00
|
|
|
* tearDown method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2011-03-12 17:06:10 +00:00
|
|
|
parent::tearDown();
|
2013-08-02 21:56:11 +00:00
|
|
|
// Cache::clear(false, 'file_test');
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::drop('file_test');
|
2012-03-26 03:30:28 +00:00
|
|
|
Cache::drop('file_groups');
|
2012-03-26 04:03:37 +00:00
|
|
|
Cache::drop('file_groups2');
|
|
|
|
Cache::drop('file_groups3');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testCacheDirChange method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testCacheDirChange() {
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(Cache::settings('sessions'), $result['settings']);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'tests'));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(Cache::settings('sessions'), $result['settings']);
|
|
|
|
$this->assertNotEquals(Cache::settings('default'), $result['settings']);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testReadAndWriteCache method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testReadAndWriteCache() {
|
2008-06-02 17:35:56 +00:00
|
|
|
Cache::config('default');
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write(null, 'here', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::set(array('duration' => 1), 'file_test');
|
2009-02-06 22:56:06 +00:00
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expecting = '';
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expecting, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write('test', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_test'));
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$expecting = $data;
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expecting, $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::delete('test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-10-19 01:21:05 +00:00
|
|
|
/**
|
|
|
|
* Test read/write on the same cache key. Ensures file handles are re-wound.
|
2012-07-18 01:55:29 +00:00
|
|
|
*
|
2011-10-19 01:21:05 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testConsecutiveReadWrite() {
|
|
|
|
Cache::write('rw', 'first write', 'file_test');
|
|
|
|
$result = Cache::read('rw', 'file_test');
|
|
|
|
|
|
|
|
Cache::write('rw', 'second write', 'file_test');
|
2012-03-27 03:04:32 +00:00
|
|
|
$resultB = Cache::read('rw', 'file_test');
|
2011-10-19 01:21:05 +00:00
|
|
|
|
|
|
|
Cache::delete('rw', 'file_test');
|
|
|
|
$this->assertEquals('first write', $result);
|
2012-03-27 03:04:32 +00:00
|
|
|
$this->assertEquals('second write', $resultB);
|
2011-10-19 01:21:05 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExpiry method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExpiry() {
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::set(array('duration' => 1), 'file_test');
|
2009-02-06 22:56:06 +00:00
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write('other_test', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
sleep(2);
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('other_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
|
2012-03-11 03:29:35 +00:00
|
|
|
Cache::set(array('duration' => "+1 second"), 'file_test');
|
2009-02-06 22:56:06 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write('other_test', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
sleep(2);
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('other_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testDeleteCache method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDeleteCache() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write('delete_test', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::delete('delete_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test'));
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::delete('delete_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testSerialize method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testSerialize() {
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::config('file_test', array('engine' => 'File', 'serialize' => true));
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2011-03-12 17:06:10 +00:00
|
|
|
$write = Cache::write('serialize_test', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($write);
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::config('file_test', array('serialize' => false));
|
|
|
|
$read = Cache::read('serialize_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$newread = Cache::read('serialize_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2013-01-23 12:45:50 +00:00
|
|
|
Cache::delete('serialize_test', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame($read, serialize($data));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame(unserialize($newread), $data);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testClear method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testClear() {
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::config('file_test', array('engine' => 'File', 'duration' => 1));
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2014-02-11 21:38:24 +00:00
|
|
|
Cache::write('serialize_test1', $data, 'file_test');
|
|
|
|
Cache::write('serialize_test2', $data, 'file_test');
|
|
|
|
Cache::write('serialize_test3', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
2008-07-28 02:29:58 +00:00
|
|
|
sleep(2);
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::clear(true, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
|
|
|
|
|
|
|
$data = 'this is a test of the emergency broadcasting system';
|
2014-02-11 21:38:24 +00:00
|
|
|
Cache::write('serialize_test1', $data, 'file_test');
|
|
|
|
Cache::write('serialize_test2', $data, 'file_test');
|
|
|
|
Cache::write('serialize_test3', $data, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1'));
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2'));
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3'));
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::clear(false, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test1'));
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test2'));
|
|
|
|
$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3'));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2010-05-27 04:01:17 +00:00
|
|
|
/**
|
|
|
|
* test that clear() doesn't wipe files not in the current engine's prefix.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testClearWithPrefixes() {
|
2010-11-13 04:05:44 +00:00
|
|
|
$FileOne = new FileEngine();
|
2010-05-27 04:01:17 +00:00
|
|
|
$FileOne->init(array(
|
|
|
|
'prefix' => 'prefix_one_',
|
|
|
|
'duration' => DAY
|
|
|
|
));
|
2010-11-13 04:05:44 +00:00
|
|
|
$FileTwo = new FileEngine();
|
2010-05-27 04:01:17 +00:00
|
|
|
$FileTwo->init(array(
|
|
|
|
'prefix' => 'prefix_two_',
|
|
|
|
'duration' => DAY
|
|
|
|
));
|
|
|
|
|
2012-03-27 03:04:32 +00:00
|
|
|
$dataOne = $dataTwo = $expected = 'content to cache';
|
|
|
|
$FileOne->write('prefix_one_key_one', $dataOne, DAY);
|
|
|
|
$FileTwo->write('prefix_two_key_two', $dataTwo, DAY);
|
2010-05-27 04:01:17 +00:00
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $FileOne->read('prefix_one_key_one'));
|
|
|
|
$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two'));
|
2010-05-27 04:01:17 +00:00
|
|
|
|
|
|
|
$FileOne->clear(false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two'), 'secondary config was cleared by accident.');
|
2011-03-12 17:06:10 +00:00
|
|
|
$FileTwo->clear(false);
|
2010-05-27 04:01:17 +00:00
|
|
|
}
|
|
|
|
|
2013-07-27 21:15:15 +00:00
|
|
|
/**
|
|
|
|
* Test that clear() also removes files with group tags.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testClearWithGroups() {
|
|
|
|
$engine = new FileEngine();
|
|
|
|
$engine->init(array(
|
|
|
|
'prefix' => 'cake_test_',
|
|
|
|
'duration' => DAY,
|
2013-08-02 21:56:11 +00:00
|
|
|
'groups' => array('short', 'round')
|
2013-07-27 21:15:15 +00:00
|
|
|
));
|
2013-07-28 02:20:40 +00:00
|
|
|
$key = 'cake_test_test_key';
|
|
|
|
$engine->write($key, 'it works', DAY);
|
2013-07-27 21:15:15 +00:00
|
|
|
$engine->clear(false);
|
2013-07-28 02:20:40 +00:00
|
|
|
$this->assertFalse($engine->read($key), 'Key should have been removed');
|
2013-07-27 21:15:15 +00:00
|
|
|
}
|
|
|
|
|
2013-08-02 21:56:11 +00:00
|
|
|
/**
|
|
|
|
* Test that clear() also removes files with group tags.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testClearWithNoKeys() {
|
|
|
|
$engine = new FileEngine();
|
|
|
|
$engine->init(array(
|
|
|
|
'prefix' => 'cake_test_',
|
|
|
|
'duration' => DAY,
|
|
|
|
'groups' => array('one', 'two')
|
|
|
|
));
|
|
|
|
$key = 'cake_test_test_key';
|
|
|
|
$engine->clear(false);
|
|
|
|
$this->assertFalse($engine->read($key), 'No errors should be found');
|
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testKeyPath method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testKeyPath() {
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::write('views.countries.something', 'here', 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something'));
|
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$result = Cache::read('views.countries.something', 'file_test');
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('here', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-04-25 03:31:44 +00:00
|
|
|
$result = Cache::clear(false, 'file_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
$this->assertTrue($result);
|
2013-08-24 21:39:13 +00:00
|
|
|
|
|
|
|
$result = Cache::write('domain.test.com:8080', 'here', 'file_test');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_domain_test_com_8080'));
|
|
|
|
|
|
|
|
$result = Cache::write('command>dir|more', 'here', 'file_test');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertTrue(file_exists(CACHE . 'cake_command_dir_more'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testRemoveWindowsSlashesFromCache method
|
2008-06-24 01:09:54 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testRemoveWindowsSlashesFromCache() {
|
2009-11-18 23:07:48 +00:00
|
|
|
Cache::config('windows_test', array('engine' => 'File', 'isWindows' => true, 'prefix' => null, 'path' => TMP));
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2011-12-01 07:21:31 +00:00
|
|
|
$expected = array(
|
2009-11-18 23:07:48 +00:00
|
|
|
'C:\dev\prj2\sites\cake\libs' => array(
|
|
|
|
0 => 'C:\dev\prj2\sites\cake\libs', 1 => 'C:\dev\prj2\sites\cake\libs\view',
|
|
|
|
2 => 'C:\dev\prj2\sites\cake\libs\view\scaffolds', 3 => 'C:\dev\prj2\sites\cake\libs\view\pages',
|
|
|
|
4 => 'C:\dev\prj2\sites\cake\libs\view\layouts', 5 => 'C:\dev\prj2\sites\cake\libs\view\layouts\xml',
|
|
|
|
6 => 'C:\dev\prj2\sites\cake\libs\view\layouts\rss', 7 => 'C:\dev\prj2\sites\cake\libs\view\layouts\js',
|
|
|
|
8 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email', 9 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email\text',
|
|
|
|
10 => 'C:\dev\prj2\sites\cake\libs\view\layouts\email\html', 11 => 'C:\dev\prj2\sites\cake\libs\view\helpers',
|
|
|
|
12 => 'C:\dev\prj2\sites\cake\libs\view\errors', 13 => 'C:\dev\prj2\sites\cake\libs\view\elements',
|
|
|
|
14 => 'C:\dev\prj2\sites\cake\libs\view\elements\email', 15 => 'C:\dev\prj2\sites\cake\libs\view\elements\email\text',
|
|
|
|
16 => 'C:\dev\prj2\sites\cake\libs\view\elements\email\html', 17 => 'C:\dev\prj2\sites\cake\libs\model',
|
|
|
|
18 => 'C:\dev\prj2\sites\cake\libs\model\datasources', 19 => 'C:\dev\prj2\sites\cake\libs\model\datasources\dbo',
|
|
|
|
20 => 'C:\dev\prj2\sites\cake\libs\model\behaviors', 21 => 'C:\dev\prj2\sites\cake\libs\controller',
|
|
|
|
22 => 'C:\dev\prj2\sites\cake\libs\controller\components', 23 => 'C:\dev\prj2\sites\cake\libs\cache'),
|
|
|
|
'C:\dev\prj2\sites\main_site\vendors' => array(
|
|
|
|
0 => 'C:\dev\prj2\sites\main_site\vendors', 1 => 'C:\dev\prj2\sites\main_site\vendors\shells',
|
|
|
|
2 => 'C:\dev\prj2\sites\main_site\vendors\shells\templates', 3 => 'C:\dev\prj2\sites\main_site\vendors\shells\templates\cdc_project',
|
|
|
|
4 => 'C:\dev\prj2\sites\main_site\vendors\shells\tasks', 5 => 'C:\dev\prj2\sites\main_site\vendors\js',
|
|
|
|
6 => 'C:\dev\prj2\sites\main_site\vendors\css'),
|
|
|
|
'C:\dev\prj2\sites\vendors' => array(
|
|
|
|
0 => 'C:\dev\prj2\sites\vendors', 1 => 'C:\dev\prj2\sites\vendors\simpletest',
|
|
|
|
2 => 'C:\dev\prj2\sites\vendors\simpletest\test', 3 => 'C:\dev\prj2\sites\vendors\simpletest\test\support',
|
|
|
|
4 => 'C:\dev\prj2\sites\vendors\simpletest\test\support\collector', 5 => 'C:\dev\prj2\sites\vendors\simpletest\extensions',
|
|
|
|
6 => 'C:\dev\prj2\sites\vendors\simpletest\extensions\testdox', 7 => 'C:\dev\prj2\sites\vendors\simpletest\docs',
|
|
|
|
8 => 'C:\dev\prj2\sites\vendors\simpletest\docs\fr', 9 => 'C:\dev\prj2\sites\vendors\simpletest\docs\en'),
|
|
|
|
'C:\dev\prj2\sites\main_site\views\helpers' => array(
|
|
|
|
0 => 'C:\dev\prj2\sites\main_site\views\helpers')
|
|
|
|
);
|
|
|
|
|
|
|
|
Cache::write('test_dir_map', $expected, 'windows_test');
|
|
|
|
$data = Cache::read('test_dir_map', 'windows_test');
|
|
|
|
Cache::delete('test_dir_map', 'windows_test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $data);
|
2009-11-18 23:07:48 +00:00
|
|
|
|
|
|
|
Cache::drop('windows_test');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* testWriteQuotedString method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testWriteQuotedString() {
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::config('file_test', array('engine' => 'File', 'path' => TMP . 'tests'));
|
|
|
|
Cache::write('App.doubleQuoteTest', '"this is a quoted string"', 'file_test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
2011-03-12 17:06:10 +00:00
|
|
|
|
|
|
|
Cache::config('file_test', array('isWindows' => true, 'path' => TMP . 'tests'));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"');
|
2011-03-12 17:06:10 +00:00
|
|
|
Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'");
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::delete('App.singleQuoteTest', 'file_test');
|
|
|
|
Cache::delete('App.doubleQuoteTest', 'file_test');
|
2008-06-23 00:27:33 +00:00
|
|
|
}
|
2010-02-23 04:21:30 +00:00
|
|
|
|
|
|
|
/**
|
2013-08-07 11:24:45 +00:00
|
|
|
* check that FileEngine does not generate an error when a configured Path does not exist in debug mode.
|
2010-02-23 04:21:30 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2013-08-07 11:24:45 +00:00
|
|
|
public function testPathDoesNotExist() {
|
|
|
|
$this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.');
|
2011-05-31 00:49:46 +00:00
|
|
|
|
2013-08-07 11:24:45 +00:00
|
|
|
Cache::config('autocreate', array(
|
2010-02-23 04:21:30 +00:00
|
|
|
'engine' => 'File',
|
2013-08-07 11:24:45 +00:00
|
|
|
'path' => TMP . 'tests' . DS . 'autocreate'
|
2010-02-23 04:21:30 +00:00
|
|
|
));
|
|
|
|
|
2013-08-07 11:24:45 +00:00
|
|
|
Cache::drop('autocreate');
|
2010-02-23 04:21:30 +00:00
|
|
|
}
|
2011-10-11 11:26:03 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Testing the mask setting in FileEngine
|
2011-10-28 05:01:17 +00:00
|
|
|
*
|
2011-10-11 11:26:03 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testMaskSetting() {
|
2012-01-07 04:01:59 +00:00
|
|
|
if (DS === '\\') {
|
|
|
|
$this->markTestSkipped('File permission testing does not work on Windows.');
|
|
|
|
}
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::config('mask_test', array('engine' => 'File', 'path' => TMP . 'tests'));
|
|
|
|
$data = 'This is some test content';
|
|
|
|
$write = Cache::write('masking_test', $data, 'mask_test');
|
2013-08-07 23:03:21 +00:00
|
|
|
$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
2011-10-11 11:26:03 +00:00
|
|
|
$expected = '0664';
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::delete('masking_test', 'mask_test');
|
|
|
|
Cache::drop('mask_test');
|
|
|
|
|
|
|
|
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0666, 'path' => TMP . 'tests'));
|
2014-02-11 21:38:24 +00:00
|
|
|
Cache::write('masking_test', $data, 'mask_test');
|
2013-08-07 23:03:21 +00:00
|
|
|
$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
2011-10-11 11:26:03 +00:00
|
|
|
$expected = '0666';
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::delete('masking_test', 'mask_test');
|
|
|
|
Cache::drop('mask_test');
|
|
|
|
|
|
|
|
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0644, 'path' => TMP . 'tests'));
|
2014-02-11 21:38:24 +00:00
|
|
|
Cache::write('masking_test', $data, 'mask_test');
|
2013-08-07 23:03:21 +00:00
|
|
|
$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
2011-10-11 11:26:03 +00:00
|
|
|
$expected = '0644';
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::delete('masking_test', 'mask_test');
|
|
|
|
Cache::drop('mask_test');
|
|
|
|
|
|
|
|
Cache::config('mask_test', array('engine' => 'File', 'mask' => 0640, 'path' => TMP . 'tests'));
|
2014-02-11 21:38:24 +00:00
|
|
|
Cache::write('masking_test', $data, 'mask_test');
|
2013-08-07 23:03:21 +00:00
|
|
|
$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4);
|
2011-10-11 11:26:03 +00:00
|
|
|
$expected = '0640';
|
2011-12-13 04:35:31 +00:00
|
|
|
$this->assertEquals($expected, $result);
|
2011-10-11 11:26:03 +00:00
|
|
|
Cache::delete('masking_test', 'mask_test');
|
|
|
|
Cache::drop('mask_test');
|
|
|
|
}
|
2012-03-11 03:29:35 +00:00
|
|
|
|
2012-03-26 03:30:28 +00:00
|
|
|
/**
|
|
|
|
* Tests that configuring groups for stored keys return the correct values when read/written
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupsReadWrite() {
|
|
|
|
Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b')));
|
|
|
|
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
|
|
|
$this->assertEquals('value', Cache::read('test_groups', 'file_groups'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('test_groups2', 'value2', 'file_groups'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups3', 'value3', 'file_groups'));
|
|
|
|
}
|
|
|
|
|
2013-04-26 06:07:44 +00:00
|
|
|
/**
|
|
|
|
* Test that clearing with repeat writes works properly
|
2014-04-02 01:02:37 +00:00
|
|
|
*
|
|
|
|
* @return void
|
2013-04-26 06:07:44 +00:00
|
|
|
*/
|
|
|
|
public function testClearingWithRepeatWrites() {
|
|
|
|
Cache::config('repeat', array(
|
|
|
|
'engine' => 'File', 'groups' => array('users')
|
|
|
|
));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('user', 'rchavik', 'repeat'));
|
|
|
|
$this->assertEquals('rchavik', Cache::read('user', 'repeat'));
|
|
|
|
|
|
|
|
Cache::delete('user', 'repeat');
|
|
|
|
$this->assertEquals(false, Cache::read('user', 'repeat'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('user', 'ADmad', 'repeat'));
|
|
|
|
$this->assertEquals('ADmad', Cache::read('user', 'repeat'));
|
|
|
|
|
|
|
|
Cache::clearGroup('users', 'repeat');
|
|
|
|
$this->assertEquals(false, Cache::read('user', 'repeat'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('user', 'markstory', 'repeat'));
|
|
|
|
$this->assertEquals('markstory', Cache::read('user', 'repeat'));
|
|
|
|
|
|
|
|
Cache::drop('repeat');
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:27:27 +00:00
|
|
|
/**
|
2013-02-11 21:21:50 +00:00
|
|
|
* Tests that deleting from a groups-enabled config is possible
|
2012-03-26 03:30:28 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupDelete() {
|
2013-06-09 02:41:46 +00:00
|
|
|
Cache::config('file_groups', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'duration' => 3600,
|
|
|
|
'groups' => array('group_a', 'group_b')
|
|
|
|
));
|
2012-03-26 03:30:28 +00:00
|
|
|
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
|
|
|
$this->assertEquals('value', Cache::read('test_groups', 'file_groups'));
|
|
|
|
$this->assertTrue(Cache::delete('test_groups', 'file_groups'));
|
|
|
|
|
|
|
|
$this->assertFalse(Cache::read('test_groups', 'file_groups'));
|
|
|
|
}
|
|
|
|
|
2012-03-26 04:03:37 +00:00
|
|
|
/**
|
|
|
|
* Test clearing a cache group
|
|
|
|
*
|
|
|
|
* @return void
|
2013-01-11 14:06:54 +00:00
|
|
|
*/
|
2012-03-26 04:03:37 +00:00
|
|
|
public function testGroupClear() {
|
|
|
|
Cache::config('file_groups', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a', 'group_b')));
|
|
|
|
Cache::config('file_groups2', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_b')));
|
2013-06-09 02:41:46 +00:00
|
|
|
Cache::config('file_groups3', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'duration' => 3600,
|
|
|
|
'groups' => array('group_b'),
|
|
|
|
'prefix' => 'leading_',
|
|
|
|
));
|
2012-03-26 04:03:37 +00:00
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
2013-06-09 02:41:46 +00:00
|
|
|
$this->assertTrue(Cache::write('test_groups2', 'value 2', 'file_groups2'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups3', 'value 3', 'file_groups3'));
|
2012-03-26 04:03:37 +00:00
|
|
|
|
2013-06-09 02:41:46 +00:00
|
|
|
$this->assertTrue(Cache::clearGroup('group_b', 'file_groups'));
|
2012-03-26 04:03:37 +00:00
|
|
|
$this->assertFalse(Cache::read('test_groups', 'file_groups'));
|
2013-06-09 02:41:46 +00:00
|
|
|
$this->assertFalse(Cache::read('test_groups2', 'file_groups2'));
|
|
|
|
$this->assertEquals('value 3', Cache::read('test_groups3', 'file_groups3'));
|
2012-03-26 04:03:37 +00:00
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('test_groups4', 'value', 'file_groups'));
|
2013-06-09 02:41:46 +00:00
|
|
|
$this->assertTrue(Cache::write('test_groups5', 'value 2', 'file_groups2'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups6', 'value 3', 'file_groups3'));
|
2012-03-26 04:03:37 +00:00
|
|
|
|
|
|
|
$this->assertTrue(Cache::clearGroup('group_b', 'file_groups'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups4', 'file_groups'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups5', 'file_groups2'));
|
2013-06-09 02:41:46 +00:00
|
|
|
$this->assertEquals('value 3', Cache::read('test_groups6', 'file_groups3'));
|
2012-03-26 04:03:37 +00:00
|
|
|
}
|
2013-09-10 02:24:18 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that clearGroup works with no prefix.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupClearNoPrefix() {
|
|
|
|
Cache::config('file_groups', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'duration' => 3600,
|
|
|
|
'prefix' => '',
|
|
|
|
'groups' => array('group_a', 'group_b')
|
|
|
|
));
|
|
|
|
Cache::write('key_1', 'value', 'file_groups');
|
|
|
|
Cache::write('key_2', 'value', 'file_groups');
|
|
|
|
Cache::clearGroup('group_a', 'file_groups');
|
|
|
|
$this->assertFalse(Cache::read('key_1', 'file_groups'), 'Did not delete');
|
|
|
|
$this->assertFalse(Cache::read('key_2', 'file_groups'), 'Did not delete');
|
|
|
|
}
|
|
|
|
|
2015-07-27 21:42:00 +00:00
|
|
|
/**
|
2015-08-10 10:06:19 +00:00
|
|
|
* Test add method.
|
2015-07-27 21:42:00 +00:00
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAdd() {
|
|
|
|
Cache::delete('test_add_key', 'file_test');
|
|
|
|
|
|
|
|
$result = Cache::add('test_add_key', 'test data', 'file_test');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$expected = 'test data';
|
|
|
|
$result = Cache::read('test_add_key', 'file_test');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Cache::add('test_add_key', 'test data 2', 'file_test');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|