mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-56316 tests: Ensure consistent assertion count
This commit is contained in:
parent
d9520bc04e
commit
070015004e
1 changed files with 32 additions and 19 deletions
|
@ -84,35 +84,48 @@ class core_string_manager_standard_testcase extends advanced_testcase {
|
||||||
'Please refer to https://docs.moodle.org/dev/String_deprecation');
|
'Please refer to https://docs.moodle.org/dev/String_deprecation');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return all deprecated strings.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function get_deprecated_strings_provider() {
|
||||||
|
global $CFG;
|
||||||
|
|
||||||
|
$teststringman = testable_core_string_manager::instance($CFG->langotherroot, $CFG->langlocalroot, array());
|
||||||
|
$allstrings = $teststringman->get_all_deprecated_strings();
|
||||||
|
return array_map(function($string) {
|
||||||
|
return [$string];
|
||||||
|
}, $allstrings);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This test is a built-in validation of deprecated.txt files in lang locations.
|
* This test is a built-in validation of deprecated.txt files in lang locations.
|
||||||
*
|
*
|
||||||
* It will fail if the string in the wrong format or non-existing (mistyped) string was deprecated.
|
* It will fail if the string in the wrong format or non-existing (mistyped) string was deprecated.
|
||||||
|
*
|
||||||
|
* @dataProvider get_deprecated_strings_provider
|
||||||
|
* @param string $string The string to be tested
|
||||||
*/
|
*/
|
||||||
public function test_validate_deprecated_strings_files() {
|
public function test_validate_deprecated_strings_files($string) {
|
||||||
global $CFG;
|
|
||||||
$stringman = get_string_manager();
|
$stringman = get_string_manager();
|
||||||
$teststringman = testable_core_string_manager::instance($CFG->langotherroot, $CFG->langlocalroot, array());
|
|
||||||
$allstrings = $teststringman->get_all_deprecated_strings();
|
|
||||||
|
|
||||||
foreach ($allstrings as $string) {
|
$result = preg_match('/^(.*),(.*)$/', $string, $matches);
|
||||||
if (!preg_match('/^(.*),(.*)$/', $string, $matches) ||
|
$this->assertEquals(1, $result);
|
||||||
clean_param($matches[2], PARAM_COMPONENT) !== $matches[2]) {
|
$this->assertCount(3, $matches);
|
||||||
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not have correct syntax');
|
$this->assertEquals($matches[2], clean_param($matches[2], PARAM_COMPONENT),
|
||||||
}
|
"Component name {$string} appearing in one of the lang/en/deprecated.txt files does not have correct syntax");
|
||||||
|
|
||||||
list($pluginttype, $pluginname) = core_component::normalize_component($matches[2]);
|
list($pluginttype, $pluginname) = core_component::normalize_component($matches[2]);
|
||||||
$normcomponent = $pluginname ? ($pluginttype . '_' . $pluginname) : $pluginttype;
|
$normcomponent = $pluginname ? ($pluginttype . '_' . $pluginname) : $pluginttype;
|
||||||
if ($matches[2] !== $normcomponent) {
|
$this->assertEquals($normcomponent, $matches[2],
|
||||||
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not have normalised component name');
|
'String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not have normalised component name');
|
||||||
}
|
|
||||||
if (!$stringman->string_exists($matches[1], $matches[2])) {
|
$this->assertTrue($stringman->string_exists($matches[1], $matches[2]),
|
||||||
$this->fail('String "'.$string.'" appearing in one of the lang/en/deprecated.txt files does not exist');
|
"String {$string} appearing in one of the lang/en/deprecated.txt files does not exist");
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper class providing testable string_manager
|
* Helper class providing testable string_manager
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue