diff --git a/lib/classes/encryption.php b/lib/classes/encryption.php index 5ae20478896..6da3c1b009b 100644 --- a/lib/classes/encryption.php +++ b/lib/classes/encryption.php @@ -80,8 +80,8 @@ class encryption { throw new \moodle_exception('encryption_keyalreadyexists', 'error'); } - // Don't make it read-only in Behat or it will fail to clear for future runs. - if (defined('BEHAT_SITE_RUNNING')) { + // Don't make it read-only in tests or it will fail to clear for future runs. + if (defined('BEHAT_SITE_RUNNING') || PHPUNIT_TEST) { $chmod = false; } diff --git a/lib/tests/encryption_test.php b/lib/tests/encryption_test.php index dee650446b3..fa631651968 100644 --- a/lib/tests/encryption_test.php +++ b/lib/tests/encryption_test.php @@ -28,28 +28,8 @@ use advanced_testcase; */ final class encryption_test extends advanced_testcase { - /** - * Clear junk created by tests. - */ - protected function tearDown(): void { - global $CFG; - $keyfile = encryption::get_key_file(encryption::METHOD_OPENSSL); - if (file_exists($keyfile)) { - chmod($keyfile, 0700); - } - $keyfile = encryption::get_key_file(encryption::METHOD_SODIUM); - if (file_exists($keyfile)) { - chmod($keyfile, 0700); - } - remove_dir($CFG->dataroot . '/secret'); - unset($CFG->nokeygeneration); - parent::tearDown(); - } - protected function setUp(): void { parent::setUp(); - $this->tearDown(); - require_once(__DIR__ . '/fixtures/testable_encryption.php'); }