/** * Test save grades for a team submission */ public function test_save_grades_with_group_submission() { global $DB, $USER, $CFG; require_once $CFG->dirroot . '/group/lib.php'; $this->resetAfterTest(true); // Create a course and seplment and users. $course = self::getDataGenerator()->create_course(); $teacher = self::getDataGenerator()->create_user(); $teacherrole = $DB->get_record('role', array('shortname' => 'teacher')); $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id); $groupingdata = array(); $groupingdata['courseid'] = $course->id; $groupingdata['name'] = 'Group seplment grouping'; $grouping = self::getDataGenerator()->create_grouping($groupingdata); $group1data = array(); $group1data['courseid'] = $course->id; $group1data['name'] = 'Team 1'; $group2data = array(); $group2data['courseid'] = $course->id; $group2data['name'] = 'Team 2'; $group1 = self::getDataGenerator()->create_group($group1data); $group2 = self::getDataGenerator()->create_group($group2data); groups_sepl_grouping($grouping->id, $group1->id); groups_sepl_grouping($grouping->id, $group2->id); $generator = $this->getDataGenerator()->get_plugin_generator('mod_sepl'); $params['course'] = $course->id; $params['teamsubmission'] = 1; $params['teamsubmissiongroupingid'] = $grouping->id; $instance = $generator->create_instance($params); $cm = get_coursemodule_from_instance('sepl', $instance->id); $context = context_module::instance($cm->id); $sepl = new sepl($context, $cm, $course); $student1 = self::getDataGenerator()->create_user(); $student2 = self::getDataGenerator()->create_user(); $student3 = self::getDataGenerator()->create_user(); $student4 = self::getDataGenerator()->create_user(); $studentrole = $DB->get_record('role', array('shortname' => 'student')); $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id); $this->getDataGenerator()->enrol_user($student2->id, $course->id, $studentrole->id); $this->getDataGenerator()->enrol_user($student3->id, $course->id, $studentrole->id); $this->getDataGenerator()->enrol_user($student4->id, $course->id, $studentrole->id); groups_add_member($group1->id, $student1->id); groups_add_member($group1->id, $student2->id); groups_add_member($group1->id, $student3->id); groups_add_member($group2->id, $student4->id); $this->setUser($teacher); $feedbackpluginparams = array(); $feedbackpluginparams['files_filemanager'] = 0; $feedbackeditorparams = array('text' => '', 'format' => 1); $feedbackpluginparams['seplfeedbackcomments_editor'] = $feedbackeditorparams; $grades1 = array(); $student1gradeinfo = array(); $student1gradeinfo['userid'] = $student1->id; $student1gradeinfo['grade'] = 50; $student1gradeinfo['attemptnumber'] = -1; $student1gradeinfo['addattempt'] = true; $student1gradeinfo['workflowstate'] = 'released'; $student1gradeinfo['plugindata'] = $feedbackpluginparams; $grades1[] = $student1gradeinfo; $student2gradeinfo = array(); $student2gradeinfo['userid'] = $student2->id; $student2gradeinfo['grade'] = 75; $student2gradeinfo['attemptnumber'] = -1; $student2gradeinfo['addattempt'] = true; $student2gradeinfo['workflowstate'] = 'released'; $student2gradeinfo['plugindata'] = $feedbackpluginparams; $grades1[] = $student2gradeinfo; $this->setExpectedException('invalid_parameter_exception'); // Expect an exception since 2 grades have been submitted for the same team. $result = mod_sepl_external::save_grades($instance->id, true, $grades1); $result = external_api::clean_returnvalue(mod_sepl_external::save_grades_returns(), $result); $grades2 = array(); $student3gradeinfo = array(); $student3gradeinfo['userid'] = $student3->id; $student3gradeinfo['grade'] = 50; $student3gradeinfo['attemptnumber'] = -1; $student3gradeinfo['addattempt'] = true; $student3gradeinfo['workflowstate'] = 'released'; $student3gradeinfo['plugindata'] = $feedbackpluginparams; $grades2[] = $student3gradeinfo; $student4gradeinfo = array(); $student4gradeinfo['userid'] = $student4->id; $student4gradeinfo['grade'] = 75; $student4gradeinfo['attemptnumber'] = -1; $student4gradeinfo['addattempt'] = true; $student4gradeinfo['workflowstate'] = 'released'; $student4gradeinfo['plugindata'] = $feedbackpluginparams; $grades2[] = $student4gradeinfo; $result = mod_sepl_external::save_grades($instance->id, true, $grades2); $result = external_api::clean_returnvalue(mod_sepl_external::save_grades_returns(), $result); // There should be no warnings. $this->assertEquals(0, count($result)); $student3grade = $DB->get_record('sepl_grades', array('userid' => $student3->id, 'seplment' => $instance->id), '*', MUST_EXIST); $this->assertEquals($student3grade->grade, '50.0'); $student4grade = $DB->get_record('sepl_grades', array('userid' => $student4->id, 'seplment' => $instance->id), '*', MUST_EXIST); $this->assertEquals($student4grade->grade, '75.0'); }
/** * Testing can_edit_submission */ public function test_can_edit_submission() { global $PAGE, $DB; $this->create_extra_users(); $this->setAdminUser(); // Create seplment (onlinetext). $sepl = $this->create_instance(array('seplsubmission_onlinetext_enabled' => 1, 'submissiondrafts' => 1)); $PAGE->set_url(new moodle_url('/mod/sepl/view.php', array('id' => $sepl->get_course_module()->id))); // Check student can edit their own submission. $this->assertTrue($sepl->can_edit_submission($this->students[0]->id, $this->students[0]->id)); // Check student cannot edit others submission. $this->assertFalse($sepl->can_edit_submission($this->students[0]->id, $this->students[1]->id)); // Check teacher cannot (by default) edit a students submission. $this->assertFalse($sepl->can_edit_submission($this->students[0]->id, $this->teachers[0]->id)); // Add the required capability to edit a student submission. $roleid = create_role('Dummy role', 'dummyrole', 'dummy role description'); sepl_capability('mod/sepl:editothersubmission', CAP_ALLOW, $roleid, $sepl->get_context()->id); role_sepl($roleid, $this->teachers[0]->id, $sepl->get_context()->id); accesslib_clear_all_caches_for_unit_testing(); // Retest - should now have access. $this->assertTrue($sepl->can_edit_submission($this->students[0]->id, $this->teachers[0]->id)); // Force create an seplment with SEPARATEGROUPS. $data = new stdClass(); $data->courseid = $this->course->id; $data->name = 'Grouping'; $groupingid = groups_create_grouping($data); groups_sepl_grouping($groupingid, $this->groups[0]->id); groups_sepl_grouping($groupingid, $this->groups[1]->id); $sepl = $this->create_instance(array('groupingid' => $groupingid, 'groupmode' => SEPARATEGROUPS)); // Add the capability to the new seplment for extra students 0 and 1. sepl_capability('mod/sepl:editothersubmission', CAP_ALLOW, $roleid, $sepl->get_context()->id); role_sepl($roleid, $this->extrastudents[0]->id, $sepl->get_context()->id); role_sepl($roleid, $this->extrastudents[1]->id, $sepl->get_context()->id); accesslib_clear_all_caches_for_unit_testing(); // Verify the extra student does not have the capability to edit a submission not in their group. $this->assertFalse($sepl->can_edit_submission($this->students[0]->id, $this->extrastudents[1]->id)); // Verify the extra student does have the capability to edit a submission in their group. $this->assertTrue($sepl->can_edit_submission($this->students[0]->id, $this->extrastudents[0]->id)); }