From e39099ac3667e22f171d82c8fbb456f456323334 Mon Sep 17 00:00:00 2001 From: Eric Merrill Date: Sat, 17 May 2014 23:46:44 -0400 Subject: [PATCH] MDL-45603 cache Fix the mappingsonly option to work as advertised. --- cache/classes/helper.php | 3 ++- cache/tests/cache_test.php | 27 +++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/cache/classes/helper.php b/cache/classes/helper.php index 39ee2e49fd236..02bd243afcb6d 100644 --- a/cache/classes/helper.php +++ b/cache/classes/helper.php @@ -719,7 +719,8 @@ public static function get_stores_suitable_for_definition(cache_definition $defi 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 2267afad415b9..5a85f1465e85c 100644 --- a/cache/tests/cache_test.php +++ b/cache/tests/cache_test.php @@ -470,6 +470,33 @@ public function test_definition_overridden_loader() { $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. */