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
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* PHP 5
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-04-27 02:49:18 +00:00
|
|
|
* CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html>
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2010-10-03 16:31:21 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2012-04-27 02:49:18 +00:00
|
|
|
* @link http://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
|
2010-10-03 16:27:27 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
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
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2011-03-12 17:06:10 +00:00
|
|
|
parent::tearDown();
|
|
|
|
Cache::clear(false, 'file_test');
|
|
|
|
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
|
|
|
|
2011-03-12 17:06:10 +00:00
|
|
|
$delete = 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';
|
2011-03-12 17:06:10 +00:00
|
|
|
$write = Cache::write('serialize_test1', $data, 'file_test');
|
|
|
|
$write = Cache::write('serialize_test2', $data, 'file_test');
|
|
|
|
$write = 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';
|
2011-03-12 17:06:10 +00:00
|
|
|
$write = Cache::write('serialize_test1', $data, 'file_test');
|
|
|
|
$write = Cache::write('serialize_test2', $data, 'file_test');
|
|
|
|
$write = 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
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
}
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* check that FileEngine generates an error when a configured Path does not exist.
|
|
|
|
*
|
2011-09-10 16:23:28 +00:00
|
|
|
* @expectedException PHPUnit_Framework_Error_Warning
|
2010-02-23 04:21:30 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testErrorWhenPathDoesNotExist() {
|
2011-05-31 00:49:46 +00:00
|
|
|
$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.');
|
|
|
|
|
2010-02-23 04:21:30 +00:00
|
|
|
Cache::config('failure', array(
|
|
|
|
'engine' => 'File',
|
|
|
|
'path' => TMP . 'tests' . DS . 'file_failure'
|
|
|
|
));
|
|
|
|
|
|
|
|
Cache::drop('failure');
|
|
|
|
}
|
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');
|
2012-03-11 03:29:35 +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'));
|
|
|
|
$write = Cache::write('masking_test', $data, 'mask_test');
|
2012-03-11 03:29:35 +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'));
|
|
|
|
$write = Cache::write('masking_test', $data, 'mask_test');
|
2012-03-11 03:29:35 +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'));
|
|
|
|
$write = Cache::write('masking_test', $data, 'mask_test');
|
2012-03-11 03:29:35 +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'));
|
|
|
|
}
|
|
|
|
|
2012-04-24 02:27:27 +00:00
|
|
|
/**
|
2012-03-26 03:30:28 +00:00
|
|
|
* Tests that deleteing from a groups-enabled config is possible
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testGroupDelete() {
|
|
|
|
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::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
|
|
|
|
**/
|
|
|
|
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')));
|
|
|
|
Cache::config('file_groups3', array('engine' => 'File', 'duration' => 3600, 'groups' => array('group_a')));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups2', 'value', 'file_groups2'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups3', 'value', 'file_groups3'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::clearGroup('group_a', 'file_groups'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups', 'file_groups'));
|
|
|
|
$this->assertEquals('value', Cache::read('test_groups2', 'file_groups2'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups3', 'file_groups3'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::write('test_groups4', 'value', 'file_groups'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups5', 'value', 'file_groups2'));
|
|
|
|
$this->assertTrue(Cache::write('test_groups6', 'value', 'file_groups3'));
|
|
|
|
|
|
|
|
$this->assertTrue(Cache::clearGroup('group_b', 'file_groups'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups4', 'file_groups'));
|
|
|
|
$this->assertFalse(Cache::read('test_groups5', 'file_groups2'));
|
|
|
|
$this->assertEquals('value', Cache::read('test_groups6', 'file_groups3'));
|
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|