Skip to content

Commit

Permalink
Merge pull request #64 from SashaAnastasi/TOTARA_19-fixes
Browse files Browse the repository at this point in the history
Totara 19 fixes
  • Loading branch information
danmarsden authored Mar 5, 2025
2 parents b3420a4 + e39d67b commit 017a1c7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
2 changes: 1 addition & 1 deletion classes/cache_config.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ private function generate_store_instance_config(array $stores): array {
foreach ($stores as $name => $store) {

// First check that all the required fields are present in the store.
if (!(array_key_exists('type', $store) ||
if (!(array_key_exists('type', $store) &&
array_key_exists('config', $store))) {
throw new cache_exception(get_string('store_missing_fields', 'tool_forcedcache', $name));
}
Expand Down
37 changes: 29 additions & 8 deletions tests/cache_config_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ public function test_read_non_existent_config_file() {
$method->invoke($config);
}


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

// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
}

public function test_generate_store_instance_config_badtype() {
// Directly create a config.
$config = new \tool_forcedcache_cache_config();

// Setup reflection for private function.
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
$method->setAccessible(true);

// Read in the fixtures file for data.
include(__DIR__ . '/fixtures/stores_data.php');

// Now test a store with a bad type.
$this->expectException(\cache_exception::class);
$this->expectExceptionMessage(get_string('store_bad_type', 'tool_forcedcache', 'faketype'));
$storearr1 = $method->invoke($config, $storebadtype['input']);
$this->assertNull($storearr1);
}

public function test_generate_store_instance_config_missingfield() {
// Directly create a config.
$config = new \tool_forcedcache_cache_config();

// Setup reflection for private function.
$method = new \ReflectionMethod($config, 'generate_store_instance_config');
$method->setAccessible(true);

// Read in the fixtures file for data.
include(__DIR__ . '/fixtures/stores_data.php');

// Now test a store with a missing required field.
$this->expectException(\cache_exception::class);
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcu-test'));
$storearr1 = $method->invoke($config, $storemissingfields['input']);
$this->assertNull($storearr1);

// Now test store with where store isn't ready, don't instantiate (APCu doesn't work from CLI).
$this->assertEquals($storereqsnotmet['expected'], $method->invoke($config, $storereqsnotmet['input']));
$this->expectExceptionMessage(get_string('store_missing_fields', 'tool_forcedcache', 'apcutest'));
$storearr1 = $method->invoke($config, $storemissingfield['input']);
}

/**
Expand Down

0 comments on commit 017a1c7

Please sign in to comment.