2011-06-21 23:01:47 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* WincacheEngineTest file
|
|
|
|
*
|
2017-06-10 22:15:34 +00:00
|
|
|
* CakePHP(tm) Tests <https://book.cakephp.org/2.0/en/development/testing.html>
|
2017-06-10 22:10:52 +00:00
|
|
|
* Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2011-06-21 23:01:47 +00:00
|
|
|
*
|
|
|
|
* Licensed under The MIT License
|
2013-02-08 12:22:51 +00:00
|
|
|
* For full copyright and license information, please see the LICENSE.txt
|
2011-06-21 23:01:47 +00:00
|
|
|
* Redistributions of files must retain the above copyright notice
|
|
|
|
*
|
2017-06-10 22:10:52 +00:00
|
|
|
* @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
|
2017-06-10 22:15:34 +00:00
|
|
|
* @link https://book.cakephp.org/2.0/en/development/testing.html CakePHP(tm) Tests
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Cache.Engine
|
2011-06-21 23:01:47 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5434
|
2017-06-10 22:23:14 +00:00
|
|
|
* @license https://opensource.org/licenses/mit-license.php MIT License
|
2011-06-21 23:01:47 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
App::uses('Cache', 'Cache');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WincacheEngineTest class
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Cache.Engine
|
2011-06-21 23:01:47 +00:00
|
|
|
*/
|
|
|
|
class WincacheEngineTest extends CakeTestCase {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* setUp method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function setUp() : void {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::setUp();
|
2011-06-21 23:01:47 +00:00
|
|
|
$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
|
|
|
|
*/
|
2022-12-28 07:03:39 +00:00
|
|
|
public function tearDown() : void {
|
2012-04-16 02:20:34 +00:00
|
|
|
parent::tearDown();
|
2011-06-21 23:01:47 +00:00
|
|
|
Configure::write('Cache.disable', $this->_cacheDisable);
|
|
|
|
Cache::drop('wincache');
|
2012-03-26 02:57:09 +00:00
|
|
|
Cache::drop('wincache_groups');
|
2011-06-21 23:01:47 +00:00
|
|
|
Cache::config('default');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* testReadAndWriteCache method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testReadAndWriteCache() {
|
|
|
|
Cache::set(array('duration' => 1), 'wincache');
|
|
|
|
|
|
|
|
$result = Cache::read('test', 'wincache');
|
|
|
|
$expecting = '';
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expecting, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$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;
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals($expecting, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-03-11 03:29:35 +00:00
|
|
|
Cache::set(array('duration' => 1), 'wincache');
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(4, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::read('test_decrement', 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(4, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::decrement('test_decrement', 2, 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(2, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::read('test_decrement', 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(2, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(6, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::read('test_increment', 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(6, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::increment('test_increment', 2, 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(8, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
|
|
|
|
$result = Cache::read('test_increment', 'wincache');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(8, $result);
|
2011-06-21 23:01:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* test the clearing of cache keys
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testClear() {
|
2011-08-20 13:25:53 +00:00
|
|
|
wincache_ucache_set('not_cake', 'safe');
|
2011-06-21 23:01:47 +00:00
|
|
|
Cache::write('some_value', 'value', 'wincache');
|
|
|
|
|
|
|
|
$result = Cache::clear(false, 'wincache');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
$this->assertFalse(Cache::read('some_value', 'wincache'));
|
2011-08-20 13:25:53 +00:00
|
|
|
$this->assertEquals('safe', wincache_ucache_get('not_cake'));
|
2011-06-21 23:01:47 +00:00
|
|
|
}
|
2012-03-26 02:57:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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() {
|
2012-03-27 04:05:15 +00:00
|
|
|
Cache::config('wincache_groups', array(
|
|
|
|
'engine' => 'Wincache',
|
|
|
|
'duration' => 0,
|
|
|
|
'groups' => array('group_a', 'group_b'),
|
|
|
|
'prefix' => 'test_'
|
|
|
|
));
|
2012-03-26 02:57:09 +00:00
|
|
|
$this->assertTrue(Cache::write('test_groups', 'value', 'wincache_groups'));
|
|
|
|
$this->assertEquals('value', Cache::read('test_groups', 'wincache_groups'));
|
|
|
|
|
2012-03-27 04:05:15 +00:00
|
|
|
wincache_ucache_inc('test_group_a');
|
2012-03-26 02:57:09 +00:00
|
|
|
$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'));
|
|
|
|
|
2012-03-27 04:05:15 +00:00
|
|
|
wincache_ucache_inc('test_group_b');
|
2012-03-26 02:57:09 +00:00
|
|
|
$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() {
|
2012-03-27 04:05:15 +00:00
|
|
|
Cache::config('wincache_groups', array(
|
|
|
|
'engine' => 'Wincache',
|
|
|
|
'duration' => 0,
|
|
|
|
'groups' => array('group_a', 'group_b'),
|
|
|
|
'prefix' => 'test_'
|
|
|
|
));
|
2012-03-26 02:57:09 +00:00
|
|
|
$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
|
2013-01-11 14:06:54 +00:00
|
|
|
*/
|
2012-03-26 02:57:09 +00:00
|
|
|
public function testGroupClear() {
|
2012-03-27 04:05:15 +00:00
|
|
|
Cache::config('wincache_groups', array(
|
|
|
|
'engine' => 'Wincache',
|
|
|
|
'duration' => 0,
|
|
|
|
'groups' => array('group_a', 'group_b'),
|
|
|
|
'prefix' => 'test_'
|
|
|
|
));
|
2012-03-26 02:57:09 +00:00
|
|
|
|
|
|
|
$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'));
|
|
|
|
}
|
2015-07-27 21:42:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Test that failed add write return false.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAdd() {
|
|
|
|
Cache::delete('test_add_key', 'wincache');
|
|
|
|
|
|
|
|
$result = Cache::add('test_add_key', 'test data', 'wincache');
|
|
|
|
$this->assertTrue($result);
|
|
|
|
|
|
|
|
$expected = 'test data';
|
|
|
|
$result = Cache::read('test_add_key', 'wincache');
|
|
|
|
$this->assertEquals($expected, $result);
|
|
|
|
|
|
|
|
$result = Cache::add('test_add_key', 'test data 2', 'wincache');
|
|
|
|
$this->assertFalse($result);
|
|
|
|
}
|
2011-06-21 23:01:47 +00:00
|
|
|
}
|