MDL-36363 cache: added unit tests for muliple loaders

This commit is contained in:
Sam Hemelryk 2013-01-31 12:16:08 +13:00
parent 3aee2fb8ee
commit 956d3544f0
2 changed files with 61 additions and 0 deletions

View File

@ -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'));
}
}

View File

@ -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
);
}
}
/**