mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
MDL-40909 enrol_imsenterprise: removed 'new' add_to_log call
Here we are replacing the unnecessary code used to create a course with a call to create_course(), which triggers the event 'course_created'. Nothing more is needed.
This commit is contained in:
parent
f1f4f4fd7b
commit
7cbb5070f5
@ -26,8 +26,9 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot.'/course/lib.php');
|
||||
require_once($CFG->dirroot.'/course/tests/fixtures/course_capability_assignment.php');
|
||||
require_once($CFG->dirroot . '/course/lib.php');
|
||||
require_once($CFG->dirroot . '/course/tests/fixtures/course_capability_assignment.php');
|
||||
require_once($CFG->dirroot . '/enrol/imsenterprise/tests/imsenterprise_test.php');
|
||||
|
||||
class core_course_courselib_testcase extends advanced_testcase {
|
||||
|
||||
@ -1400,8 +1401,10 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
// Catch the events.
|
||||
$sink = $this->redirectEvents();
|
||||
|
||||
// Create the course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
// Create the course with an id number which is used later when generating a course via the imsenterprise plugin.
|
||||
$data = new stdClass();
|
||||
$data->idnumber = 'idnumber';
|
||||
$course = $this->getDataGenerator()->create_course($data);
|
||||
// Get course from DB for comparison.
|
||||
$course = $DB->get_record('course', array('id' => $course->id));
|
||||
|
||||
@ -1420,6 +1423,32 @@ class core_course_courselib_testcase extends advanced_testcase {
|
||||
$this->assertEventLegacyData($course, $event);
|
||||
$expectedlog = array(SITEID, 'course', 'new', 'view.php?id=' . $course->id, $course->fullname . ' (ID ' . $course->id . ')');
|
||||
$this->assertEventLegacyLogData($expectedlog, $event);
|
||||
|
||||
// Now we want to trigger creating a course via the imsenterprise.
|
||||
// Delete the course we created earlier, as we want the imsenterprise plugin to create this.
|
||||
// We do not want print out any of the text this function generates while doing this, which is why
|
||||
// we are using ob_start() and ob_end_clean().
|
||||
ob_start();
|
||||
delete_course($course);
|
||||
ob_end_clean();
|
||||
|
||||
// Create the XML file we want to use.
|
||||
$imstestcase = new enrol_imsenterprise_testcase();
|
||||
$imstestcase->imsplugin = enrol_get_plugin('imsenterprise');
|
||||
$imstestcase->set_test_config();
|
||||
$imstestcase->set_xml_file(false, array($course));
|
||||
|
||||
// Capture the event.
|
||||
$sink = $this->redirectEvents();
|
||||
$imstestcase->imsplugin->cron();
|
||||
$events = $sink->get_events();
|
||||
$sink->close();
|
||||
$event = $events[0];
|
||||
|
||||
// Validate the event triggered is \core\event\course_created. There is no need to validate the other values
|
||||
// as they have already been validated in the previous steps. Here we only want to make sure that when the
|
||||
// imsenterprise plugin creates a course an event is triggered.
|
||||
$this->assertInstanceOf('\core\event\course_created', $event);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -377,24 +377,11 @@ class enrol_imsenterprise_plugin extends enrol_plugin {
|
||||
} else {
|
||||
$course->category = $this->get_default_category_id();
|
||||
}
|
||||
$course->timecreated = time();
|
||||
$course->startdate = time();
|
||||
// Choose a sort order that puts us at the start of the list!
|
||||
$course->sortorder = 0;
|
||||
$courseid = $DB->insert_record('course', $course);
|
||||
|
||||
// Setup default enrolment plugins.
|
||||
$course->id = $courseid;
|
||||
enrol_course_updated(true, $course, null);
|
||||
|
||||
// Setup the blocks.
|
||||
$course = $DB->get_record('course', array('id' => $courseid));
|
||||
blocks_add_default_course_blocks($course);
|
||||
|
||||
// Create default 0-section.
|
||||
course_create_sections_if_missing($course, 0);
|
||||
|
||||
add_to_log(SITEID, "course", "new", "view.php?id=$course->id", "$course->fullname (ID $course->id)");
|
||||
$course = create_course($course);
|
||||
|
||||
$this->log_line("Created course $coursecode in Moodle (Moodle ID is $course->id)");
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
/**
|
||||
* @var $imsplugin enrol_imsenterprise_plugin IMS plugin instance.
|
||||
*/
|
||||
protected $imsplugin;
|
||||
public $imsplugin;
|
||||
|
||||
/**
|
||||
* Setup required for all tests.
|
||||
@ -254,7 +254,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
/**
|
||||
* Sets the plugin configuration for testing
|
||||
*/
|
||||
protected function set_test_config() {
|
||||
public function set_test_config() {
|
||||
$this->imsplugin->set_config('mailadmins', false);
|
||||
$this->imsplugin->set_config('prev_path', '');
|
||||
$this->imsplugin->set_config('createnewusers', true);
|
||||
@ -268,7 +268,7 @@ class enrol_imsenterprise_testcase extends advanced_testcase {
|
||||
* @param bool|array $users false or array of users StdClass
|
||||
* @param bool|array $courses false or of courses StdClass
|
||||
*/
|
||||
protected function set_xml_file($users = false, $courses = false) {
|
||||
public function set_xml_file($users = false, $courses = false) {
|
||||
|
||||
$xmlcontent = '<enterprise>';
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user