2011-12-22 03:17:41 +01:00
|
|
|
<?php
|
|
|
|
|
2014-05-11 22:42:41 +02:00
|
|
|
class ConfigTest_DefinesFoo extends Object implements TestOnly {
|
2011-12-22 03:17:41 +01:00
|
|
|
protected static $foo = 1;
|
2016-08-22 17:39:11 +02:00
|
|
|
|
|
|
|
private static $not_foo = 1;
|
2011-12-22 03:17:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigTest_DefinesBar extends ConfigTest_DefinesFoo {
|
|
|
|
public static $bar = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigTest_DefinesFooAndBar extends ConfigTest_DefinesFoo {
|
|
|
|
protected static $foo = 3;
|
|
|
|
public static $bar = 3;
|
|
|
|
}
|
|
|
|
|
2014-05-11 22:42:41 +02:00
|
|
|
class ConfigTest_DefinesFooDoesntExtendObject implements TestOnly {
|
2011-12-22 03:17:41 +01:00
|
|
|
protected static $foo = 4;
|
|
|
|
}
|
|
|
|
|
2014-05-11 22:42:41 +02:00
|
|
|
class ConfigStaticTest_First extends Config implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
/** @config */
|
|
|
|
private static $first = array('test_1');
|
|
|
|
/** @config */
|
|
|
|
private static $second = array('test_1');
|
|
|
|
/** @config */
|
|
|
|
private static $third = 'test_1';
|
|
|
|
|
|
|
|
/** @config */
|
|
|
|
private static $bool = true;
|
|
|
|
/** @config */
|
|
|
|
private static $int = 42;
|
|
|
|
/** @config */
|
|
|
|
private static $string = 'value';
|
|
|
|
/** @config */
|
|
|
|
private static $nullable = 'value';
|
|
|
|
|
|
|
|
/** @config */
|
|
|
|
private static $default_false = false;
|
|
|
|
/** @config */
|
|
|
|
private static $default_null = null;
|
|
|
|
/** @config */
|
|
|
|
private static $default_zero = 0;
|
2013-03-21 14:32:09 +01:00
|
|
|
public static $default_emtpy_string = '';
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigStaticTest_Second extends ConfigStaticTest_First {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $first = array('test_2');
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigStaticTest_Third extends ConfigStaticTest_Second {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $first = array('test_3');
|
|
|
|
private static $second = array('test_3');
|
2012-04-18 13:11:53 +02:00
|
|
|
public static $fourth = array('test_3');
|
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigStaticTest_Fourth extends ConfigStaticTest_Third {
|
|
|
|
public static $fourth = array('test_4');
|
|
|
|
}
|
|
|
|
|
2014-05-11 22:42:41 +02:00
|
|
|
class ConfigStaticTest_Combined1 extends Config implements TestOnly {
|
2013-03-21 19:48:54 +01:00
|
|
|
/** @config */
|
|
|
|
private static $first = array('test_1');
|
|
|
|
/** @config */
|
|
|
|
private static $second = array('test_1');
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigStaticTest_Combined2 extends ConfigStaticTest_Combined1 {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $first = array('test_2');
|
|
|
|
private static $second = null;
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class ConfigStaticTest_Combined3 extends ConfigStaticTest_Combined2 {
|
2013-03-21 19:48:54 +01:00
|
|
|
private static $first = array('test_3');
|
|
|
|
private static $second = array('test_3');
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
2014-05-11 22:42:41 +02:00
|
|
|
class ConfigTest_TestNest extends Object implements TestOnly {
|
|
|
|
/** @config */
|
|
|
|
private static $foo = 3;
|
|
|
|
/** @config */
|
|
|
|
private static $bar = 5;
|
|
|
|
}
|
|
|
|
|
2011-12-22 03:17:41 +01:00
|
|
|
class ConfigTest extends SapphireTest {
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-06-10 00:27:54 +02:00
|
|
|
protected $depSettings = null;
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-06-10 00:27:54 +02:00
|
|
|
public function setUp() {
|
|
|
|
parent::setUp();
|
|
|
|
$this->depSettings = Deprecation::dump_settings();
|
|
|
|
Deprecation::set_enabled(false);
|
|
|
|
}
|
2016-01-06 00:34:58 +01:00
|
|
|
|
2015-06-10 00:27:54 +02:00
|
|
|
public function tearDown() {
|
|
|
|
Deprecation::restore_settings($this->depSettings);
|
|
|
|
parent::tearDown();
|
|
|
|
}
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-04-22 05:21:12 +02:00
|
|
|
public function testNest() {
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-04-22 05:21:12 +02:00
|
|
|
// Check basic config
|
2014-05-11 22:42:41 +02:00
|
|
|
$this->assertEquals(3, Config::inst()->get('ConfigTest_TestNest', 'foo'));
|
|
|
|
$this->assertEquals(5, Config::inst()->get('ConfigTest_TestNest', 'bar'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-04-22 05:21:12 +02:00
|
|
|
// Test nest copies data
|
|
|
|
Config::nest();
|
2014-05-11 22:42:41 +02:00
|
|
|
$this->assertEquals(3, Config::inst()->get('ConfigTest_TestNest', 'foo'));
|
|
|
|
$this->assertEquals(5, Config::inst()->get('ConfigTest_TestNest', 'bar'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-04-22 05:21:12 +02:00
|
|
|
// Test nested data can be updated
|
2014-05-11 22:42:41 +02:00
|
|
|
Config::inst()->update('ConfigTest_TestNest', 'foo', 4);
|
|
|
|
$this->assertEquals(4, Config::inst()->get('ConfigTest_TestNest', 'foo'));
|
|
|
|
$this->assertEquals(5, Config::inst()->get('ConfigTest_TestNest', 'bar'));
|
2014-08-15 08:53:05 +02:00
|
|
|
|
2014-04-22 05:21:12 +02:00
|
|
|
// Test unnest restores data
|
|
|
|
Config::unnest();
|
2014-05-11 22:42:41 +02:00
|
|
|
$this->assertEquals(3, Config::inst()->get('ConfigTest_TestNest', 'foo'));
|
|
|
|
$this->assertEquals(5, Config::inst()->get('ConfigTest_TestNest', 'bar'));
|
2014-04-22 05:21:12 +02:00
|
|
|
}
|
2011-12-22 03:17:41 +01:00
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testUpdateStatic() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET),
|
|
|
|
array('test_1'));
|
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Second', 'first', Config::FIRST_SET),
|
|
|
|
array('test_2'));
|
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'first', Config::FIRST_SET),
|
|
|
|
array('test_3'));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1_2'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_Third', 'first', array('test_3_2'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4'));
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'first', Config::FIRST_SET),
|
|
|
|
array('test_1_2', 'test_1'));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
Config::inst()->update('ConfigStaticTest_Fourth', 'second', array('test_4'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
|
|
|
|
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'second', Config::FIRST_SET),
|
|
|
|
array('test_4'));
|
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET),
|
|
|
|
array('test_3_2', 'test_3'));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
Config::inst()->remove('ConfigStaticTest_Third', 'second');
|
2013-03-21 19:48:54 +01:00
|
|
|
$this->assertEquals(array(), Config::inst()->get('ConfigStaticTest_Third', 'second'));
|
2012-04-18 13:11:53 +02:00
|
|
|
Config::inst()->update('ConfigStaticTest_Third', 'second', array('test_3_2'));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Third', 'second', Config::FIRST_SET),
|
|
|
|
array('test_3_2'));
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
2013-03-21 14:32:09 +01:00
|
|
|
public function testUpdateWithFalsyValues() {
|
|
|
|
// Booleans
|
|
|
|
$this->assertTrue(Config::inst()->get('ConfigStaticTest_First', 'bool'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'bool', false);
|
|
|
|
$this->assertFalse(Config::inst()->get('ConfigStaticTest_First', 'bool'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'bool', true);
|
|
|
|
$this->assertTrue(Config::inst()->get('ConfigStaticTest_First', 'bool'));
|
|
|
|
|
|
|
|
// Integers
|
|
|
|
$this->assertEquals(42, Config::inst()->get('ConfigStaticTest_First', 'int'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'int', 0);
|
|
|
|
$this->assertEquals(0, Config::inst()->get('ConfigStaticTest_First', 'int'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'int', 42);
|
|
|
|
$this->assertEquals(42, Config::inst()->get('ConfigStaticTest_First', 'int'));
|
|
|
|
|
|
|
|
// Strings
|
|
|
|
$this->assertEquals('value', Config::inst()->get('ConfigStaticTest_First', 'string'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'string', '');
|
|
|
|
$this->assertEquals('', Config::inst()->get('ConfigStaticTest_First', 'string'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'string', 'value');
|
|
|
|
$this->assertEquals('value', Config::inst()->get('ConfigStaticTest_First', 'string'));
|
|
|
|
|
|
|
|
// Nulls
|
|
|
|
$this->assertEquals('value', Config::inst()->get('ConfigStaticTest_First', 'nullable'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'nullable', null);
|
|
|
|
$this->assertNull(Config::inst()->get('ConfigStaticTest_First', 'nullable'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'nullable', 'value');
|
|
|
|
$this->assertEquals('value', Config::inst()->get('ConfigStaticTest_First', 'nullable'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testSetsFalsyDefaults() {
|
|
|
|
$this->assertFalse(Config::inst()->get('ConfigStaticTest_First', 'default_false'));
|
|
|
|
// Technically the same as an undefined config key
|
|
|
|
$this->assertNull(Config::inst()->get('ConfigStaticTest_First', 'default_null'));
|
|
|
|
$this->assertEquals(0, Config::inst()->get('ConfigStaticTest_First', 'default_zero'));
|
|
|
|
$this->assertEquals('', Config::inst()->get('ConfigStaticTest_First', 'default_empty_string'));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testUninheritedStatic() {
|
2012-04-18 13:11:53 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_First', 'third', Config::UNINHERITED), 'test_1');
|
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Fourth', 'third', Config::UNINHERITED), null);
|
|
|
|
|
|
|
|
Config::inst()->update('ConfigStaticTest_First', 'first', array('test_1b'));
|
|
|
|
Config::inst()->update('ConfigStaticTest_Second', 'first', array('test_2b'));
|
|
|
|
|
|
|
|
// Check that it can be applied to parent and subclasses, and queried directly
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertContains('test_1b',
|
|
|
|
Config::inst()->get('ConfigStaticTest_First', 'first', Config::UNINHERITED));
|
|
|
|
$this->assertContains('test_2b',
|
|
|
|
Config::inst()->get('ConfigStaticTest_Second', 'first', Config::UNINHERITED));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
// But it won't affect subclasses - this is *uninherited* static
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertNotContains('test_2b',
|
|
|
|
Config::inst()->get('ConfigStaticTest_Third', 'first', Config::UNINHERITED));
|
2014-10-25 23:28:28 +02:00
|
|
|
$this->assertNull(Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
// Subclasses that don't have the static explicitly defined should allow definition, also
|
2014-08-15 08:53:05 +02:00
|
|
|
// This also checks that set can be called after the first uninherited get()
|
|
|
|
// call (which can be buggy due to caching)
|
2012-04-18 13:11:53 +02:00
|
|
|
Config::inst()->update('ConfigStaticTest_Fourth', 'first', array('test_4b'));
|
|
|
|
$this->assertContains('test_4b', Config::inst()->get('ConfigStaticTest_Fourth', 'first', Config::UNINHERITED));
|
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testCombinedStatic() {
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'first'),
|
|
|
|
array('test_3', 'test_2', 'test_1'));
|
2012-04-18 13:11:53 +02:00
|
|
|
|
|
|
|
// test that null values are ignored, but values on either side are still merged
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals(Config::inst()->get('ConfigStaticTest_Combined3', 'second'),
|
|
|
|
array('test_3', 'test_1'));
|
2012-04-18 13:11:53 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testMerges() {
|
2011-12-22 03:17:41 +01:00
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => 3);
|
|
|
|
Config::merge_array_low_into_high($result, array('C' => 4, 'D' => 5));
|
|
|
|
$this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => 3, 'D' => 5));
|
|
|
|
|
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => 3);
|
|
|
|
Config::merge_array_high_into_low($result, array('C' => 4, 'D' => 5));
|
|
|
|
$this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => 4, 'D' => 5));
|
|
|
|
|
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3));
|
|
|
|
Config::merge_array_low_into_high($result, array('C' => array(4, 5, 6), 'D' => 5));
|
|
|
|
$this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3, 4, 5, 6), 'D' => 5));
|
|
|
|
|
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => array(1, 2, 3));
|
|
|
|
Config::merge_array_high_into_low($result, array('C' => array(4, 5, 6), 'D' => 5));
|
|
|
|
$this->assertEquals($result, array('A' => 1, 'B' => 2, 'C' => array(4, 5, 6, 1, 2, 3), 'D' => 5));
|
|
|
|
|
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2), 'D' => 3);
|
|
|
|
Config::merge_array_low_into_high($result, array('C' => array('Bar' => 3, 'Baz' => 4)));
|
2014-08-15 08:53:05 +02:00
|
|
|
$this->assertEquals($result,
|
2012-09-26 23:34:00 +02:00
|
|
|
array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2, 'Baz' => 4), 'D' => 3));
|
2011-12-22 03:17:41 +01:00
|
|
|
|
|
|
|
$result = array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 2), 'D' => 3);
|
|
|
|
Config::merge_array_high_into_low($result, array('C' => array('Bar' => 3, 'Baz' => 4)));
|
2012-09-26 23:34:00 +02:00
|
|
|
$this->assertEquals($result,
|
|
|
|
array('A' => 1, 'B' => 2, 'C' => array('Foo' => 1, 'Bar' => 3, 'Baz' => 4), 'D' => 3));
|
2011-12-22 03:17:41 +01:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testStaticLookup() {
|
2011-12-22 03:17:41 +01:00
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFoo', 'foo'), 1);
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFoo', 'bar'), null);
|
|
|
|
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesBar', 'foo'), null);
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesBar', 'bar'), 2);
|
|
|
|
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFooAndBar', 'foo'), 3);
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFooAndBar', 'bar'), 3);
|
|
|
|
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFooDoesntExtendObject', 'foo'), 4);
|
|
|
|
$this->assertEquals(Object::static_lookup('ConfigTest_DefinesFooDoesntExtendObject', 'bar'), null);
|
|
|
|
}
|
|
|
|
|
2016-08-02 08:07:31 +02:00
|
|
|
public function testForClass() {
|
|
|
|
$config = ConfigTest_DefinesFoo::config();
|
|
|
|
// Set values
|
2016-08-22 17:39:11 +02:00
|
|
|
$this->assertTrue(isset($config->not_foo));
|
|
|
|
$this->assertFalse(empty($config->not_foo));
|
|
|
|
$this->assertEquals(1, $config->not_foo);
|
|
|
|
|
2016-08-02 08:07:31 +02:00
|
|
|
// Unset values
|
2016-08-02 12:57:45 +02:00
|
|
|
$this->assertFalse(isset($config->bar));
|
|
|
|
$this->assertTrue(empty($config->bar));
|
|
|
|
$this->assertNull($config->bar);
|
2016-08-02 08:07:31 +02:00
|
|
|
}
|
|
|
|
|
2012-09-19 12:07:39 +02:00
|
|
|
public function testFragmentOrder() {
|
2012-11-23 14:55:19 +01:00
|
|
|
$this->markTestIncomplete();
|
2011-12-22 03:17:41 +01:00
|
|
|
}
|
2013-02-26 04:39:40 +01:00
|
|
|
|
2013-12-20 06:05:56 +01:00
|
|
|
public function testCacheCleaning() {
|
|
|
|
$cache = new ConfigTest_Config_MemCache();
|
|
|
|
|
|
|
|
for ($i = 0; $i < 1000; $i++) $cache->set($i, $i);
|
|
|
|
$this->assertEquals(1000, count($cache->cache));
|
|
|
|
|
|
|
|
$cache->clean();
|
|
|
|
$this->assertEquals(0, count($cache->cache), 'Clean clears all items');
|
|
|
|
$this->assertFalse($cache->get(1), 'Clean clears all items');
|
|
|
|
|
|
|
|
$cache->set(1, 1, array('Foo'));
|
|
|
|
$this->assertEquals(1, count($cache->cache));
|
|
|
|
$this->assertEquals(1, count($cache->tags));
|
|
|
|
|
|
|
|
$cache->clean('Foo');
|
|
|
|
$this->assertEquals(0, count($cache->tags), 'Clean items with matching tag');
|
|
|
|
$this->assertFalse($cache->get(1), 'Clean items with matching tag');
|
|
|
|
|
|
|
|
$cache->set(1, 1, array('Foo', 'Bar'));
|
|
|
|
$this->assertEquals(2, count($cache->tags));
|
|
|
|
$this->assertEquals(1, count($cache->cache));
|
|
|
|
|
|
|
|
$cache->clean('Bar');
|
|
|
|
$this->assertEquals(1, count($cache->tags));
|
|
|
|
$this->assertEquals(0, count($cache->cache), 'Clean items with any single matching tag');
|
|
|
|
$this->assertFalse($cache->get(1), 'Clean items with any single matching tag');
|
|
|
|
}
|
|
|
|
|
2013-02-26 04:39:40 +01:00
|
|
|
public function testLRUDiscarding() {
|
2015-08-29 06:20:00 +02:00
|
|
|
$cache = new Config_LRU();
|
2013-02-26 04:39:40 +01:00
|
|
|
for ($i = 0; $i < Config_LRU::SIZE*2; $i++) $cache->set($i, $i);
|
|
|
|
$this->assertEquals(
|
2015-08-29 06:20:00 +02:00
|
|
|
Config_LRU::SIZE, $cache->getIndexCount(),
|
2013-02-26 04:39:40 +01:00
|
|
|
'Homogenous usage gives exact discarding'
|
|
|
|
);
|
2015-08-29 06:20:00 +02:00
|
|
|
$cache = new Config_LRU();
|
2013-02-26 04:39:40 +01:00
|
|
|
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set($i, $i);
|
|
|
|
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set(-1, -1);
|
|
|
|
$this->assertLessThan(
|
2015-08-29 06:20:00 +02:00
|
|
|
Config_LRU::SIZE, $cache->getIndexCount(),
|
2013-02-26 04:39:40 +01:00
|
|
|
'Heterogenous usage gives sufficient discarding'
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-29 06:20:00 +02:00
|
|
|
|
2013-02-26 04:39:40 +01:00
|
|
|
public function testLRUCleaning() {
|
2015-08-29 06:20:00 +02:00
|
|
|
$cache = new Config_LRU();
|
2013-02-26 04:39:40 +01:00
|
|
|
for ($i = 0; $i < Config_LRU::SIZE; $i++) $cache->set($i, $i);
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(Config_LRU::SIZE, $cache->getIndexCount());
|
2013-02-26 04:39:40 +01:00
|
|
|
$cache->clean();
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(0, $cache->getIndexCount(), 'Clean clears all items');
|
2013-02-26 04:39:40 +01:00
|
|
|
$this->assertFalse($cache->get(1), 'Clean clears all items');
|
|
|
|
$cache->set(1, 1, array('Foo'));
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(1, $cache->getIndexCount());
|
2013-02-26 04:39:40 +01:00
|
|
|
$cache->clean('Foo');
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(0, $cache->getIndexCount(), 'Clean items with matching tag');
|
2013-02-26 04:39:40 +01:00
|
|
|
$this->assertFalse($cache->get(1), 'Clean items with matching tag');
|
|
|
|
$cache->set(1, 1, array('Foo', 'Bar'));
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(1, $cache->getIndexCount());
|
2013-02-26 04:39:40 +01:00
|
|
|
$cache->clean('Bar');
|
2015-08-29 06:20:00 +02:00
|
|
|
$this->assertEquals(0, $cache->getIndexCount(), 'Clean items with any single matching tag');
|
2013-02-26 04:39:40 +01:00
|
|
|
$this->assertFalse($cache->get(1), 'Clean items with any single matching tag');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-12-20 06:05:56 +01:00
|
|
|
class ConfigTest_Config_MemCache extends Config_MemCache implements TestOnly {
|
|
|
|
|
|
|
|
public $cache;
|
|
|
|
public $tags;
|
2013-02-26 04:39:40 +01:00
|
|
|
|
2011-12-22 03:17:41 +01:00
|
|
|
}
|