mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
MDL-64285 core: Fix environment check test
* Looping the environment results and skipping some items mean that if a test gets skipped, the rest of the environment results won't be tested. It's better to use a data provider for this in order to individually test each environment result.
This commit is contained in:
parent
33a388eff7
commit
c482e6bd51
@ -32,36 +32,61 @@ defined('MOODLE_INTERNAL') || die();
|
||||
class core_environment_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* Test the environment.
|
||||
* Test the environment check status.
|
||||
*/
|
||||
public function test_environment() {
|
||||
public function test_environment_check_status() {
|
||||
global $CFG;
|
||||
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
list($envstatus, $environment_results) = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE);
|
||||
|
||||
$results = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE);
|
||||
|
||||
// The first element of the results array contains the environment check status.
|
||||
$status = reset($results);
|
||||
$this->assertTrue($status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for Moodle environment check tests.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function environment_provider() {
|
||||
global $CFG;
|
||||
require_once($CFG->libdir.'/environmentlib.php');
|
||||
|
||||
$results = check_moodle_environment(normalize_version($CFG->release), ENV_SELECT_RELEASE);
|
||||
// The second element of the results array contains the list of environment results.
|
||||
$environmentresults = end($results);
|
||||
return array_map(function($result) {
|
||||
return [$result];
|
||||
}, $environmentresults);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test the environment.
|
||||
*
|
||||
* @dataProvider environment_provider
|
||||
* @param environment_results $result
|
||||
*/
|
||||
public function test_environment($result) {
|
||||
$sslmessages = ['ssl/tls configuration not supported', 'invalid ssl/tls configuration'];
|
||||
|
||||
$this->assertNotEmpty($envstatus);
|
||||
foreach ($environment_results as $environment_result) {
|
||||
if ($environment_result->part === 'php_setting'
|
||||
and $environment_result->info === 'opcache.enable'
|
||||
and $environment_result->getLevel() === 'optional'
|
||||
and $environment_result->getStatus() === false
|
||||
) {
|
||||
$this->markTestSkipped('OPCache extension is not necessary for unit testing.');
|
||||
continue;
|
||||
}
|
||||
if ($environment_result->part === 'custom_check'
|
||||
and in_array($environment_result->info, $sslmessages)
|
||||
and $environment_result->getLevel() === 'optional'
|
||||
and $environment_result->getStatus() === false
|
||||
) {
|
||||
$this->markTestSkipped('Up-to-date TLS libraries are not necessary for unit testing.');
|
||||
continue;
|
||||
}
|
||||
$this->assertTrue($environment_result->getStatus(), "Problem detected in environment ($environment_result->part:$environment_result->info), fix all warnings and errors!");
|
||||
if ($result->part === 'php_setting'
|
||||
&& $result->info === 'opcache.enable'
|
||||
&& $result->getLevel() === 'optional'
|
||||
&& $result->getStatus() === false) {
|
||||
$this->markTestSkipped('OPCache extension is not necessary for unit testing.');
|
||||
}
|
||||
|
||||
if ($result->part === 'custom_check'
|
||||
&& $result->getLevel() === 'optional'
|
||||
&& $result->getStatus() === false) {
|
||||
if (in_array($result->info, $sslmessages)) {
|
||||
$this->markTestSkipped('Up-to-date TLS libraries are not necessary for unit testing.');
|
||||
}
|
||||
}
|
||||
$info = "{$result->part}:{$result->info}";
|
||||
$this->assertTrue($result->getStatus(), "Problem detected in environment ($info), fix all warnings and errors!");
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user