forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-59811 enrol: Unit tests for get_user_enrolment_actions()
- Loading branch information
1 parent
d8e9a23
commit 18000c6
Showing
8 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Database enrolment tests. | ||
* | ||
* @package enrol_database | ||
* @copyright 2017 Jun Pataleta | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
|
||
/** | ||
* Database enrolment tests. | ||
* | ||
* @package enrol_database | ||
* @copyright 2017 Jun Pataleta | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class enrol_database_lib_testcase extends advanced_testcase { | ||
/** | ||
* Test for getting user enrolment actions. | ||
*/ | ||
public function test_get_user_enrolment_actions() { | ||
global $CFG, $PAGE; | ||
$this->resetAfterTest(); | ||
|
||
// Set page URL to prevent debugging messages. | ||
$PAGE->set_url('/enrol/editinstance.php'); | ||
|
||
$pluginname = 'database'; | ||
|
||
// Only enable the database enrol plugin. | ||
$CFG->enrol_plugins_enabled = $pluginname; | ||
|
||
$generator = $this->getDataGenerator(); | ||
|
||
// Get the enrol plugin. | ||
$plugin = enrol_get_plugin($pluginname); | ||
|
||
// Create a course. | ||
$course = $generator->create_course(); | ||
// Enable this enrol plugin for the course. | ||
$plugin->add_instance($course); | ||
|
||
// Create a student. | ||
$student = $generator->create_user(); | ||
// Enrol the student to the course. | ||
$generator->enrol_user($student->id, $course->id, 'student', $pluginname); | ||
|
||
// Teachers don't have enrol/database:unenrol capability by default. Login as admin for simplicity. | ||
$this->setAdminUser(); | ||
require_once($CFG->dirroot . '/enrol/locallib.php'); | ||
$manager = new course_enrolment_manager($PAGE, $course); | ||
$userenrolments = $manager->get_user_enrolments($student->id); | ||
$this->assertCount(1, $userenrolments); | ||
|
||
$ue = reset($userenrolments); | ||
$actions = $plugin->get_user_enrolment_actions($manager, $ue); | ||
// Database enrol has 0 enrol actions for active users. | ||
$this->assertCount(0, $actions); | ||
|
||
// Enrol actions for a suspended student. | ||
// Suspend the student. | ||
$ue->status = ENROL_USER_SUSPENDED; | ||
|
||
$actions = $plugin->get_user_enrolment_actions($manager, $ue); | ||
// Database enrol has enrol actions for suspended students -- unenrol. | ||
$this->assertCount(1, $actions); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.