mirror of
				https://github.com/brmlab/brmsklad.git
				synced 2025-10-31 08:13:58 +01:00 
			
		
		
		
	Upgrade CakePHP from 2.2.5 to 2.9.5
This commit is contained in:
		
							parent
							
								
									5a580df460
								
							
						
					
					
						commit
						235a541597
					
				
					 793 changed files with 60746 additions and 23753 deletions
				
			
		|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * ApcEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 1.2.0.5434 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
|  | @ -26,6 +25,13 @@ App::uses('Cache', 'Cache'); | |||
|  */ | ||||
| class ApcEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * APC extension to be used | ||||
|  * | ||||
|  * @var string | ||||
|  */ | ||||
| 	protected $_apcExtension = 'apc'; | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  | @ -33,7 +39,16 @@ class ApcEngineTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.'); | ||||
| 		$hasApc = extension_loaded('apc') || extension_loaded('apcu'); | ||||
| 		$this->skipIf(!$hasApc, 'Apc is not installed or configured properly.'); | ||||
| 
 | ||||
| 		if (PHP_SAPI === 'cli') { | ||||
| 			$this->skipIf(!ini_get('apc.enable_cli'), 'APC is not enabled for the CLI.'); | ||||
| 		} | ||||
| 
 | ||||
| 		if (extension_loaded('apcu')) { | ||||
| 			$this->_apcExtension = 'apcu'; | ||||
| 		} | ||||
| 
 | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
|  | @ -144,7 +159,8 @@ class ApcEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement().'); | ||||
| 		$hasSupport = function_exists('apc_dec') || function_exists('apcu_dec'); | ||||
| 		$this->skipIf(!$hasSupport, 'No apc_dec()/apcu_dec() function, cannot test decrement().'); | ||||
| 
 | ||||
| 		$result = Cache::write('test_decrement', 5, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
|  | @ -168,7 +184,8 @@ class ApcEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().'); | ||||
| 		$hasSupport = function_exists('apc_inc') || function_exists('apcu_inc'); | ||||
| 		$this->skipIf(!function_exists('apc_inc'), 'No apc_inc()/apcu_inc() function, cannot test increment().'); | ||||
| 
 | ||||
| 		$result = Cache::write('test_increment', 5, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
|  | @ -192,14 +209,18 @@ class ApcEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		apc_store('not_cake', 'survive'); | ||||
| 		$storeFunc = $this->_apcExtension . '_store'; | ||||
| 		$fetchFunc = $this->_apcExtension . '_fetch'; | ||||
| 		$deleteFunc = $this->_apcExtension . '_delete'; | ||||
| 
 | ||||
| 		$storeFunc('not_cake', 'survive'); | ||||
| 		Cache::write('some_value', 'value', 'apc'); | ||||
| 
 | ||||
| 		$result = Cache::clear(false, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(Cache::read('some_value', 'apc')); | ||||
| 		$this->assertEquals('survive', apc_fetch('not_cake')); | ||||
| 		apc_delete('not_cake'); | ||||
| 		$this->assertEquals('survive', $fetchFunc('not_cake')); | ||||
| 		$deleteFunc('not_cake'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -210,6 +231,7 @@ class ApcEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupsReadWrite() { | ||||
| 		$incFunc = $this->_apcExtension . '_inc'; | ||||
| 		Cache::config('apc_groups', array( | ||||
| 			'engine' => 'Apc', | ||||
| 			'duration' => 0, | ||||
|  | @ -219,12 +241,12 @@ class ApcEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'apc_groups')); | ||||
| 
 | ||||
| 		apc_inc('test_group_a'); | ||||
| 		$incFunc('test_group_a'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'apc_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'apc_groups')); | ||||
| 
 | ||||
| 		apc_inc('test_group_b'); | ||||
| 		$incFunc('test_group_b'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'apc_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'apc_groups')); | ||||
|  | @ -253,7 +275,7 @@ class ApcEngineTest extends CakeTestCase { | |||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('apc_groups', array( | ||||
| 			'engine' => 'Apc', | ||||
|  | @ -270,4 +292,23 @@ class ApcEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'apc_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test add method. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::delete('test_add_key', 'apc'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'apc'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'apc'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * FileEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 1.2.0.5434 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
|  | @ -51,7 +50,7 @@ class FileEngineTest extends CakeTestCase { | |||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Cache::clear(false, 'file_test'); | ||||
| 		// Cache::clear(false, 'file_test');
 | ||||
| 		Cache::drop('file_test'); | ||||
| 		Cache::drop('file_groups'); | ||||
| 		Cache::drop('file_groups2'); | ||||
|  | @ -181,7 +180,7 @@ class FileEngineTest extends CakeTestCase { | |||
| 
 | ||||
| 		$newread = Cache::read('serialize_test', 'file_test'); | ||||
| 
 | ||||
| 		$delete = Cache::delete('serialize_test', 'file_test'); | ||||
| 		Cache::delete('serialize_test', 'file_test'); | ||||
| 
 | ||||
| 		$this->assertSame($read, serialize($data)); | ||||
| 
 | ||||
|  | @ -197,9 +196,9 @@ class FileEngineTest extends CakeTestCase { | |||
| 		Cache::config('file_test', array('engine' => 'File', 'duration' => 1)); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$write = Cache::write('serialize_test1', $data, 'file_test'); | ||||
| 		$write = Cache::write('serialize_test2', $data, 'file_test'); | ||||
| 		$write = Cache::write('serialize_test3', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test1', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test2', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test3', $data, 'file_test'); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1')); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2')); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3')); | ||||
|  | @ -211,9 +210,9 @@ class FileEngineTest extends CakeTestCase { | |||
| 		$this->assertFalse(file_exists(CACHE . 'cake_serialize_test3')); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$write = Cache::write('serialize_test1', $data, 'file_test'); | ||||
| 		$write = Cache::write('serialize_test2', $data, 'file_test'); | ||||
| 		$write = Cache::write('serialize_test3', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test1', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test2', $data, 'file_test'); | ||||
| 		Cache::write('serialize_test3', $data, 'file_test'); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test1')); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test2')); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_serialize_test3')); | ||||
|  | @ -254,6 +253,41 @@ class FileEngineTest extends CakeTestCase { | |||
| 		$FileTwo->clear(false); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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, | ||||
| 			'groups' => array('short', 'round') | ||||
| 		)); | ||||
| 		$key = 'cake_test_test_key'; | ||||
| 		$engine->write($key, 'it works', DAY); | ||||
| 		$engine->clear(false); | ||||
| 		$this->assertFalse($engine->read($key), 'Key should have been removed'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testKeyPath method | ||||
|  * | ||||
|  | @ -269,6 +303,14 @@ class FileEngineTest extends CakeTestCase { | |||
| 
 | ||||
| 		$result = Cache::clear(false, 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -337,20 +379,19 @@ class FileEngineTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * check that FileEngine generates an error when a configured Path does not exist. | ||||
|  * check that FileEngine does not generate an error when a configured Path does not exist in debug mode. | ||||
|  * | ||||
|  * @expectedException PHPUnit_Framework_Error_Warning | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testErrorWhenPathDoesNotExist() { | ||||
| 		$this->skipIf(is_dir(TMP . 'tests' . DS . 'file_failure'), 'Cannot run test directory exists.'); | ||||
| 	public function testPathDoesNotExist() { | ||||
| 		$this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.'); | ||||
| 
 | ||||
| 		Cache::config('failure', array( | ||||
| 		Cache::config('autocreate', array( | ||||
| 			'engine' => 'File', | ||||
| 			'path' => TMP . 'tests' . DS . 'file_failure' | ||||
| 			'path' => TMP . 'tests' . DS . 'autocreate' | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::drop('failure'); | ||||
| 		Cache::drop('autocreate'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  | @ -365,31 +406,31 @@ class FileEngineTest extends CakeTestCase { | |||
| 		Cache::config('mask_test', array('engine' => 'File', 'path' => TMP . 'tests')); | ||||
| 		$data = 'This is some test content'; | ||||
| 		$write = Cache::write('masking_test', $data, 'mask_test'); | ||||
| 		$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		$expected = '0664'; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 		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'); | ||||
| 		$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		Cache::write('masking_test', $data, 'mask_test'); | ||||
| 		$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		$expected = '0666'; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 		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'); | ||||
| 		$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		Cache::write('masking_test', $data, 'mask_test'); | ||||
| 		$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		$expected = '0644'; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 		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'); | ||||
| 		$result = substr(sprintf('%o',fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		Cache::write('masking_test', $data, 'mask_test'); | ||||
| 		$result = substr(sprintf('%o', fileperms(TMP . 'tests' . DS . 'cake_masking_test')), -4); | ||||
| 		$expected = '0640'; | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 		Cache::delete('masking_test', 'mask_test'); | ||||
|  | @ -411,12 +452,44 @@ class FileEngineTest extends CakeTestCase { | |||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * Test that clearing with repeat writes works properly | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	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'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleting 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'))); | ||||
| 		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')); | ||||
|  | @ -428,28 +501,71 @@ class FileEngineTest extends CakeTestCase { | |||
|  * 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'))); | ||||
| 		Cache::config('file_groups3', array( | ||||
| 			'engine' => 'File', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_b'), | ||||
| 			'prefix' => 'leading_', | ||||
| 		)); | ||||
| 
 | ||||
| 		$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::write('test_groups2', 'value 2', 'file_groups2')); | ||||
| 		$this->assertTrue(Cache::write('test_groups3', 'value 3', 'file_groups3')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'file_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', '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->assertFalse(Cache::read('test_groups2', 'file_groups2')); | ||||
| 		$this->assertEquals('value 3', 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::write('test_groups5', 'value 2', 'file_groups2')); | ||||
| 		$this->assertTrue(Cache::write('test_groups6', 'value 3', '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')); | ||||
| 		$this->assertEquals('value 3', Cache::read('test_groups6', 'file_groups3')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test add method. | ||||
|  * | ||||
|  * @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); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,24 +2,28 @@ | |||
| /** | ||||
|  * MemcacheEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 1.2.0.5434 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| App::uses('MemcacheEngine', 'Cache/Engine'); | ||||
| 
 | ||||
| /** | ||||
|  * TestMemcacheEngine | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class TestMemcacheEngine extends MemcacheEngine { | ||||
| 
 | ||||
| /** | ||||
|  | @ -93,7 +97,6 @@ class MemcacheEngineTest extends CakeTestCase { | |||
| 			'persistent' => true, | ||||
| 			'compress' => false, | ||||
| 			'engine' => 'Memcache', | ||||
| 			'persistent' => true, | ||||
| 			'groups' => array() | ||||
| 		); | ||||
| 		$this->assertEquals($expecting, $settings); | ||||
|  | @ -158,6 +161,17 @@ class MemcacheEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test domain starts with u | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringWithU() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$result = $Memcached->parseServerString('udomain.net:13211'); | ||||
| 		$this->assertEquals(array('udomain.net', '13211'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test non latin domains. | ||||
|  * | ||||
|  | @ -460,7 +474,7 @@ class MemcacheEngineTest extends CakeTestCase { | |||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('memcache_groups', array( | ||||
| 			'engine' => 'Memcache', | ||||
|  | @ -476,4 +490,23 @@ class MemcacheEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'memcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that failed add write return false. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::delete('test_add_key', 'memcache'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'memcache'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'memcache'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
							
								
								
									
										827
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										827
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,827 @@ | |||
| <?php | ||||
| /** | ||||
|  * MemcachedEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 2.5.0 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| App::uses('MemcachedEngine', 'Cache/Engine'); | ||||
| 
 | ||||
| /** | ||||
|  * TestMemcachedEngine | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class TestMemcachedEngine extends MemcachedEngine { | ||||
| 
 | ||||
| /** | ||||
|  * public accessor to _parseServerString | ||||
|  * | ||||
|  * @param string $server | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function parseServerString($server) { | ||||
| 		return $this->_parseServerString($server); | ||||
| 	} | ||||
| 
 | ||||
| 	public function setMemcached($memcached) { | ||||
| 		$this->_Memcached = $memcached; | ||||
| 	} | ||||
| 
 | ||||
| 	public function getMemcached() { | ||||
| 		return $this->_Memcached; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * MemcachedEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class MemcachedEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!class_exists('Memcached'), 'Memcached is not installed or configured properly.'); | ||||
| 
 | ||||
| 		// @codingStandardsIgnoreStart
 | ||||
| 		$socket = @fsockopen('127.0.0.1', 11211, $errno, $errstr, 1); | ||||
| 		// @codingStandardsIgnoreEnd
 | ||||
| 		$this->skipIf(!$socket, 'Memcached is not running.'); | ||||
| 		fclose($socket); | ||||
| 
 | ||||
| 		Cache::config('memcached', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Cache::drop('memcached'); | ||||
| 		Cache::drop('memcached_groups'); | ||||
| 		Cache::drop('memcached_helper'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSettings() { | ||||
| 		$settings = Cache::settings('memcached'); | ||||
| 		unset($settings['path']); | ||||
| 		$expecting = array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600, | ||||
| 			'probability' => 100, | ||||
| 			'servers' => array('127.0.0.1'), | ||||
| 			'persistent' => false, | ||||
| 			'compress' => false, | ||||
| 			'engine' => 'Memcached', | ||||
| 			'login' => null, | ||||
| 			'password' => null, | ||||
| 			'groups' => array(), | ||||
| 			'serialize' => 'php', | ||||
| 			'options' => array() | ||||
| 		); | ||||
| 		$this->assertEquals($expecting, $settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testCompressionSetting method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCompressionSetting() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$Memcached->init(array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'compress' => false | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertFalse($Memcached->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); | ||||
| 
 | ||||
| 		$MemcachedCompressed = new TestMemcachedEngine(); | ||||
| 		$MemcachedCompressed->init(array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'compress' => true | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue($MemcachedCompressed->getMemcached()->getOption(Memcached::OPT_COMPRESSION)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test setting options | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testOptionsSetting() { | ||||
| 		$memcached = new TestMemcachedEngine(); | ||||
| 		$memcached->init(array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'options' => array( | ||||
| 				Memcached::OPT_BINARY_PROTOCOL => true | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertEquals(1, $memcached->getMemcached()->getOption(Memcached::OPT_BINARY_PROTOCOL)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test accepts only valid serializer engine | ||||
|  * | ||||
|  * @return  void | ||||
|  */ | ||||
| 	public function testInvalidSerializerSetting() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'invalid_serializer' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException( | ||||
| 			'CacheException', 'invalid_serializer is not a valid serializer engine for Memcached' | ||||
| 		); | ||||
| 		$Memcached->init($settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testPhpSerializerSetting method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testPhpSerializerSetting() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'php' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached->init($settings); | ||||
| 		$this->assertEquals(Memcached::SERIALIZER_PHP, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testJsonSerializerSetting method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testJsonSerializerSetting() { | ||||
| 		$this->skipIf( | ||||
| 			!Memcached::HAVE_JSON, | ||||
| 			'Memcached extension is not compiled with json support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'json' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached->init($settings); | ||||
| 		$this->assertEquals(Memcached::SERIALIZER_JSON, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIgbinarySerializerSetting method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIgbinarySerializerSetting() { | ||||
| 		$this->skipIf( | ||||
| 			!Memcached::HAVE_IGBINARY, | ||||
| 			'Memcached extension is not compiled with igbinary support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'igbinary' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached->init($settings); | ||||
| 		$this->assertEquals(Memcached::SERIALIZER_IGBINARY, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMsgpackSerializerSetting method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMsgpackSerializerSetting() { | ||||
| 		$this->skipIf( | ||||
| 			!defined('Memcached::HAVE_MSGPACK') || !Memcached::HAVE_MSGPACK, | ||||
| 			'Memcached extension is not compiled with msgpack support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'msgpack' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached->init($settings); | ||||
| 		$this->assertEquals(Memcached::SERIALIZER_MSGPACK, $Memcached->getMemcached()->getOption(Memcached::OPT_SERIALIZER)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testJsonSerializerThrowException method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testJsonSerializerThrowException() { | ||||
| 		$this->skipIf( | ||||
| 			Memcached::HAVE_JSON, | ||||
| 			'Memcached extension is compiled with json support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'json' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException( | ||||
| 			'CacheException', 'Memcached extension is not compiled with json support' | ||||
| 		); | ||||
| 		$Memcached->init($settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMsgpackSerializerThrowException method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMsgpackSerializerThrowException() { | ||||
| 		$this->skipIf( | ||||
| 			defined('Memcached::HAVE_MSGPACK') && Memcached::HAVE_MSGPACK, | ||||
| 			'Memcached extension is compiled with msgpack support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'msgpack' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException( | ||||
| 			'CacheException', 'msgpack is not a valid serializer engine for Memcached' | ||||
| 		); | ||||
| 		$Memcached->init($settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIgbinarySerializerThrowException method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIgbinarySerializerThrowException() { | ||||
| 		$this->skipIf( | ||||
| 			Memcached::HAVE_IGBINARY, | ||||
| 			'Memcached extension is compiled with igbinary support' | ||||
| 		); | ||||
| 
 | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'serialize' => 'igbinary' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException( | ||||
| 			'CacheException', 'Memcached extension is not compiled with igbinary support' | ||||
| 		); | ||||
| 		$Memcached->init($settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test using authentication without memcached installed with SASL support | ||||
|  * throw an exception | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSaslAuthException() { | ||||
| 		$this->skipIf(version_compare(PHP_VERSION, '7.0.0', '>=')); | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'login' => 'test', | ||||
| 			'password' => 'password' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException('PHPUnit_Framework_Error_Warning'); | ||||
| 		$Memcached->init($settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMultipleServers() { | ||||
| 		$servers = array('127.0.0.1:11211', '127.0.0.1:11222'); | ||||
| 		$available = true; | ||||
| 		$Memcached = new Memcached(); | ||||
| 
 | ||||
| 		foreach ($servers as $server) { | ||||
| 			list($host, $port) = explode(':', $server); | ||||
| 			//@codingStandardsIgnoreStart
 | ||||
| 			if (!$Memcached->addServer($host, $port)) { | ||||
| 				$available = false; | ||||
| 			} | ||||
| 			//@codingStandardsIgnoreEnd
 | ||||
| 		} | ||||
| 
 | ||||
| 		$this->skipIf(!$available, 'Need memcached servers at ' . implode(', ', $servers) . ' to run this test.'); | ||||
| 
 | ||||
| 		$Memcached = new MemcachedEngine(); | ||||
| 		$Memcached->init(array('engine' => 'Memcached', 'servers' => $servers)); | ||||
| 
 | ||||
| 		$settings = $Memcached->settings(); | ||||
| 		$this->assertEquals($settings['servers'], $servers); | ||||
| 		Cache::drop('dual_server'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test connecting to an ipv6 server. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectIpv6() { | ||||
| 		$Memcached = new MemcachedEngine(); | ||||
| 		$result = $Memcached->init(array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 200, | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array( | ||||
| 				'[::1]:11211' | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test domain starts with u | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringWithU() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$result = $Memcached->parseServerString('udomain.net:13211'); | ||||
| 		$this->assertEquals(array('udomain.net', '13211'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test non latin domains. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringNonLatin() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$result = $Memcached->parseServerString('schülervz.net:13211'); | ||||
| 		$this->assertEquals(array('schülervz.net', '13211'), $result); | ||||
| 
 | ||||
| 		$result = $Memcached->parseServerString('sülül:1111'); | ||||
| 		$this->assertEquals(array('sülül', '1111'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test unix sockets. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringUnix() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$result = $Memcached->parseServerString('unix:///path/to/memcachedd.sock'); | ||||
| 		$this->assertEquals(array('/path/to/memcachedd.sock', 0), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1), null, 'memcached'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcached'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcached'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test', 'memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'memcached'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcached'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'memcached'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => "+1 second"), 'memcached'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(3); | ||||
| 		$result = Cache::read('other_test', 'memcached'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('memcached', array('duration' => '+1 second')); | ||||
| 
 | ||||
| 		$result = Cache::read('other_test', 'memcached'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('memcached', array('duration' => '+29 days')); | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('long_expiry_test', $data, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('long_expiry_test', 'memcached'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::config('memcached', array('duration' => 3600)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDeleteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDeleteCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('delete_test', $data, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$result = Cache::write('test_decrement', 5, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'memcached'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'memcached'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'memcached'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'memcached'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		Cache::delete('test_decrement', 'memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test decrementing compressed keys | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrementCompressedKeys() { | ||||
| 		Cache::config('compressed_memcached', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => '+2 seconds', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'compress' => true | ||||
| 		)); | ||||
| 
 | ||||
| 		$result = Cache::write('test_decrement', 5, 'compressed_memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'compressed_memcached'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'compressed_memcached'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'compressed_memcached'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'compressed_memcached'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		Cache::delete('test_decrement', 'compressed_memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$result = Cache::write('test_increment', 5, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 1, 'memcached'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'memcached'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'memcached'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'memcached'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		Cache::delete('test_increment', 'memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test incrementing compressed keys | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrementCompressedKeys() { | ||||
| 		Cache::config('compressed_memcached', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => '+2 seconds', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'compress' => true | ||||
| 		)); | ||||
| 
 | ||||
| 		$result = Cache::write('test_increment', 5, 'compressed_memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 1, 'compressed_memcached'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'compressed_memcached'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'compressed_memcached'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'compressed_memcached'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		Cache::delete('test_increment', 'compressed_memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that configurations don't conflict, when a file engine is declared after a memcached one. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConfigurationConflict() { | ||||
| 		Cache::config('long_memcached', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => '+2 seconds', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 		)); | ||||
| 		Cache::config('short_memcached', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => '+1 seconds', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 		)); | ||||
| 		Cache::config('some_file', array('engine' => 'File')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('duration_test', 'yay', 'long_memcached')); | ||||
| 		$this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcached')); | ||||
| 
 | ||||
| 		$this->assertEquals('yay', Cache::read('duration_test', 'long_memcached'), 'Value was not read %s'); | ||||
| 		$this->assertEquals('boo', Cache::read('short_duration_test', 'short_memcached'), 'Value was not read %s'); | ||||
| 
 | ||||
| 		sleep(1); | ||||
| 		$this->assertEquals('yay', Cache::read('duration_test', 'long_memcached'), 'Value was not read %s'); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$this->assertFalse(Cache::read('short_duration_test', 'short_memcached'), 'Cache was not invalidated %s'); | ||||
| 		$this->assertFalse(Cache::read('duration_test', 'long_memcached'), 'Value did not expire %s'); | ||||
| 
 | ||||
| 		Cache::delete('duration_test', 'long_memcached'); | ||||
| 		Cache::delete('short_duration_test', 'short_memcached'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test clearing memcached. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		Cache::config('memcached2', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'prefix' => 'cake2_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache1', 'memcached'); | ||||
| 		$result = Cache::clear(true, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertEquals('cache1', Cache::read('some_value', 'memcached')); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache2', 'memcached2'); | ||||
| 		$result = Cache::clear(false, 'memcached'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(Cache::read('some_value', 'memcached')); | ||||
| 		$this->assertEquals('cache2', Cache::read('some_value', 'memcached2')); | ||||
| 
 | ||||
| 		Cache::clear(false, 'memcached2'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that a 0 duration can successfully write. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testZeroDuration() { | ||||
| 		Cache::config('memcached', array('duration' => 0)); | ||||
| 		$result = Cache::write('test_key', 'written!', 'memcached'); | ||||
| 
 | ||||
| 		$this->assertTrue($result); | ||||
| 		$result = Cache::read('test_key', 'memcached'); | ||||
| 		$this->assertEquals('written!', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that durations greater than 30 days never expire | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testLongDurationEqualToZero() { | ||||
| 		$this->markTestSkipped('Cannot run as Memcached cannot be reflected'); | ||||
| 
 | ||||
| 		$memcached = new TestMemcachedEngine(); | ||||
| 		$memcached->settings['compress'] = false; | ||||
| 
 | ||||
| 		$mock = $this->getMock('Memcached'); | ||||
| 		$memcached->setMemcached($mock); | ||||
| 		$mock->expects($this->once()) | ||||
| 			->method('set') | ||||
| 			->with('key', 'value', 0); | ||||
| 
 | ||||
| 		$value = 'value'; | ||||
| 		$memcached->write('key', $value, 50 * DAY); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that configuring groups for stored keys return the correct values when read/written | ||||
|  * Shows that altering the group value is equivalent to deleting all keys under the same | ||||
|  * group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupReadWrite() { | ||||
| 		Cache::config('memcached_groups', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		Cache::config('memcached_helper', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => 3600, | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'memcached_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_a', 1, 'memcached_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcached_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'memcached_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'memcached_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_b', 1, 'memcached_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcached_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'memcached_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'memcached_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('memcached_groups', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'memcached_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'memcached_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcached_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('memcached_groups', array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcached_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'memcached_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcached_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'memcached_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'memcached_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcached_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test add method. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::set(array('duration' => 1), null, 'memcached'); | ||||
| 		Cache::delete('test_add_key', 'default'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'default'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'default'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'default'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * RedisEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/view/1196/Testing CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 2.2 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
|  | @ -25,7 +24,7 @@ App::uses('RedisEngine', 'Cache/Engine'); | |||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class RegisEngineTest extends CakeTestCase { | ||||
| class RedisEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  | @ -33,10 +32,18 @@ class RegisEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!class_exists('Redis'), 'Redis is not installed or configured properly.'); | ||||
| 
 | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 
 | ||||
| 		// @codingStandardsIgnoreStart
 | ||||
| 		$socket = @fsockopen('127.0.0.1', 6379, $errno, $errstr, 1); | ||||
| 		// @codingStandardsIgnoreEnd
 | ||||
| 		$this->skipIf(!$socket, 'Redis is not running.'); | ||||
| 		fclose($socket); | ||||
| 
 | ||||
| 		Cache::config('redis', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'prefix' => 'cake_', | ||||
|  | @ -50,6 +57,7 @@ class RegisEngineTest extends CakeTestCase { | |||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop(''); | ||||
| 		Cache::drop('redis_groups'); | ||||
|  | @ -73,7 +81,10 @@ class RegisEngineTest extends CakeTestCase { | |||
| 			'server' => '127.0.0.1', | ||||
| 			'port' => 6379, | ||||
| 			'timeout' => 0, | ||||
| 			'persistent' => true | ||||
| 			'persistent' => true, | ||||
| 			'password' => false, | ||||
| 			'database' => 0, | ||||
| 			'unix_socket' => false, | ||||
| 		); | ||||
| 		$this->assertEquals($expecting, $settings); | ||||
| 	} | ||||
|  | @ -88,6 +99,67 @@ class RegisEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue($Redis->init(Cache::settings('redis'))); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testMultiDatabaseOperations method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMultiDatabaseOperations() { | ||||
| 		Cache::config('redisdb0', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'prefix' => 'cake2_', | ||||
| 			'duration' => 3600, | ||||
| 			'persistent' => false, | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::config('redisdb1', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'database' => 1, | ||||
| 			'prefix' => 'cake2_', | ||||
| 			'duration' => 3600, | ||||
| 			'persistent' => false, | ||||
| 		)); | ||||
| 
 | ||||
| 		$result = Cache::write('save_in_0', true, 'redisdb0'); | ||||
| 		$exist = Cache::read('save_in_0', 'redisdb0'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue($exist); | ||||
| 
 | ||||
| 		$result = Cache::write('save_in_1', true, 'redisdb1'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$exist = Cache::read('save_in_0', 'redisdb1'); | ||||
| 		$this->assertFalse($exist); | ||||
| 		$exist = Cache::read('save_in_1', 'redisdb1'); | ||||
| 		$this->assertTrue($exist); | ||||
| 
 | ||||
| 		Cache::delete('save_in_0', 'redisdb0'); | ||||
| 		$exist = Cache::read('save_in_0', 'redisdb0'); | ||||
| 		$this->assertFalse($exist); | ||||
| 
 | ||||
| 		Cache::delete('save_in_1', 'redisdb1'); | ||||
| 		$exist = Cache::read('save_in_1', 'redisdb1'); | ||||
| 		$this->assertFalse($exist); | ||||
| 
 | ||||
| 		Cache::drop('redisdb0'); | ||||
| 		Cache::drop('redisdb1'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test write numbers method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testWriteNumbers() { | ||||
| 		$result = Cache::write('test-counter', 1, 'redis'); | ||||
| 		$this->assertSame(1, Cache::read('test-counter', 'redis')); | ||||
| 
 | ||||
| 		$result = Cache::write('test-counter', 0, 'redis'); | ||||
| 		$this->assertSame(0, Cache::read('test-counter', 'redis')); | ||||
| 
 | ||||
| 		$result = Cache::write('test-counter', -1, 'redis'); | ||||
| 		$this->assertSame(-1, Cache::read('test-counter', 'redis')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  | @ -315,7 +387,7 @@ class RegisEngineTest extends CakeTestCase { | |||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('redis_groups', array( | ||||
| 			'engine' => 'Redis', | ||||
|  | @ -332,4 +404,22 @@ class RegisEngineTest extends CakeTestCase { | |||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test add method. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::delete('test_add_key', 'redis'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'redis'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'redis'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * WincacheEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 1.2.0.5434 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
|  | @ -243,7 +242,7 @@ class WincacheEngineTest extends CakeTestCase { | |||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('wincache_groups', array( | ||||
| 			'engine' => 'Wincache', | ||||
|  | @ -260,4 +259,23 @@ class WincacheEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'wincache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that failed add write return false. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::delete('test_add_key', 'wincache'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'wincache'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'wincache'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
|  | @ -2,19 +2,18 @@ | |||
| /** | ||||
|  * XcacheEngineTest file | ||||
|  * | ||||
|  * PHP 5 | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/2.0/en/development/testing.html> | ||||
|  * Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * | ||||
|  * Licensed under The MIT License | ||||
|  * For full copyright and license information, please see the LICENSE.txt | ||||
|  * Redistributions of files must retain the above copyright notice | ||||
|  * | ||||
|  * @copyright     Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @copyright     Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org) | ||||
|  * @link          http://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 1.2.0.5434 | ||||
|  * @license       MIT License (http://www.opensource.org/licenses/mit-license.php) | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
|  | @ -252,7 +251,7 @@ class XcacheEngineTest extends CakeTestCase { | |||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  **/ | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('xcache_groups', array( | ||||
| 			'engine' => 'Xcache', | ||||
|  | @ -269,4 +268,24 @@ class XcacheEngineTest extends CakeTestCase { | |||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'xcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test that failed add write return false. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testAdd() { | ||||
| 		Cache::set(array('duration' => 1), null); | ||||
| 		Cache::delete('test_add_key', 'default'); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data', 'default'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$expected = 'test data'; | ||||
| 		$result = Cache::read('test_add_key', 'default'); | ||||
| 		$this->assertEquals($expected, $result); | ||||
| 
 | ||||
| 		$result = Cache::add('test_add_key', 'test data 2', 'default'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Brm Ko
						Brm Ko