diff --git a/enrol/tests/enrollib_special_test.php b/enrol/tests/enrollib_special_test.php deleted file mode 100644 index 132bda15274..00000000000 --- a/enrol/tests/enrollib_special_test.php +++ /dev/null @@ -1,93 +0,0 @@ -. - -/** - * Test plugin enrollib parts. - * - * @package core_enrol - * @category test - * @copyright 2017 Darko Miletic - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - - -/** - * Test plugin enrollib parts. - * - * @package core - * @category test - * @copyright 2017 Darko Miletic - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -class core_enrollib_special_testcase extends advanced_testcase { - - /** - * Confirms that timemodified field was updated after modification of user enrollment - */ - public function test_enrollment_update_timemodified() { - global $DB; - - $this->resetAfterTest(true); - $datagen = $this->getDataGenerator(); - - /** @var enrol_manual_plugin $manualplugin */ - $manualplugin = enrol_get_plugin('manual'); - $this->assertNotNull($manualplugin); - - $studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student'], MUST_EXIST); - $course = $datagen->create_course(); - $user = $datagen->create_user(); - - $instanceid = null; - $instances = enrol_get_instances($course->id, true); - foreach ($instances as $inst) { - if ($inst->enrol == 'manual') { - $instanceid = (int)$inst->id; - break; - } - } - if (empty($instanceid)) { - $instanceid = $manualplugin->add_default_instance($course); - if (empty($instanceid)) { - $instanceid = $manualplugin->add_instance($course); - } - } - $this->assertNotNull($instanceid); - - $instance = $DB->get_record('enrol', ['id' => $instanceid], '*', MUST_EXIST); - $manualplugin->enrol_user($instance, $user->id, $studentroleid, 0, 0, ENROL_USER_ACTIVE); - $userenrolorig = (int)$DB->get_field( - 'user_enrolments', - 'timemodified', - ['enrolid' => $instance->id, 'userid' => $user->id], - MUST_EXIST - ); - $this->waitForSecond(); - $this->waitForSecond(); - $manualplugin->update_user_enrol($instance, $user->id, ENROL_USER_SUSPENDED); - $userenrolpost = (int)$DB->get_field( - 'user_enrolments', - 'timemodified', - ['enrolid' => $instance->id, 'userid' => $user->id], - MUST_EXIST - ); - - $this->assertGreaterThan($userenrolorig, $userenrolpost); - } - -} diff --git a/enrol/tests/enrollib_test.php b/enrol/tests/enrollib_test.php index 0355f130bb9..b3dcfc1df17 100644 --- a/enrol/tests/enrollib_test.php +++ b/enrol/tests/enrollib_test.php @@ -422,4 +422,58 @@ class core_enrollib_testcase extends advanced_testcase { $this->assertEquals('self', $event->other['enrol']); $this->assertEventContextNotUsed($event); } + + /** + * Confirms that timemodified field was updated after modification of user enrollment + */ + public function test_enrollment_update_timemodified() { + global $DB; + + $this->resetAfterTest(true); + $datagen = $this->getDataGenerator(); + + /** @var enrol_manual_plugin $manualplugin */ + $manualplugin = enrol_get_plugin('manual'); + $this->assertNotNull($manualplugin); + + $studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student'], MUST_EXIST); + $course = $datagen->create_course(); + $user = $datagen->create_user(); + + $instanceid = null; + $instances = enrol_get_instances($course->id, true); + foreach ($instances as $inst) { + if ($inst->enrol == 'manual') { + $instanceid = (int)$inst->id; + break; + } + } + if (empty($instanceid)) { + $instanceid = $manualplugin->add_default_instance($course); + if (empty($instanceid)) { + $instanceid = $manualplugin->add_instance($course); + } + } + $this->assertNotNull($instanceid); + + $instance = $DB->get_record('enrol', ['id' => $instanceid], '*', MUST_EXIST); + $manualplugin->enrol_user($instance, $user->id, $studentroleid, 0, 0, ENROL_USER_ACTIVE); + $userenrolorig = (int)$DB->get_field( + 'user_enrolments', + 'timemodified', + ['enrolid' => $instance->id, 'userid' => $user->id], + MUST_EXIST + ); + $this->waitForSecond(); + $this->waitForSecond(); + $manualplugin->update_user_enrol($instance, $user->id, ENROL_USER_SUSPENDED); + $userenrolpost = (int)$DB->get_field( + 'user_enrolments', + 'timemodified', + ['enrolid' => $instance->id, 'userid' => $user->id], + MUST_EXIST + ); + + $this->assertGreaterThan($userenrolorig, $userenrolpost); + } }