mirror of
				https://github.com/brmlab/brmbiolab_sklad.git
				synced 2025-10-30 23:14:01 +01:00 
			
		
		
		
	Initial commit
This commit is contained in:
		
						commit
						3b93da31de
					
				
					 1004 changed files with 265840 additions and 0 deletions
				
			
		
							
								
								
									
										276
									
								
								lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										276
									
								
								lib/Cake/Test/Case/Cache/Engine/ApcEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,276 @@ | |||
| <?php | ||||
| /** | ||||
|  * ApcEngineTest file | ||||
|  * | ||||
|  * 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 1.2.0.5434 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| 
 | ||||
| /** | ||||
|  * ApcEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class ApcEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!function_exists('apc_store'), 'Apc is not installed or configured properly.'); | ||||
| 
 | ||||
| 		if (php_sapi_name() === 'cli') { | ||||
| 			$this->skipIf(!ini_get('apc.enable_cli'), 'APC is not enabled for the CLI.'); | ||||
| 		} | ||||
| 
 | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 		Cache::config('apc', array('engine' => 'Apc', 'prefix' => 'cake_')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop('apc'); | ||||
| 		Cache::drop('apc_groups'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1), 'apc'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'apc'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'apc'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test', 'apc'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Writing cache entries with duration = 0 (forever) should work. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadWriteDurationZero() { | ||||
| 		Cache::config('apc', array('engine' => 'Apc', 'duration' => 0, 'prefix' => 'cake_')); | ||||
| 		Cache::write('zero', 'Should save', 'apc'); | ||||
| 		sleep(1); | ||||
| 
 | ||||
| 		$result = Cache::read('zero', 'apc'); | ||||
| 		$this->assertEquals('Should save', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'apc'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'apc'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'apc'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => 1), 'apc'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'apc'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'apc'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDeleteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDeleteCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('delete_test', $data, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$this->skipIf(!function_exists('apc_dec'), 'No apc_dec() function, cannot test decrement().'); | ||||
| 
 | ||||
| 		$result = Cache::write('test_decrement', 5, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'apc'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'apc'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'apc'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'apc'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$this->skipIf(!function_exists('apc_inc'), 'No apc_inc() function, cannot test increment().'); | ||||
| 
 | ||||
| 		$result = Cache::write('test_increment', 5, 'apc'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 1, 'apc'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'apc'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'apc'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'apc'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test the clearing of cache keys | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		apc_store('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'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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 testGroupsReadWrite() { | ||||
| 		Cache::config('apc_groups', array( | ||||
| 			'engine' => 'Apc', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'apc_groups')); | ||||
| 
 | ||||
| 		apc_inc('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'); | ||||
| 		$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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('apc_groups', array( | ||||
| 			'engine' => 'Apc', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'apc_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'apc_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('apc_groups', array( | ||||
| 			'engine' => 'Apc', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'apc_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'apc_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'apc_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'apc_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'apc_groups')); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										553
									
								
								lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										553
									
								
								lib/Cake/Test/Case/Cache/Engine/FileEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,553 @@ | |||
| <?php | ||||
| /** | ||||
|  * FileEngineTest file | ||||
|  * | ||||
|  * 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 1.2.0.5434 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| 
 | ||||
| /** | ||||
|  * FileEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class FileEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * config property | ||||
|  * | ||||
|  * @var array | ||||
|  */ | ||||
| 	public $config = array(); | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 		Cache::config('file_test', array('engine' => 'File', 'path' => CACHE)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		// Cache::clear(false, 'file_test');
 | ||||
| 		Cache::drop('file_test'); | ||||
| 		Cache::drop('file_groups'); | ||||
| 		Cache::drop('file_groups2'); | ||||
| 		Cache::drop('file_groups3'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testCacheDirChange method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testCacheDirChange() { | ||||
| 		$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'sessions')); | ||||
| 		$this->assertEquals(Cache::settings('sessions'), $result['settings']); | ||||
| 
 | ||||
| 		$result = Cache::config('sessions', array('engine' => 'File', 'path' => TMP . 'tests')); | ||||
| 		$this->assertEquals(Cache::settings('sessions'), $result['settings']); | ||||
| 		$this->assertNotEquals(Cache::settings('default'), $result['settings']); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::config('default'); | ||||
| 
 | ||||
| 		$result = Cache::write(null, 'here', 'file_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => 1), 'file_test'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'file_test'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'file_test'); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_test')); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'file_test'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test', 'file_test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test read/write on the same cache key. Ensures file handles are re-wound. | ||||
|  * | ||||
|  * @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'); | ||||
| 		$resultB = Cache::read('rw', 'file_test'); | ||||
| 
 | ||||
| 		Cache::delete('rw', 'file_test'); | ||||
| 		$this->assertEquals('first write', $result); | ||||
| 		$this->assertEquals('second write', $resultB); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'file_test'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'file_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'file_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => "+1 second"), 'file_test'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'file_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDeleteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDeleteCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('delete_test', $data, 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(file_exists(TMP . 'tests' . DS . 'delete_test')); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'file_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSerialize method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSerialize() { | ||||
| 		Cache::config('file_test', array('engine' => 'File', 'serialize' => true)); | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$write = Cache::write('serialize_test', $data, 'file_test'); | ||||
| 		$this->assertTrue($write); | ||||
| 
 | ||||
| 		Cache::config('file_test', array('serialize' => false)); | ||||
| 		$read = Cache::read('serialize_test', 'file_test'); | ||||
| 
 | ||||
| 		$newread = Cache::read('serialize_test', 'file_test'); | ||||
| 
 | ||||
| 		Cache::delete('serialize_test', 'file_test'); | ||||
| 
 | ||||
| 		$this->assertSame($read, serialize($data)); | ||||
| 
 | ||||
| 		$this->assertSame(unserialize($newread), $data); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testClear method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		Cache::config('file_test', array('engine' => 'File', 'duration' => 1)); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		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')); | ||||
| 		sleep(2); | ||||
| 		$result = Cache::clear(true, 'file_test'); | ||||
| 		$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'; | ||||
| 		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')); | ||||
| 
 | ||||
| 		$result = Cache::clear(false, 'file_test'); | ||||
| 		$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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that clear() doesn't wipe files not in the current engine's prefix. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClearWithPrefixes() { | ||||
| 		$FileOne = new FileEngine(); | ||||
| 		$FileOne->init(array( | ||||
| 			'prefix' => 'prefix_one_', | ||||
| 			'duration' => DAY | ||||
| 		)); | ||||
| 		$FileTwo = new FileEngine(); | ||||
| 		$FileTwo->init(array( | ||||
| 			'prefix' => 'prefix_two_', | ||||
| 			'duration' => DAY | ||||
| 		)); | ||||
| 
 | ||||
| 		$dataOne = $dataTwo = $expected = 'content to cache'; | ||||
| 		$FileOne->write('prefix_one_key_one', $dataOne, DAY); | ||||
| 		$FileTwo->write('prefix_two_key_two', $dataTwo, DAY); | ||||
| 
 | ||||
| 		$this->assertEquals($expected, $FileOne->read('prefix_one_key_one')); | ||||
| 		$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two')); | ||||
| 
 | ||||
| 		$FileOne->clear(false); | ||||
| 		$this->assertEquals($expected, $FileTwo->read('prefix_two_key_two'), 'secondary config was cleared by accident.'); | ||||
| 		$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 | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testKeyPath() { | ||||
| 		$result = Cache::write('views.countries.something', 'here', 'file_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertTrue(file_exists(CACHE . 'cake_views_countries_something')); | ||||
| 
 | ||||
| 		$result = Cache::read('views.countries.something', 'file_test'); | ||||
| 		$this->assertEquals('here', $result); | ||||
| 
 | ||||
| 		$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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testRemoveWindowsSlashesFromCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testRemoveWindowsSlashesFromCache() { | ||||
| 		Cache::config('windows_test', array('engine' => 'File', 'isWindows' => true, 'prefix' => null, 'path' => TMP)); | ||||
| 
 | ||||
| 		$expected = array( | ||||
| 			'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'); | ||||
| 		$this->assertEquals($expected, $data); | ||||
| 
 | ||||
| 		Cache::drop('windows_test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testWriteQuotedString method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testWriteQuotedString() { | ||||
| 		Cache::config('file_test', array('engine' => 'File', 'path' => TMP . 'tests')); | ||||
| 		Cache::write('App.doubleQuoteTest', '"this is a quoted string"', 'file_test'); | ||||
| 		$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"'); | ||||
| 		Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test'); | ||||
| 		$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'"); | ||||
| 
 | ||||
| 		Cache::config('file_test', array('isWindows' => true, 'path' => TMP . 'tests')); | ||||
| 		$this->assertSame(Cache::read('App.doubleQuoteTest', 'file_test'), '"this is a quoted string"'); | ||||
| 		Cache::write('App.singleQuoteTest', "'this is a quoted string'", 'file_test'); | ||||
| 		$this->assertSame(Cache::read('App.singleQuoteTest', 'file_test'), "'this is a quoted string'"); | ||||
| 		Cache::delete('App.singleQuoteTest', 'file_test'); | ||||
| 		Cache::delete('App.doubleQuoteTest', 'file_test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * check that FileEngine does not generate an error when a configured Path does not exist in debug mode. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testPathDoesNotExist() { | ||||
| 		$this->skipIf(is_dir(TMP . 'tests' . DS . 'autocreate'), 'Cannot run if test directory exists.'); | ||||
| 
 | ||||
| 		Cache::config('autocreate', array( | ||||
| 			'engine' => 'File', | ||||
| 			'path' => TMP . 'tests' . DS . 'autocreate' | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::drop('autocreate'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Testing the mask setting in FileEngine | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMaskSetting() { | ||||
| 		if (DS === '\\') { | ||||
| 			$this->markTestSkipped('File permission testing does not work on Windows.'); | ||||
| 		} | ||||
| 		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); | ||||
| 		$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')); | ||||
| 		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')); | ||||
| 		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')); | ||||
| 		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'); | ||||
| 		Cache::drop('mask_test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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') | ||||
| 		)); | ||||
| 		$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')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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_b'), | ||||
| 			'prefix' => 'leading_', | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'file_groups')); | ||||
| 		$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_b', 'file_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'file_groups')); | ||||
| 		$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 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 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'); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										482
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										482
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,482 @@ | |||
| <?php | ||||
| /** | ||||
|  * MemcacheEngineTest file | ||||
|  * | ||||
|  * 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 1.2.0.5434 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| App::uses('MemcacheEngine', 'Cache/Engine'); | ||||
| 
 | ||||
| /** | ||||
|  * Class TestMemcacheEngine | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class TestMemcacheEngine extends MemcacheEngine { | ||||
| 
 | ||||
| /** | ||||
|  * public accessor to _parseServerString | ||||
|  * | ||||
|  * @param string $server | ||||
|  * @return array | ||||
|  */ | ||||
| 	public function parseServerString($server) { | ||||
| 		return $this->_parseServerString($server); | ||||
| 	} | ||||
| 
 | ||||
| 	public function setMemcache($memcache) { | ||||
| 		$this->_Memcache = $memcache; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * MemcacheEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class MemcacheEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!class_exists('Memcache'), 'Memcache is not installed or configured properly.'); | ||||
| 
 | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 		Cache::config('memcache', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop('memcache'); | ||||
| 		Cache::drop('memcache_groups'); | ||||
| 		Cache::drop('memcache_helper'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSettings() { | ||||
| 		$settings = Cache::settings('memcache'); | ||||
| 		unset($settings['serialize'], $settings['path']); | ||||
| 		$expecting = array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600, | ||||
| 			'probability' => 100, | ||||
| 			'servers' => array('127.0.0.1'), | ||||
| 			'persistent' => true, | ||||
| 			'compress' => false, | ||||
| 			'engine' => 'Memcache', | ||||
| 			'groups' => array() | ||||
| 		); | ||||
| 		$this->assertEquals($expecting, $settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testMultipleServers() { | ||||
| 		$servers = array('127.0.0.1:11211', '127.0.0.1:11222'); | ||||
| 		$available = true; | ||||
| 		$Memcache = new Memcache(); | ||||
| 
 | ||||
| 		foreach ($servers as $server) { | ||||
| 			list($host, $port) = explode(':', $server); | ||||
| 			//@codingStandardsIgnoreStart
 | ||||
| 			if (!@$Memcache->connect($host, $port)) { | ||||
| 				$available = false; | ||||
| 			} | ||||
| 			//@codingStandardsIgnoreEnd
 | ||||
| 		} | ||||
| 
 | ||||
| 		$this->skipIf(!$available, 'Need memcache servers at ' . implode(', ', $servers) . ' to run this test.'); | ||||
| 
 | ||||
| 		$Memcache = new MemcacheEngine(); | ||||
| 		$Memcache->init(array('engine' => 'Memcache', 'servers' => $servers)); | ||||
| 
 | ||||
| 		$settings = $Memcache->settings(); | ||||
| 		$this->assertEquals($settings['servers'], $servers); | ||||
| 		Cache::drop('dual_server'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnect method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnect() { | ||||
| 		$Memcache = new MemcacheEngine(); | ||||
| 		$Memcache->init(Cache::settings('memcache')); | ||||
| 		$result = $Memcache->connect('127.0.0.1'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test connecting to an ipv6 server. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnectIpv6() { | ||||
| 		$Memcache = new MemcacheEngine(); | ||||
| 		$result = $Memcache->init(array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 200, | ||||
| 			'engine' => 'Memcache', | ||||
| 			'servers' => array( | ||||
| 				'[::1]:11211' | ||||
| 			) | ||||
| 		)); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test non latin domains. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringNonLatin() { | ||||
| 		$Memcache = new TestMemcacheEngine(); | ||||
| 		$result = $Memcache->parseServerString('schülervz.net:13211'); | ||||
| 		$this->assertEquals(array('schülervz.net', '13211'), $result); | ||||
| 
 | ||||
| 		$result = $Memcache->parseServerString('sülül:1111'); | ||||
| 		$this->assertEquals(array('sülül', '1111'), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test unix sockets. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testParseServerStringUnix() { | ||||
| 		$Memcache = new TestMemcacheEngine(); | ||||
| 		$result = $Memcache->parseServerString('unix:///path/to/memcached.sock'); | ||||
| 		$this->assertEquals(array('unix:///path/to/memcached.sock', 0), $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1), null, 'memcache'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcache'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcache'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test', 'memcache'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'memcache'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'memcache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'memcache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => "+1 second"), 'memcache'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(3); | ||||
| 		$result = Cache::read('other_test', 'memcache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('memcache', array('duration' => '+1 second')); | ||||
| 
 | ||||
| 		$result = Cache::read('other_test', 'memcache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('memcache', array('duration' => '+29 days')); | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('long_expiry_test', $data, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('long_expiry_test', 'memcache'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::config('memcache', 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, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$result = Cache::write('test_decrement', 5, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'memcache'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'memcache'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'memcache'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'memcache'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$result = Cache::write('test_increment', 5, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 1, 'memcache'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'memcache'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'memcache'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'memcache'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that configurations don't conflict, when a file engine is declared after a memcache one. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConfigurationConflict() { | ||||
| 		Cache::config('long_memcache', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'duration' => '+2 seconds', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 		)); | ||||
| 		Cache::config('short_memcache', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'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_memcache')); | ||||
| 		$this->assertTrue(Cache::write('short_duration_test', 'boo', 'short_memcache')); | ||||
| 
 | ||||
| 		$this->assertEquals('yay', Cache::read('duration_test', 'long_memcache'), 'Value was not read %s'); | ||||
| 		$this->assertEquals('boo', Cache::read('short_duration_test', 'short_memcache'), 'Value was not read %s'); | ||||
| 
 | ||||
| 		sleep(1); | ||||
| 		$this->assertEquals('yay', Cache::read('duration_test', 'long_memcache'), 'Value was not read %s'); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$this->assertFalse(Cache::read('short_duration_test', 'short_memcache'), 'Cache was not invalidated %s'); | ||||
| 		$this->assertFalse(Cache::read('duration_test', 'long_memcache'), 'Value did not expire %s'); | ||||
| 
 | ||||
| 		Cache::delete('duration_test', 'long_memcache'); | ||||
| 		Cache::delete('short_duration_test', 'short_memcache'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test clearing memcache. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		Cache::config('memcache2', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'prefix' => 'cake2_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache1', 'memcache'); | ||||
| 		$result = Cache::clear(true, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertEquals('cache1', Cache::read('some_value', 'memcache')); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache2', 'memcache2'); | ||||
| 		$result = Cache::clear(false, 'memcache'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(Cache::read('some_value', 'memcache')); | ||||
| 		$this->assertEquals('cache2', Cache::read('some_value', 'memcache2')); | ||||
| 
 | ||||
| 		Cache::clear(false, 'memcache2'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that a 0 duration can successfully write. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testZeroDuration() { | ||||
| 		Cache::config('memcache', array('duration' => 0)); | ||||
| 		$result = Cache::write('test_key', 'written!', 'memcache'); | ||||
| 
 | ||||
| 		$this->assertTrue($result); | ||||
| 		$result = Cache::read('test_key', 'memcache'); | ||||
| 		$this->assertEquals('written!', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that durations greater than 30 days never expire | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testLongDurationEqualToZero() { | ||||
| 		$memcache = new TestMemcacheEngine(); | ||||
| 		$memcache->settings['compress'] = false; | ||||
| 
 | ||||
| 		$mock = $this->getMock('Memcache'); | ||||
| 		$memcache->setMemcache($mock); | ||||
| 		$mock->expects($this->once()) | ||||
| 			->method('set') | ||||
| 			->with('key', 'value', false, 0); | ||||
| 
 | ||||
| 		$value = 'value'; | ||||
| 		$memcache->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('memcache_groups', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		Cache::config('memcache_helper', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'duration' => 3600, | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_a', 1, 'memcache_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'memcache_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'memcache_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_b', 1, 'memcache_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'memcache_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'memcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('memcache_groups', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'memcache_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'memcache_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('memcache_groups', array( | ||||
| 			'engine' => 'Memcache', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'memcache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'memcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'memcache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'memcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'memcache_groups')); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										776
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										776
									
								
								lib/Cake/Test/Case/Cache/Engine/MemcachedEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,776 @@ | |||
| <?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'); | ||||
| 
 | ||||
| /** | ||||
|  * Class 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.'); | ||||
| 
 | ||||
| 		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' | ||||
| 		); | ||||
| 		$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 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() { | ||||
| 		$Memcached = new TestMemcachedEngine(); | ||||
| 		$settings = array( | ||||
| 			'engine' => 'Memcached', | ||||
| 			'servers' => array('127.0.0.1:11211'), | ||||
| 			'persistent' => false, | ||||
| 			'login' => 'test', | ||||
| 			'password' => 'password' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->skipIf( | ||||
| 			method_exists($Memcached->getMemcached(), 'setSaslAuthData'), | ||||
| 			'Memcached extension is installed with SASL support' | ||||
| 		); | ||||
| 
 | ||||
| 		$this->setExpectedException( | ||||
| 			'CacheException', 'Memcached extension is not build with SASL support' | ||||
| 		); | ||||
| 		$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 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('unix:///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() { | ||||
| 		$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')); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										383
									
								
								lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										383
									
								
								lib/Cake/Test/Case/Cache/Engine/RedisEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,383 @@ | |||
| <?php | ||||
| /** | ||||
|  * RedisEngineTest file | ||||
|  * | ||||
|  * CakePHP(tm) Tests <http://book.cakephp.org/view/1196/Testing> | ||||
|  * 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/view/1196/Testing CakePHP(tm) Tests | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  * @since         CakePHP(tm) v 2.2 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| App::uses('RedisEngine', 'Cache/Engine'); | ||||
| 
 | ||||
| /** | ||||
|  * RedisEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class RedisEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @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); | ||||
| 		Cache::config('redis', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop(''); | ||||
| 		Cache::drop('redis_groups'); | ||||
| 		Cache::drop('redis_helper'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSettings() { | ||||
| 		$settings = Cache::settings('redis'); | ||||
| 		$expecting = array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600, | ||||
| 			'probability' => 100, | ||||
| 			'groups' => array(), | ||||
| 			'engine' => 'Redis', | ||||
| 			'server' => '127.0.0.1', | ||||
| 			'port' => 6379, | ||||
| 			'timeout' => 0, | ||||
| 			'persistent' => true, | ||||
| 			'password' => false, | ||||
| 			'database' => 0, | ||||
| 		); | ||||
| 		$this->assertEquals($expecting, $settings); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testConnect method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testConnect() { | ||||
| 		$Redis = new RedisEngine(); | ||||
| 		$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'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1), null, 'redis'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'redis'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'redis'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = array(1, 2, 3); | ||||
| 		$this->assertTrue(Cache::write('array_data', $data, 'redis')); | ||||
| 		$this->assertEquals($data, Cache::read('array_data', 'redis')); | ||||
| 
 | ||||
| 		Cache::delete('test', 'redis'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'redis'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'redis'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'redis'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => "+1 second"), 'redis'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'redis'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('redis', array('duration' => '+1 second')); | ||||
| 		sleep(2); | ||||
| 
 | ||||
| 		$result = Cache::read('other_test', 'redis'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::config('redis', array('duration' => '+29 days')); | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('long_expiry_test', $data, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('long_expiry_test', 'redis'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::config('redis', 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, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		Cache::delete('test_decrement', 'redis'); | ||||
| 		$result = Cache::write('test_decrement', 5, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'redis'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'redis'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'redis'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'redis'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		Cache::delete('test_increment', 'redis'); | ||||
| 		$result = Cache::increment('test_increment', 1, 'redis'); | ||||
| 		$this->assertEquals(1, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'redis'); | ||||
| 		$this->assertEquals(1, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'redis'); | ||||
| 		$this->assertEquals(3, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'redis'); | ||||
| 		$this->assertEquals(3, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test clearing redis. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		Cache::config('redis2', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'prefix' => 'cake2_', | ||||
| 			'duration' => 3600 | ||||
| 		)); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache1', 'redis'); | ||||
| 		$result = Cache::clear(true, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertEquals('cache1', Cache::read('some_value', 'redis')); | ||||
| 
 | ||||
| 		Cache::write('some_value', 'cache2', 'redis2'); | ||||
| 		$result = Cache::clear(false, 'redis'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(Cache::read('some_value', 'redis')); | ||||
| 		$this->assertEquals('cache2', Cache::read('some_value', 'redis2')); | ||||
| 
 | ||||
| 		Cache::clear(false, 'redis2'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test that a 0 duration can successfully write. | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testZeroDuration() { | ||||
| 		Cache::config('redis', array('duration' => 0)); | ||||
| 		$result = Cache::write('test_key', 'written!', 'redis'); | ||||
| 
 | ||||
| 		$this->assertTrue($result); | ||||
| 		$result = Cache::read('test_key', 'redis'); | ||||
| 		$this->assertEquals('written!', $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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('redis_groups', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		Cache::config('redis_helper', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'duration' => 3600, | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'redis_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_a', 1, 'redis_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'redis_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'redis_groups')); | ||||
| 
 | ||||
| 		Cache::increment('group_b', 1, 'redis_helper'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'redis_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'redis_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('redis_groups', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'redis_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'redis_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('redis_groups', array( | ||||
| 			'engine' => 'Redis', | ||||
| 			'duration' => 3600, | ||||
| 			'groups' => array('group_a', 'group_b') | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'redis_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'redis_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'redis_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'redis_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'redis_groups')); | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
							
								
								
									
										262
									
								
								lib/Cake/Test/Case/Cache/Engine/WincacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										262
									
								
								lib/Cake/Test/Case/Cache/Engine/WincacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,262 @@ | |||
| <?php | ||||
| /** | ||||
|  * WincacheEngineTest file | ||||
|  * | ||||
|  * 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 1.2.0.5434 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| 
 | ||||
| /** | ||||
|  * WincacheEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class WincacheEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		$this->skipIf(!function_exists('wincache_ucache_set'), 'Wincache is not installed or configured properly.'); | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 		Cache::config('wincache', array('engine' => 'Wincache', 'prefix' => 'cake_')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop('wincache'); | ||||
| 		Cache::drop('wincache_groups'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1), 'wincache'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'wincache'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'wincache'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test', 'wincache'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1), 'wincache'); | ||||
| 
 | ||||
| 		$result = Cache::read('test', 'wincache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'wincache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => 1), 'wincache'); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'wincache'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test', 'wincache'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDeleteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDeleteCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('delete_test', $data, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test', 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$this->skipIf( | ||||
| 			!function_exists('wincache_ucache_dec'), | ||||
| 			'No wincache_ucache_dec() function, cannot test decrement().' | ||||
| 		); | ||||
| 
 | ||||
| 		$result = Cache::write('test_decrement', 5, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 1, 'wincache'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'wincache'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2, 'wincache'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement', 'wincache'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$this->skipIf( | ||||
| 			!function_exists('wincache_ucache_inc'), | ||||
| 			'No wincache_inc() function, cannot test increment().' | ||||
| 		); | ||||
| 
 | ||||
| 		$result = Cache::write('test_increment', 5, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 1, 'wincache'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'wincache'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2, 'wincache'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment', 'wincache'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * test the clearing of cache keys | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClear() { | ||||
| 		wincache_ucache_set('not_cake', 'safe'); | ||||
| 		Cache::write('some_value', 'value', 'wincache'); | ||||
| 
 | ||||
| 		$result = Cache::clear(false, 'wincache'); | ||||
| 		$this->assertTrue($result); | ||||
| 		$this->assertFalse(Cache::read('some_value', 'wincache')); | ||||
| 		$this->assertEquals('safe', wincache_ucache_get('not_cake')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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 testGroupsReadWrite() { | ||||
| 		Cache::config('wincache_groups', array( | ||||
| 			'engine' => 'Wincache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups')); | ||||
| 
 | ||||
| 		wincache_ucache_inc('test_group_a'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'wincache_groups')); | ||||
| 
 | ||||
| 		wincache_ucache_inc('test_group_b'); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'wincache_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'wincache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('wincache_groups', array( | ||||
| 			'engine' => 'Wincache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'wincache_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('wincache_groups', array( | ||||
| 			'engine' => 'Wincache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'wincache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'wincache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'wincache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'wincache_groups')); | ||||
| 	} | ||||
| } | ||||
							
								
								
									
										271
									
								
								lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										271
									
								
								lib/Cake/Test/Case/Cache/Engine/XcacheEngineTest.php
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,271 @@ | |||
| <?php | ||||
| /** | ||||
|  * XcacheEngineTest file | ||||
|  * | ||||
|  * 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 1.2.0.5434 | ||||
|  * @license       http://www.opensource.org/licenses/mit-license.php MIT License | ||||
|  */ | ||||
| 
 | ||||
| App::uses('Cache', 'Cache'); | ||||
| 
 | ||||
| /** | ||||
|  * XcacheEngineTest class | ||||
|  * | ||||
|  * @package       Cake.Test.Case.Cache.Engine | ||||
|  */ | ||||
| class XcacheEngineTest extends CakeTestCase { | ||||
| 
 | ||||
| /** | ||||
|  * setUp method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function setUp() { | ||||
| 		parent::setUp(); | ||||
| 		if (!function_exists('xcache_set')) { | ||||
| 			$this->markTestSkipped('Xcache is not installed or configured properly'); | ||||
| 		} | ||||
| 		$this->_cacheDisable = Configure::read('Cache.disable'); | ||||
| 		Configure::write('Cache.disable', false); | ||||
| 		Cache::config('xcache', array('engine' => 'Xcache', 'prefix' => 'cake_')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * tearDown method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function tearDown() { | ||||
| 		parent::tearDown(); | ||||
| 		Configure::write('Cache.disable', $this->_cacheDisable); | ||||
| 		Cache::drop('xcache'); | ||||
| 		Cache::drop('xcache_groups'); | ||||
| 		Cache::config('default'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testSettings method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testSettings() { | ||||
| 		$settings = Cache::settings(); | ||||
| 		$expecting = array( | ||||
| 			'prefix' => 'cake_', | ||||
| 			'duration' => 3600, | ||||
| 			'probability' => 100, | ||||
| 			'engine' => 'Xcache', | ||||
| 		); | ||||
| 		$this->assertTrue(isset($settings['PHP_AUTH_USER'])); | ||||
| 		$this->assertTrue(isset($settings['PHP_AUTH_PW'])); | ||||
| 
 | ||||
| 		unset($settings['PHP_AUTH_USER'], $settings['PHP_AUTH_PW']); | ||||
| 		$this->assertEquals($settings, $expecting); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testReadAndWriteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testReadAndWriteCache() { | ||||
| 		Cache::set(array('duration' => 1)); | ||||
| 
 | ||||
| 		$result = Cache::read('test'); | ||||
| 		$expecting = ''; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('test', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::read('test'); | ||||
| 		$expecting = $data; | ||||
| 		$this->assertEquals($expecting, $result); | ||||
| 
 | ||||
| 		Cache::delete('test'); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testExpiry method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testExpiry() { | ||||
| 		Cache::set(array('duration' => 1)); | ||||
| 		$result = Cache::read('test'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 
 | ||||
| 		Cache::set(array('duration' => "+1 second")); | ||||
| 
 | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('other_test', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		sleep(2); | ||||
| 		$result = Cache::read('other_test'); | ||||
| 		$this->assertFalse($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDeleteCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDeleteCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('delete_test', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::delete('delete_test'); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testClearCache method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testClearCache() { | ||||
| 		$data = 'this is a test of the emergency broadcasting system'; | ||||
| 		$result = Cache::write('clear_test_1', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::write('clear_test_2', $data); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::clear(); | ||||
| 		$this->assertTrue($result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testDecrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testDecrement() { | ||||
| 		$result = Cache::write('test_decrement', 5); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement'); | ||||
| 		$this->assertEquals(4, $result); | ||||
| 
 | ||||
| 		$result = Cache::decrement('test_decrement', 2); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_decrement'); | ||||
| 		$this->assertEquals(2, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * testIncrement method | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testIncrement() { | ||||
| 		$result = Cache::write('test_increment', 5); | ||||
| 		$this->assertTrue($result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment'); | ||||
| 		$this->assertEquals(6, $result); | ||||
| 
 | ||||
| 		$result = Cache::increment('test_increment', 2); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 
 | ||||
| 		$result = Cache::read('test_increment'); | ||||
| 		$this->assertEquals(8, $result); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * 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 testGroupsReadWrite() { | ||||
| 		Cache::config('xcache_groups', array( | ||||
| 			'engine' => 'Xcache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups')); | ||||
| 
 | ||||
| 		xcache_inc('test_group_a', 1); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups')); | ||||
| 		$this->assertEquals('value2', Cache::read('test_groups', 'xcache_groups')); | ||||
| 
 | ||||
| 		xcache_inc('test_group_b', 1); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value3', 'xcache_groups')); | ||||
| 		$this->assertEquals('value3', Cache::read('test_groups', 'xcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Tests that deleteing from a groups-enabled config is possible | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupDelete() { | ||||
| 		Cache::config('xcache_groups', array( | ||||
| 			'engine' => 'Xcache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups')); | ||||
| 		$this->assertEquals('value', Cache::read('test_groups', 'xcache_groups')); | ||||
| 		$this->assertTrue(Cache::delete('test_groups', 'xcache_groups')); | ||||
| 
 | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 	} | ||||
| 
 | ||||
| /** | ||||
|  * Test clearing a cache group | ||||
|  * | ||||
|  * @return void | ||||
|  */ | ||||
| 	public function testGroupClear() { | ||||
| 		Cache::config('xcache_groups', array( | ||||
| 			'engine' => 'Xcache', | ||||
| 			'duration' => 0, | ||||
| 			'groups' => array('group_a', 'group_b'), | ||||
| 			'prefix' => 'test_' | ||||
| 		)); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value', 'xcache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_a', 'xcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 
 | ||||
| 		$this->assertTrue(Cache::write('test_groups', 'value2', 'xcache_groups')); | ||||
| 		$this->assertTrue(Cache::clearGroup('group_b', 'xcache_groups')); | ||||
| 		$this->assertFalse(Cache::read('test_groups', 'xcache_groups')); | ||||
| 	} | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 mareksebera
						mareksebera