diff --git a/cache/classes/helper.php b/cache/classes/helper.php index 96bedb2bb59..015ed8a184b 100644 --- a/cache/classes/helper.php +++ b/cache/classes/helper.php @@ -718,7 +718,8 @@ class cache_helper { return $stores; } else { $stores = self::get_cache_stores($definition); - if (count($stores) === 0) { + // If mappingsonly is set, having 0 stores is ok. + if ((count($stores) === 0) && (!$definition->is_for_mappings_only())) { // No suitable stores we found for the definition. We need to come up with a sensible default. // If this has happened we can be sure that the user has mapped custom stores to either the // mode of the definition. The first alternative to try is the system default for the mode. diff --git a/cache/tests/cache_test.php b/cache/tests/cache_test.php index 2267afad415..5a85f1465e8 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -470,6 +470,33 @@ class core_cache_testcase extends advanced_testcase { $this->assertEquals('Test has no value really.', $cache->get('Test')); } + /** + * Test the mappingsonly setting. + */ + public function test_definition_mappings_only() { + $instance = cache_config_phpunittest::instance(true); + $instance->phpunit_add_definition('phpunit/mappingsonly', array( + 'mode' => cache_store::MODE_APPLICATION, + 'component' => 'phpunit', + 'area' => 'mappingsonly', + 'mappingsonly' => true + )); + $instance->phpunit_add_definition('phpunit/nonmappingsonly', array( + 'mode' => cache_store::MODE_APPLICATION, + 'component' => 'phpunit', + 'area' => 'nonmappingsonly', + 'mappingsonly' => false + )); + + $cacheonly = cache::make('phpunit', 'mappingsonly'); + $this->assertInstanceOf('cache_application', $cacheonly); + $this->assertEquals('cachestore_dummy', $cacheonly->phpunit_get_store_class()); + + $cachenon = cache::make('phpunit', 'nonmappingsonly'); + $this->assertInstanceOf('cache_application', $cachenon); + $this->assertEquals('cachestore_file', $cachenon->phpunit_get_store_class()); + } + /** * Test a very basic definition. */