MDL-55609 mod_assign: Remove shared setUp for all tests

This commit is contained in:
Andrew Nicols
2018-06-01 07:33:12 +08:00
parent 5e3bc5f34f
commit aea6fc7e83
7 changed files with 3102 additions and 2138 deletions
+255 -148
View File
@@ -25,7 +25,7 @@
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
require_once($CFG->dirroot . '/mod/assign/tests/generator.php');
require_once($CFG->dirroot . '/mod/assign/tests/fixtures/event_mod_assign_fixtures.php');
require_once($CFG->dirroot . '/mod/assign/locallib.php');
@@ -36,20 +36,25 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
* @copyright 2014 Adrian Greeve <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assign_events_testcase extends mod_assign_base_testcase {
class assign_events_testcase extends advanced_testcase {
// Use the generator helper.
use mod_assign_test_generator;
/**
* Basic tests for the submission_created() abstract class.
*/
public function test_base_event() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$instance = $generator->create_instance(array('course' => $course->id));
$modcontext = context_module::instance($instance->cmid);
$data = array(
'context' => $modcontext,
);
/** @var \mod_assign_unittests\event\nothing_happened $event */
$event = \mod_assign_unittests\event\nothing_happened::create($data);
$assign = $event->get_assign();
$this->assertDebuggingCalled();
@@ -66,14 +71,17 @@ class assign_events_testcase extends mod_assign_base_testcase {
* Basic tests for the submission_created() abstract class.
*/
public function test_submission_created() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$instance = $generator->create_instance(array('course' => $course->id));
$modcontext = context_module::instance($instance->cmid);
// Standard Event parameters.
$params = array(
'context' => $modcontext,
'courseid' => $this->course->id
'courseid' => $course->id
);
$eventinfo = $params;
@@ -91,7 +99,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$sink->close();
$this->assertEquals($modcontext->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
$this->assertEquals($course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
@@ -123,14 +131,17 @@ class assign_events_testcase extends mod_assign_base_testcase {
* Basic tests for the submission_updated() abstract class.
*/
public function test_submission_updated() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance(array('course' => $this->course->id));
$instance = $generator->create_instance(array('course' => $course->id));
$modcontext = context_module::instance($instance->cmid);
// Standard Event parameters.
$params = array(
'context' => $modcontext,
'courseid' => $this->course->id
'courseid' => $course->id
);
$eventinfo = $params;
@@ -148,7 +159,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$sink->close();
$this->assertEquals($modcontext->id, $event->contextid);
$this->assertEquals($this->course->id, $event->courseid);
$this->assertEquals($course->id, $event->courseid);
// Check that an error occurs when teamsubmission is not set.
try {
@@ -177,15 +188,25 @@ class assign_events_testcase extends mod_assign_base_testcase {
}
public function test_extension_granted() {
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$tomorrow = time() + 24*60*60;
$yesterday = time() - 24*60*60;
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance(array('duedate' => $yesterday, 'cutoffdate' => $yesterday));
$this->setUser($teacher);
$now = time();
$tomorrow = $now + DAYSECS;
$yesterday = $now - DAYSECS;
$assign = $this->create_instance($course, [
'duedate' => $yesterday,
'cutoffdate' => $yesterday,
]);
$sink = $this->redirectEvents();
$assign->testable_save_user_extension($this->students[0]->id, $tomorrow);
$assign->testable_save_user_extension($student->id, $tomorrow);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -193,13 +214,14 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\extension_granted', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'grant extension',
'view.php?id=' . $assign->get_course_module()->id,
$this->students[0]->id,
$student->id,
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -207,13 +229,19 @@ class assign_events_testcase extends mod_assign_base_testcase {
}
public function test_submission_locked() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course);
$sink = $this->redirectEvents();
$assign->lock_submission($this->students[0]->id);
$assign->lock_submission($student->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -221,28 +249,30 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_locked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'lock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('locksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
get_string('locksubmissionforstudent', 'assign', array('id' => $student->id,
'fullname' => fullname($student))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_identities_revealed() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance(array('blindmarking'=>1));
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course, ['blindmarking' => 1]);
$sink = $this->redirectEvents();
$assign->reveal_identities();
@@ -263,9 +293,6 @@ class assign_events_testcase extends mod_assign_base_testcase {
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
/**
@@ -273,10 +300,14 @@ class assign_events_testcase extends mod_assign_base_testcase {
*/
public function test_submission_status_viewed() {
global $PAGE;
$this->resetAfterTest();
$this->setUser($this->editingteachers[0]);
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$assign = $this->create_instance();
$this->setUser($teacher);
$assign = $this->create_instance($course);
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
@@ -304,16 +335,21 @@ class assign_events_testcase extends mod_assign_base_testcase {
}
public function test_submission_status_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($teacher);
$assign = $this->create_instance($course);
$submission = $assign->get_user_submission($student->id, true);
$submission->status = ASSIGN_SUBMISSION_STATUS_SUBMITTED;
$assign->testable_update_submission($submission, $this->students[0]->id, true, false);
$assign->testable_update_submission($submission, $student->id, true, false);
$sink = $this->redirectEvents();
$assign->revert_to_draft($this->students[0]->id);
$assign->revert_to_draft($student->id);
$events = $sink->get_events();
$this->assertCount(2, $events);
@@ -321,32 +357,35 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_status_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$this->assertEquals(ASSIGN_SUBMISSION_STATUS_DRAFT, $event->other['newstatus']);
$expected = array(
$assign->get_course()->id,
'assign',
'revert submission to draft',
'view.php?id=' . $assign->get_course_module()->id,
get_string('reverttodraftforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
get_string('reverttodraftforstudent', 'assign', array('id' => $student->id,
'fullname' => fullname($student))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_marker_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course);
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_allocation($this->students[0]->id, $this->teachers[0]->id);
$assign->testable_process_set_batch_marking_allocation($student->id, $teacher->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -354,34 +393,37 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\marker_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($this->teachers[0]->id, $event->other['markerid']);
$this->assertEquals($student->id, $event->relateduserid);
$this->assertEquals($teacher->id, $event->userid);
$this->assertEquals($teacher->id, $event->other['markerid']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking allocation',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkerallocationforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'marker' => fullname($this->teachers[0]))),
get_string('setmarkerallocationforlog', 'assign', array('id' => $student->id,
'fullname' => fullname($student), 'marker' => fullname($teacher))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_workflow_state_updated() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course);
// Test process_set_batch_marking_workflow_state.
$sink = $this->redirectEvents();
$assign->testable_process_set_batch_marking_workflow_state($this->students[0]->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
$assign->testable_process_set_batch_marking_workflow_state($student->id, ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -389,16 +431,16 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($student->id, $event->relateduserid);
$this->assertEquals($teacher->id, $event->userid);
$this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW, $event->other['newstate']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $student->id,
'fullname' => fullname($student), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INREVIEW)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -409,7 +451,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$data = new stdClass();
$data->grade = '50.0';
$data->workflowstate = 'readyforrelease';
$assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
$assign->testable_apply_grade_to_user($data, $student->id, 0);
$events = $sink->get_events();
$this->assertCount(4, $events);
@@ -417,16 +459,16 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($student->id, $event->relateduserid);
$this->assertEquals($teacher->id, $event->userid);
$this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE, $event->other['newstate']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE)),
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $student->id,
'fullname' => fullname($student), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_READYFORRELEASE)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -436,10 +478,10 @@ class assign_events_testcase extends mod_assign_base_testcase {
$sink = $this->redirectEvents();
$data = array(
'grademodified_' . $this->students[0]->id => time(),
'gradeattempt_' . $this->students[0]->id => '',
'quickgrade_' . $this->students[0]->id => '60.0',
'quickgrade_' . $this->students[0]->id . '_workflowstate' => 'inmarking'
'grademodified_' . $student->id => time(),
'gradeattempt_' . $student->id => '',
'quickgrade_' . $student->id => '60.0',
'quickgrade_' . $student->id . '_workflowstate' => 'inmarking'
);
$assign->testable_process_save_quick_grades($data);
@@ -449,33 +491,35 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\workflow_state_updated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($this->editingteachers[0]->id, $event->userid);
$this->assertEquals($student->id, $event->relateduserid);
$this->assertEquals($teacher->id, $event->userid);
$this->assertEquals(ASSIGN_MARKING_WORKFLOW_STATE_INMARKING, $event->other['newstate']);
$expected = array(
$assign->get_course()->id,
'assign',
'set marking workflow state',
'view.php?id=' . $assign->get_course_module()->id,
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INMARKING)),
get_string('setmarkingworkflowstateforlog', 'assign', array('id' => $student->id,
'fullname' => fullname($student), 'state' => ASSIGN_MARKING_WORKFLOW_STATE_INMARKING)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_duplicated() {
$this->setUser($this->students[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$submission1 = $assign->get_user_submission($this->students[0]->id, true, 0);
$submission2 = $assign->get_user_submission($this->students[0]->id, true, 1);
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($student);
$assign = $this->create_instance($course);
$submission1 = $assign->get_user_submission($student->id, true, 0);
$submission2 = $assign->get_user_submission($student->id, true, 1);
$submission2->status = ASSIGN_SUBMISSION_STATUS_REOPENED;
$assign->testable_update_submission($submission2, $this->students[0]->id, time(), $assign->get_instance()->teamsubmission);
$assign->testable_update_submission($submission2, $student->id, time(), $assign->get_instance()->teamsubmission);
$sink = $this->redirectEvents();
$notices = null;
@@ -487,7 +531,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_duplicated', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($submission2->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->userid);
$this->assertEquals($student->id, $event->userid);
$submission2->status = ASSIGN_SUBMISSION_STATUS_DRAFT;
$expected = array(
$assign->get_course()->id,
@@ -502,13 +546,19 @@ class assign_events_testcase extends mod_assign_base_testcase {
}
public function test_submission_unlocked() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course);
$sink = $this->redirectEvents();
$assign->unlock_submission($this->students[0]->id);
$assign->unlock_submission($student->id);
$events = $sink->get_events();
$this->assertCount(1, $events);
@@ -516,35 +566,39 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_unlocked', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($assign->get_instance()->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
'unlock submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('unlocksubmissionforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
get_string('unlocksubmissionforstudent', 'assign', array('id' => $student->id,
'fullname' => fullname($student))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
public function test_submission_graded() {
$this->editingteachers[0]->ignoresesskey = true;
$this->setUser($this->editingteachers[0]);
$assign = $this->create_instance();
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$teacher->ignoresesskey = true;
$this->setUser($teacher);
$assign = $this->create_instance($course);
// Test apply_grade_to_user.
$sink = $this->redirectEvents();
$data = new stdClass();
$data->grade = '50.0';
$assign->testable_apply_grade_to_user($data, $this->students[0]->id, 0);
$grade = $assign->get_user_grade($this->students[0]->id, false, 0);
$assign->testable_apply_grade_to_user($data, $student->id, 0);
$grade = $assign->get_user_grade($student->id, false, 0);
$events = $sink->get_events();
$this->assertCount(3, $events);
@@ -552,7 +606,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
@@ -567,14 +621,14 @@ class assign_events_testcase extends mod_assign_base_testcase {
// Test process_save_quick_grades.
$sink = $this->redirectEvents();
$grade = $assign->get_user_grade($this->students[0]->id, false);
$grade = $assign->get_user_grade($student->id, false);
$data = array(
'grademodified_' . $this->students[0]->id => time(),
'gradeattempt_' . $this->students[0]->id => $grade->attemptnumber,
'quickgrade_' . $this->students[0]->id => '60.0'
'grademodified_' . $student->id => time(),
'gradeattempt_' . $student->id => $grade->attemptnumber,
'quickgrade_' . $student->id => '60.0'
);
$assign->testable_process_save_quick_grades($data);
$grade = $assign->get_user_grade($this->students[0]->id, false);
$grade = $assign->get_user_grade($student->id, false);
$this->assertEquals('60.0', $grade->grade);
$events = $sink->get_events();
@@ -583,7 +637,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
@@ -600,7 +654,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$data = clone($grade);
$data->grade = '50.0';
$assign->update_grade($data);
$grade = $assign->get_user_grade($this->students[0]->id, false, 0);
$grade = $assign->get_user_grade($student->id, false, 0);
$this->assertEquals('50.0', $grade->grade);
$events = $sink->get_events();
@@ -609,7 +663,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
$this->assertInstanceOf('\mod_assign\event\submission_graded', $event);
$this->assertEquals($assign->get_context(), $event->get_context());
$this->assertEquals($grade->id, $event->objectid);
$this->assertEquals($this->students[0]->id, $event->relateduserid);
$this->assertEquals($student->id, $event->relateduserid);
$expected = array(
$assign->get_course()->id,
'assign',
@@ -620,8 +674,6 @@ class assign_events_testcase extends mod_assign_base_testcase {
);
$this->assertEventLegacyLogData($expected, $event);
$sink->close();
// Revert to defaults.
$this->editingteachers[0]->ignoresesskey = false;
}
/**
@@ -630,10 +682,16 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_submission_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($teacher);
$assign = $this->create_instance($course);
$submission = $assign->get_user_submission($student->id, true);
// We need to set the URL in order to view the submission.
$PAGE->set_url('/a_url');
@@ -659,7 +717,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
'assign',
'view submission',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewsubmissionforuser', 'assign', $this->students[0]->id),
get_string('viewsubmissionforuser', 'assign', $student->id),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -672,15 +730,21 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_feedback_viewed() {
global $DB, $PAGE;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$submission = $assign->get_user_submission($this->students[0]->id, true);
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($teacher);
$assign = $this->create_instance($course);
$submission = $assign->get_user_submission($student->id, true);
// Insert a grade for this submission.
$grade = new stdClass();
$grade->assignment = $assign->get_instance()->id;
$grade->userid = $this->students[0]->id;
$grade->userid = $student->id;
$gradeid = $DB->insert_record('assign_grades', $grade);
// We need to set the URL in order to view the feedback.
@@ -708,7 +772,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
'assign',
'view feedback',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewfeedbackforuser', 'assign', $this->students[0]->id),
get_string('viewfeedbackforuser', 'assign', $student->id),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -721,16 +785,22 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_grading_form_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($teacher);
$assign = $this->create_instance($course);
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// A hack - this variable is used by the view_single_grade_page function.
global $_POST;
$_POST['rownum'] = 1;
$_POST['userid'] = $this->students[0]->id;
$_POST['userid'] = $student->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
@@ -747,8 +817,8 @@ class assign_events_testcase extends mod_assign_base_testcase {
'assign',
'view grading form',
'view.php?id=' . $assign->get_course_module()->id,
get_string('viewgradingformforstudent', 'assign', array('id' => $this->students[0]->id,
'fullname' => fullname($this->students[0]))),
get_string('viewgradingformforstudent', 'assign', array('id' => $student->id,
'fullname' => fullname($student))),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -761,16 +831,22 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_grading_table_viewed() {
global $PAGE;
$this->setUser($this->editingteachers[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'editingteacher');
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($teacher);
$assign = $this->create_instance($course);
// We need to set the URL in order to view the feedback.
$PAGE->set_url('/a_url');
// A hack - this variable is used by the view_single_grade_page function.
global $_POST;
$_POST['rownum'] = 1;
$_POST['userid'] = $this->students[0]->id;
$_POST['userid'] = $student->id;
// Trigger and capture the event.
$sink = $this->redirectEvents();
@@ -800,9 +876,14 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_submission_form_viewed() {
global $PAGE;
$this->setUser($this->students[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($student);
$assign = $this->create_instance($course);
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
@@ -835,9 +916,14 @@ class assign_events_testcase extends mod_assign_base_testcase {
public function test_submission_confirmation_form_viewed() {
global $PAGE;
$this->setUser($this->students[0]);
$this->resetAfterTest();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($student);
$assign = $this->create_instance($course);
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
@@ -869,11 +955,13 @@ class assign_events_testcase extends mod_assign_base_testcase {
*/
public function test_reveal_identities_confirmation_page_viewed() {
global $PAGE;
$this->resetAfterTest();
// Set to the admin user so we have the permission to reveal identities.
$this->setAdminUser();
$assign = $this->create_instance();
$course = $this->getDataGenerator()->create_course();
$assign = $this->create_instance($course);
// We need to set the URL in order to view the submission form.
$PAGE->set_url('/a_url');
@@ -905,12 +993,17 @@ class assign_events_testcase extends mod_assign_base_testcase {
*/
public function test_statement_accepted() {
// We want to be a student so we can submit assignments.
$this->setUser($this->students[0]);
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$this->setUser($student);
// We do not want to send any messages to the student during the PHPUNIT test.
set_config('submissionreceipts', false, 'assign');
$assign = $this->create_instance();
$assign = $this->create_instance($course);
// Create the data we want to pass to the submit_for_grading function.
$data = new stdClass();
@@ -933,7 +1026,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
'view.php?id=' . $assign->get_course_module()->id,
get_string('submissionstatementacceptedlog',
'mod_assign',
fullname($this->students[0])),
fullname($student)),
$assign->get_course_module()->id
);
$this->assertEventLegacyLogData($expected, $event);
@@ -975,11 +1068,15 @@ class assign_events_testcase extends mod_assign_base_testcase {
* Test the batch_set_workflow_state_viewed event.
*/
public function test_batch_set_workflow_state_viewed() {
$assign = $this->create_instance();
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_set_workflow_state($this->students[0]->id);
$assign->testable_view_batch_set_workflow_state($student->id);
$events = $sink->get_events();
$event = reset($events);
@@ -1002,11 +1099,15 @@ class assign_events_testcase extends mod_assign_base_testcase {
* Test the batch_set_marker_allocation_viewed event.
*/
public function test_batch_set_marker_allocation_viewed() {
$assign = $this->create_instance();
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$student = $this->getDataGenerator()->create_and_enrol($course, 'student');
$assign = $this->create_instance($course);
// Trigger and capture the event.
$sink = $this->redirectEvents();
$assign->testable_view_batch_markingallocation($this->students[0]->id);
$assign->testable_view_batch_markingallocation($student->id);
$events = $sink->get_events();
$event = reset($events);
@@ -1032,9 +1133,10 @@ class assign_events_testcase extends mod_assign_base_testcase {
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_user_override_created() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$assign = $this->getDataGenerator()->get_plugin_generator('mod_assign')->create_instance(['course' => $course->id]);
$params = array(
'objectid' => 1,
@@ -1065,9 +1167,10 @@ class assign_events_testcase extends mod_assign_base_testcase {
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_group_override_created() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$assign = $this->getDataGenerator()->get_plugin_generator('mod_assign')->create_instance(['course' => $course->id]);
$params = array(
'objectid' => 1,
@@ -1098,9 +1201,10 @@ class assign_events_testcase extends mod_assign_base_testcase {
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_user_override_updated() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$assign = $this->getDataGenerator()->get_plugin_generator('mod_assign')->create_instance(['course' => $course->id]);
$params = array(
'objectid' => 1,
@@ -1131,9 +1235,10 @@ class assign_events_testcase extends mod_assign_base_testcase {
* create and trigger the event and ensure the event data is returned as expected.
*/
public function test_group_override_updated() {
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assign = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
$assign = $this->getDataGenerator()->get_plugin_generator('mod_assign')->create_instance(['course' => $course->id]);
$params = array(
'objectid' => 1,
@@ -1162,6 +1267,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
*/
public function test_user_override_deleted() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assigninstance = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
@@ -1192,6 +1298,7 @@ class assign_events_testcase extends mod_assign_base_testcase {
*/
public function test_group_override_deleted() {
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$assigninstance = $this->getDataGenerator()->create_module('assign', array('course' => $course->id));
+1 -8
View File
@@ -19,6 +19,7 @@ defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/webservice/tests/helpers.php');
require_once($CFG->dirroot . '/mod/assign/externallib.php');
/**
* External mod assign functions unit tests
@@ -30,14 +31,6 @@ require_once($CFG->dirroot . '/webservice/tests/helpers.php');
*/
class mod_assign_external_testcase extends externallib_advanced_testcase {
/**
* Tests set up
*/
protected function setUp() {
global $CFG;
require_once($CFG->dirroot . '/mod/assign/externallib.php');
}
/**
* Test get_grades
*/
+131
View File
@@ -0,0 +1,131 @@
<?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/>.
/**
* Base class for unit tests for mod_assign.
*
* @package mod_assign
* @category phpunit
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once(__DIR__ . '/fixtures/testable_assign.php');
/**
* Generator helper trait.
*
* @copyright 2018 Andrew Nicols <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
trait mod_assign_test_generator {
/**
* Convenience function to create a testable instance of an assignment.
*
* @param array $params Array of parameters to pass to the generator
* @return testable_assign Testable wrapper around the assign class.
*/
protected function create_instance($course, $params = [], $options = []) {
$params['course'] = $course->id;
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
$instance = $generator->create_instance($params, $options);
$cm = get_coursemodule_from_instance('assign', $instance->id);
$context = context_module::instance($cm->id);
return new mod_assign_testable_assign($context, $cm, $course);
}
/**
* Add a user submission to the assignment.
*
* @param \stdClass $student The user to submit for
* @param \assign $assign The assignment to submit to
* @param string $onlinetext The text tobe submitted
* @param bool $changeuser Whether to switch user to the user being submitted as.
*/
protected function add_submission($student, $assign, $onlinetext = null, $changeuser = true) {
// Add a submission.
if ($changeuser) {
$this->setUser($student);
}
if ($onlinetext === null) {
$onlinetext = 'Submission text';
}
$data = (object) [
'userid' => $student->id,
'onlinetext_editor' => [
'itemid' => file_get_unused_draft_itemid(),
'text' => $onlinetext,
'format' => FORMAT_HTML,
]
];
$assign->save_submission($data, $notices);
}
/**
* Submit the assignemnt for grading.
*
* @param \stdClass $student The user to submit for
* @param \assign $assign The assignment to submit to
* @param array $data Additional data to set
* @param bool $changeuser Whether to switch user to the user being submitted as.
*/
public function submit_for_grading($student, $assign, $data = [], $changeuser = true) {
if ($changeuser) {
$this->setUser($student);
}
$data = (object) array_merge($data, [
'userid' => $student->id,
]);
$sink = $this->redirectMessages();
$assign->submit_for_grading($data, []);
$sink->close();
return $data;
}
/**
* Mark the submission.
*
* @param \stdClass $teacher The user to mark as
* @param \assign $assign The assignment to mark
* @param \stdClass $student The user to grade
* @param array $data Additional data to set
* @param bool $changeuser Whether to switch user to the user being submitted as.
*/
protected function mark_submission($teacher, $assign, $student, $grade = 50.0, $data = [], $attempt = 0) {
// Mark the submission.
$this->setUser($teacher);
$data = (object) array_merge($data, [
'grade' => $grade,
]);
$assign->testable_apply_grade_to_user($data, $student->id, $attempt);
}
}
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+9 -16
View File
@@ -39,21 +39,6 @@ require_once($CFG->dirroot . '/mod/assign/locallib.php');
*/
class mod_assign_search_testcase extends advanced_testcase {
/**
* @var string Area id
*/
protected $assignareaid = null;
public function setUp() {
$this->resetAfterTest(true);
set_config('enableglobalsearch', true);
$this->assignareaid = \core_search\manager::generate_areaid('mod_assign', 'activity');
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
}
/**
* Test for assign file attachments.
*
@@ -62,6 +47,14 @@ class mod_assign_search_testcase extends advanced_testcase {
public function test_attach_files() {
global $USER;
$this->resetAfterTest(true);
set_config('enableglobalsearch', true);
$assignareaid = \core_search\manager::generate_areaid('mod_assign', 'activity');
// Set \core_search::instance to the mock_search_engine as we don't require the search engine to be working to test this.
$search = testable_core_search::instance();
$this->setAdminUser();
// Setup test data.
$course = $this->getDataGenerator()->create_course();
@@ -96,7 +89,7 @@ class mod_assign_search_testcase extends advanced_testcase {
$fs->create_file_from_string($filerecord, 'Test assign file 5');
// Returns the instance as long as the area is supported.
$searcharea = \core_search\manager::get_search_area($this->assignareaid);
$searcharea = \core_search\manager::get_search_area($assignareaid);
$this->assertInstanceOf('\mod_assign\search\activity', $searcharea);
$recordset = $searcharea->get_recordset_by_timestamp(0);
+86 -153
View File
@@ -30,7 +30,6 @@ global $CFG;
require_once($CFG->dirroot . '/mod/assign/locallib.php');
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
require_once($CFG->dirroot . '/mod/assignment/lib.php');
require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
/**
* Unit tests for (some of) mod/assign/upgradelib.php.
@@ -38,181 +37,115 @@ require_once($CFG->dirroot . '/mod/assign/tests/base_test.php');
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class mod_assign_upgradelib_testcase extends mod_assign_base_testcase {
class mod_assign_upgradelib_testcase extends advanced_testcase {
public function test_upgrade_upload_assignment() {
global $DB, $CFG;
$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;
$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'upload');
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $this->course);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('file');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('file');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());
$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
/**
* Data provider for assignment upgrade.
*
* @return array
*/
public function assignment_upgrade_provider() {
return [
'upload' => [
'type' => 'upload',
'submissionplugins' => [
'onlinetext' => true,
'comments' => true,
'file' => false,
],
'feedbackplugins' => [
'comments' => false,
'file' => false,
'offline' => true,
],
],
'uploadsingle' => [
'type' => 'uploadsingle',
'submissionplugins' => [
'onlinetext' => true,
'comments' => true,
'file' => false,
],
'feedbackplugins' => [
'comments' => false,
'file' => false,
'offline' => true,
],
],
'online' => [
'type' => 'online',
'submissionplugins' => [
'onlinetext' => false,
'comments' => true,
'file' => true,
],
'feedbackplugins' => [
'comments' => false,
'file' => true,
'offline' => true,
],
],
'offline' => [
'type' => 'offline',
'submissionplugins' => [
'onlinetext' => true,
'comments' => true,
'file' => true,
],
'feedbackplugins' => [
'comments' => false,
'file' => true,
'offline' => true,
],
],
];
}
public function test_upgrade_uploadsingle_assignment() {
/**
* Test assigment upgrade.
*
* @dataProvider assignment_upgrade_provider
* @param string $type The type of assignment
* @param array $plugins Which plugins shuld or shoudl not be enabled
*/
public function test_upgrade_assignment($type, $plugins) {
global $DB, $CFG;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$teacher = $this->getDataGenerator()->create_and_enrol($course, 'teacher');
$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;
$this->setUser($this->editingteachers[0]);
// Create the old assignment.
$this->setUser($teacher);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'uploadsingle');
$assignment = $generator->create_instance($params);
$assignment = $generator->create_instance([
'course' => $course->id,
'assignmenttype' => $type,
]);
// Run the upgrade.
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$record = $DB->get_record('assign', ['course' => $course->id]);
$cm = get_coursemodule_from_instance('assign', $record->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $this->course);
$assign = new assign($context, $cm, $course);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('file');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('file');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());
$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}
public function test_upgrade_onlinetext_assignment() {
global $DB, $CFG;
$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
foreach ($plugins as $plugin => $isempty) {
$plugin = $assign->get_submission_plugin_by_type($plugin);
$this->assertEquals($isempty, empty($plugin->is_enabled()));
}
$CFG->usecomments = false;
$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'online');
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $this->course);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('file');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('file');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());
$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}
public function test_upgrade_offline_assignment() {
global $DB, $CFG;
$commentconfig = false;
if (!empty($CFG->usecomments)) {
$commentconfig = $CFG->usecomments;
}
$CFG->usecomments = false;
$this->setUser($this->editingteachers[0]);
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assignment');
$params = array('course'=>$this->course->id,
'assignmenttype'=>'offline');
$assignment = $generator->create_instance($params);
$this->setAdminUser();
$log = '';
$upgrader = new assign_upgrade_manager();
$this->assertTrue($upgrader->upgrade_assignment($assignment->id, $log));
$record = $DB->get_record('assign', array('course'=>$this->course->id));
$cm = get_coursemodule_from_instance('assign', $record->id);
$context = context_module::instance($cm->id);
$assign = new assign($context, $cm, $this->course);
$plugin = $assign->get_submission_plugin_by_type('onlinetext');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('comments');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_submission_plugin_by_type('file');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('comments');
$this->assertNotEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('file');
$this->assertEmpty($plugin->is_enabled());
$plugin = $assign->get_feedback_plugin_by_type('offline');
$this->assertEmpty($plugin->is_enabled());
$CFG->usecomments = $commentconfig;
course_delete_module($cm->id);
}
}