MDL-68440 cache: Added counting of default mappings
authorPeter Burnett <peterburnett@catalyst-au.net>
Tue, 21 Apr 2020 00:00:35 +0000 (10:00 +1000)
committerPeter Burnett <peterburnett@catalyst-au.net>
Mon, 12 Oct 2020 01:57:17 +0000 (11:57 +1000)
cache/classes/administration_helper.php
cache/tests/administration_helper_test.php

index 551e62c..620505c 100644 (file)
@@ -101,13 +101,31 @@ abstract class administration_helper extends cache_helper {
         ksort($default);
         $return = $return + $default;
 
-        foreach ($instance->get_definition_mappings() as $mapping) {
+        $mappings = $instance->get_definition_mappings();
+        foreach ($mappings as $mapping) {
             if (!array_key_exists($mapping['store'], $return)) {
                 continue;
             }
             $return[$mapping['store']]['mappings']++;
         }
 
+        // Now get all definitions, and if not mapped, increment the defaults for the mode.
+        $modemappings = $instance->get_mode_mappings();
+        foreach ($instance->get_definitions() as $definition) {
+            // Construct the definition name to search for.
+            $defname = $definition['component'] . '/' . $definition['area'];
+            // Skip if definition is already mapped.
+            if (array_search($defname, array_column($mappings, 'definition')) !== false) {
+                continue;
+            }
+
+            $mode = $definition['mode'];
+            // Get the store name of the default mapping from the mode.
+            $index = array_search($mode, array_column($modemappings, 'mode'));
+            $store = $modemappings[$index]['store'];
+            $return[$store]['mappings']++;
+        }
+
         return $return;
     }
 
index 865539f..146efe3 100644 (file)
@@ -92,7 +92,12 @@ class core_cache_administration_helper_testcase extends advanced_testcase {
         $this->assertEquals(0, $summary['default']);
         $this->assertEquals(1, $summary['isready']);
         $this->assertEquals(1, $summary['requirementsmet']);
-        $this->assertEquals(1, $summary['mappings']);
+
+        // Find the number of mappings to sessionstore.
+        $mappingcount = count(array_filter($config->get_definitions(), function($element) {
+            return $element['mode'] === cache_store::MODE_APPLICATION;
+        }));
+        $this->assertEquals($mappingcount, $summary['mappings']);
 
         $definitionsummaries = core_cache\administration_helper::get_definition_summaries();
         $this->assertInternalType('array', $definitionsummaries);