MDL-69772 lang: Ignore misconfigured allcountrycodes filter
If the allcountrycodes filter contains only invalid values, ignore the whole filter setting and make get_list_of_countries() return the full list of all known countries, rather than empty list.
This commit is contained in:
@@ -427,6 +427,7 @@ class core_string_manager_standard implements core_string_manager {
|
||||
|
||||
$countries = $this->load_component_strings('core_countries', $lang);
|
||||
core_collator::asort($countries);
|
||||
|
||||
if (!$returnall and !empty($CFG->allcountrycodes)) {
|
||||
$enabled = explode(',', $CFG->allcountrycodes);
|
||||
$return = array();
|
||||
@@ -435,7 +436,10 @@ class core_string_manager_standard implements core_string_manager {
|
||||
$return[$c] = $countries[$c];
|
||||
}
|
||||
}
|
||||
return $return;
|
||||
|
||||
if (!empty($return)) {
|
||||
return $return;
|
||||
}
|
||||
}
|
||||
|
||||
return $countries;
|
||||
|
||||
@@ -143,6 +143,57 @@ class core_string_manager_standard_testcase extends advanced_testcase {
|
||||
set_config('langlist', '');
|
||||
get_string_manager(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test {@see core_string_manager_standard::get_list_of_countries()} under different conditions.
|
||||
*/
|
||||
public function test_get_list_of_countries() {
|
||||
|
||||
$this->resetAfterTest();
|
||||
$stringman = get_string_manager();
|
||||
|
||||
$countries = $stringman->get_list_of_countries(true);
|
||||
$this->assertIsArray($countries);
|
||||
$this->assertArrayHasKey('AU', $countries);
|
||||
$this->assertArrayHasKey('BE', $countries);
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
$this->assertArrayHasKey('ES', $countries);
|
||||
$this->assertGreaterThan(4, count($countries));
|
||||
|
||||
set_config('allcountrycodes', '');
|
||||
$countries = $stringman->get_list_of_countries(false);
|
||||
$this->assertArrayHasKey('AU', $countries);
|
||||
$this->assertArrayHasKey('BE', $countries);
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
$this->assertArrayHasKey('ES', $countries);
|
||||
$this->assertGreaterThan(4, count($countries));
|
||||
|
||||
set_config('allcountrycodes', 'CZ,BE');
|
||||
$countries = $stringman->get_list_of_countries(true);
|
||||
$this->assertArrayHasKey('AU', $countries);
|
||||
$this->assertArrayHasKey('BE', $countries);
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
$this->assertArrayHasKey('ES', $countries);
|
||||
$this->assertGreaterThan(4, count($countries));
|
||||
|
||||
$countries = $stringman->get_list_of_countries(false);
|
||||
$this->assertEquals(2, count($countries));
|
||||
$this->assertArrayHasKey('BE', $countries);
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
|
||||
set_config('allcountrycodes', 'CZ,UVWXYZ');
|
||||
$countries = $stringman->get_list_of_countries();
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
$this->assertEquals(1, count($countries));
|
||||
|
||||
set_config('allcountrycodes', 'UVWXYZ');
|
||||
$countries = $stringman->get_list_of_countries();
|
||||
$this->assertArrayHasKey('AU', $countries);
|
||||
$this->assertArrayHasKey('BE', $countries);
|
||||
$this->assertArrayHasKey('CZ', $countries);
|
||||
$this->assertArrayHasKey('ES', $countries);
|
||||
$this->assertGreaterThan(4, count($countries));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user