MDL-45513 cache: implemented defines for unit testing alternative caches
This commit is contained in:
Vendored
+27
-6
@@ -58,18 +58,37 @@ class core_cache_testcase extends advanced_testcase {
|
||||
cache_factory::reset();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the expected application cache store.
|
||||
* @return string
|
||||
*/
|
||||
protected function get_expected_application_cache_store() {
|
||||
$expected = 'cachestore_file';
|
||||
if (defined('TEST_CACHE_USING_APPLICATION_STORE') && preg_match('#[a-zA-Z][a-zA-Z0-9_]*#', TEST_CACHE_USING_APPLICATION_STORE)) {
|
||||
$expected = 'cachestore_'.(string)TEST_CACHE_USING_APPLICATION_STORE;
|
||||
}
|
||||
return $expected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests cache configuration
|
||||
*/
|
||||
public function test_cache_config() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->altcacheconfigpath)) {
|
||||
if (defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH &&
|
||||
!empty($CFG->altcacheconfigpath)) {
|
||||
// We need to skip this test - it checks the default config structure, but very likely we arn't using the
|
||||
// default config structure here so theres no point in running the test.
|
||||
$this->markTestSkipped('Skipped testing default cache config structure as alt cache path is being used.');
|
||||
}
|
||||
|
||||
if (defined('TEST_CACHE_USING_APPLICATION_STORE')) {
|
||||
// We need to skip this test - it checks the default config structure, but very likely we arn't using the
|
||||
// default config structure here because we are testing against an alternative application store.
|
||||
$this->markTestSkipped('Skipped testing default cache config structure as alt application store is being used.');
|
||||
}
|
||||
|
||||
$instance = cache_config::instance();
|
||||
$this->assertInstanceOf('cache_config_phpunittest', $instance);
|
||||
|
||||
@@ -482,27 +501,29 @@ class core_cache_testcase extends advanced_testcase {
|
||||
* Test the mappingsonly setting.
|
||||
*/
|
||||
public function test_definition_mappings_only() {
|
||||
/** @var cache_config_phpunittest $instance */
|
||||
$instance = cache_config_phpunittest::instance(true);
|
||||
$instance->phpunit_add_definition('phpunit/mappingsonly', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'mappingsonly',
|
||||
'mappingsonly' => true
|
||||
));
|
||||
), false);
|
||||
$instance->phpunit_add_definition('phpunit/nonmappingsonly', array(
|
||||
'mode' => cache_store::MODE_APPLICATION,
|
||||
'component' => 'phpunit',
|
||||
'area' => 'nonmappingsonly',
|
||||
'mappingsonly' => false
|
||||
));
|
||||
), false);
|
||||
|
||||
$cacheonly = cache::make('phpunit', 'mappingsonly');
|
||||
$this->assertInstanceOf('cache_application', $cacheonly);
|
||||
$this->assertEquals('cachestore_dummy', $cacheonly->phpunit_get_store_class());
|
||||
|
||||
$expected = $this->get_expected_application_cache_store();
|
||||
$cachenon = cache::make('phpunit', 'nonmappingsonly');
|
||||
$this->assertInstanceOf('cache_application', $cachenon);
|
||||
$this->assertEquals('cachestore_file', $cachenon->phpunit_get_store_class());
|
||||
$this->assertEquals($expected, $cachenon->phpunit_get_store_class());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1082,7 +1103,7 @@ class core_cache_testcase extends advanced_testcase {
|
||||
*/
|
||||
public function test_alt_cache_path() {
|
||||
global $CFG;
|
||||
if ($CFG->altcacheconfigpath) {
|
||||
if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
|
||||
$this->markTestSkipped('Skipped testing alt cache path as it is already being used.');
|
||||
}
|
||||
$this->resetAfterTest();
|
||||
@@ -1161,7 +1182,7 @@ class core_cache_testcase extends advanced_testcase {
|
||||
public function test_disable() {
|
||||
global $CFG;
|
||||
|
||||
if (!empty($CFG->altcacheconfigpath)) {
|
||||
if ((defined('TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH') && TEST_CACHE_USING_ALT_CACHE_CONFIG_PATH) || !empty($CFG->altcacheconfigpath)) {
|
||||
// We can't run this test as it requires us to delete the cache configuration script which we just
|
||||
// cant do with a custom path in play.
|
||||
$this->markTestSkipped('Skipped testing cache disable functionality as alt cache path is being used.');
|
||||
|
||||
Reference in New Issue
Block a user