Skip to content

Commit 017a1c7

Browse files
authored
Merge pull request #64 from SashaAnastasi/TOTARA_19-fixes
Totara 19 fixes
2 parents b3420a4 + e39d67b commit 017a1c7

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

classes/cache_config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ private function generate_store_instance_config(array $stores): array {
208208
foreach ($stores as $name => $store) {
209209

210210
// First check that all the required fields are present in the store.
211-
if (!(array_key_exists('type', $store) ||
211+
if (!(array_key_exists('type', $store) &&
212212
array_key_exists('config', $store))) {
213213
throw new cache_exception(get_string('store_missing_fields', 'tool_forcedcache', $name));
214214
}

tests/cache_config_test.php

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,6 @@ public function test_read_non_existent_config_file() {
132132
$method->invoke($config);
133133
}
134134

135-
136135
public function test_generate_store_instance_config() {
137136
// Directly create a config.
138137
$config = new \tool_forcedcache_cache_config();
@@ -153,20 +152,42 @@ public function test_generate_store_instance_config() {
153152
// Now test with 0 stores declared and confirm its just the defaults.
154153
$this->assertEquals($storezero['expected'], $method->invoke($config, $storezero['input']));
155154

155+
// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
156+
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
157+
}
158+
159+
public function test_generate_store_instance_config_badtype() {
160+
// Directly create a config.
161+
$config = new \tool_forcedcache_cache_config();
162+
163+
// Setup reflection for private function.
164+
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
165+
$method->setAccessible(true);
166+
167+
// Read in the fixtures file for data.
168+
include(__DIR__ . '/fixtures/stores_data.php');
169+
156170
// Now test a store with a bad type.
157171
$this->expectException(\cache_exception::class);
158172
$this->expectExceptionMessage(get_string('store_bad_type', 'tool_forcedcache', 'faketype'));
159173
$storearr1 = $method->invoke($config, $storebadtype['input']);
160-
$this->assertNull($storearr1);
174+
}
175+
176+
public function test_generate_store_instance_config_missingfield() {
177+
// Directly create a config.
178+
$config = new \tool_forcedcache_cache_config();
179+
180+
// Setup reflection for private function.
181+
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
182+
$method->setAccessible(true);
183+
184+
// Read in the fixtures file for data.
185+
include(__DIR__ . '/fixtures/stores_data.php');
161186

162187
// Now test a store with a missing required field.
163188
$this->expectException(\cache_exception::class);
164-
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcu-test'));
165-
$storearr1 = $method->invoke($config, $storemissingfields['input']);
166-
$this->assertNull($storearr1);
167-
168-
// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
169-
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
189+
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcutest'));
190+
$storearr1 = $method->invoke($config, $storemissingfield['input']);
170191
}
171192

172193
/**

0 commit comments

Comments
 (0)