mirror of
https://github.com/moodle/moodle.git
synced 2025-01-19 06:18:28 +01:00
MDL-36363 cache: added unit tests for muliple loaders
This commit is contained in:
parent
3aee2fb8ee
commit
956d3544f0
22
cache/tests/cache_test.php
vendored
22
cache/tests/cache_test.php
vendored
@ -744,4 +744,26 @@ class cache_phpunit_tests extends advanced_testcase {
|
||||
$config = $factory->create_config_instance();
|
||||
$this->assertEquals('cache_config_phpunittest', get_class($config));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that multiple loaders work ok.
|
||||
*/
|
||||
public function test_multiple_loaders() {
|
||||
$instance = cache_config_phpunittest::instance(true);
|
||||
$instance->phpunit_add_file_store('phpunittest1');
|
||||
$instance->phpunit_add_file_store('phpunittest2');
|
||||
$instance->phpunit_add_definition('phpunit/multi_loader', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'multi_loader'
|
||||
));
|
||||
$instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest1', 3);
|
||||
$instance->phpunit_add_definition_mapping('phpunit/multi_loader', 'phpunittest2', 2);
|
||||
|
||||
$cache = cache::make('phpunit', 'multi_loader');
|
||||
$this->assertInstanceOf('cache_application', $cache);
|
||||
$this->assertFalse($cache->get('test'));
|
||||
$this->assertTrue($cache->set('test', 'test'));
|
||||
$this->assertEquals('test', $cache->get('test'));
|
||||
}
|
||||
}
|
39
cache/tests/fixtures/lib.php
vendored
39
cache/tests/fixtures/lib.php
vendored
@ -63,6 +63,45 @@ class cache_config_phpunittest extends cache_config_writer {
|
||||
public function phpunit_remove_stores() {
|
||||
$this->configstores = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully adds a file store.
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public function phpunit_add_file_store($name) {
|
||||
$this->configstores[$name] = array(
|
||||
'name' => $name,
|
||||
'plugin' => 'file',
|
||||
'configuration' => array(
|
||||
'path' => ''
|
||||
),
|
||||
'features' => 6,
|
||||
'modes' => 3,
|
||||
'mappingsonly' => false,
|
||||
'class' => 'cachestore_file',
|
||||
'default' => false,
|
||||
'lock' => 'cachelock_file_default'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Forcefully injects a definition => store mapping.
|
||||
*
|
||||
* This function does no validation, you should only be calling if it you know
|
||||
* exactly what to expect.
|
||||
*
|
||||
* @param string $definition
|
||||
* @param string $store
|
||||
* @param int $sort
|
||||
*/
|
||||
public function phpunit_add_definition_mapping($definition, $store, $sort) {
|
||||
$this->configdefinitionmappings[] = array(
|
||||
'store' => $store,
|
||||
'definition' => $definition,
|
||||
'sort' => (int)$sort
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user