Ejemplo n.º 1
0
 /**
  * Test merging two users where one has submitted an assignment and the other
  * has no.
  */
 public function test_mergenonconflictingassigngrades()
 {
     global $DB;
     $this->setUser($this->editingteachers[0]);
     $assign = $this->create_instance();
     $this->setUser($this->teachers[0]);
     // Give a grade to student 1.
     $data = new stdClass();
     $data->grade = '75.0';
     $assign->testable_apply_grade_to_user($data, $this->students[1]->id, 0);
     // Check initial state - student 0 has no grade, student 1 has 75.00.
     $this->assertEquals(false, $assign->testable_is_graded($this->students[0]->id));
     $this->assertEquals(true, $assign->testable_is_graded($this->students[1]->id));
     $this->assertEquals('75.00', $this->get_user_assign_grade($this->students[1], $assign, $this->course));
     $this->assertEquals('-', $this->get_user_assign_grade($this->students[0], $assign, $this->course));
     // Merge student 1 into student 0.
     $mut = new MergeUserTool();
     $mut->merge($this->students[0]->id, $this->students[1]->id);
     // Student 0 should now have a grade of 75.00.
     $this->assertEquals(true, $assign->testable_is_graded($this->students[0]->id));
     $this->assertEquals('75.00', $this->get_user_assign_grade($this->students[0], $assign, $this->course));
     // Student 1 should now be suspended.
     $user_remove = $DB->get_record('user', array('id' => $this->students[1]->id));
     $this->assertEquals(1, $user_remove->suspended);
 }
 /**
  * Enrol two users on one unique course each and one shared course
  * then merge them.
  */
 public function test_mergeenrolments()
 {
     global $DB;
     // Setup two users to merge.
     $user_remove = $this->getDataGenerator()->create_user();
     $user_keep = $this->getDataGenerator()->create_user();
     // Create three courses.
     $course1 = $this->getDataGenerator()->create_course();
     $course2 = $this->getDataGenerator()->create_course();
     $course3 = $this->getDataGenerator()->create_course();
     $maninstance1 = $DB->get_record('enrol', array('courseid' => $course1->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance2 = $DB->get_record('enrol', array('courseid' => $course2->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $maninstance3 = $DB->get_record('enrol', array('courseid' => $course3->id, 'enrol' => 'manual'), '*', MUST_EXIST);
     $manual = enrol_get_plugin('manual');
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     // Enrol $user_remove on course 1 + 2 and $user_keep on course 2 + 3.
     $manual->enrol_user($maninstance1, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_remove->id, $studentrole->id);
     $manual->enrol_user($maninstance2, $user_keep->id, $studentrole->id);
     $manual->enrol_user($maninstance3, $user_keep->id, $studentrole->id);
     // Check initial state of enrolments for $user_remove.
     $courses = enrol_get_all_users_courses($user_remove->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course1->id, $course2->id), array_keys($courses));
     // Check initial state of enrolments for $user_keep.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(2, $courses);
     $this->assertEquals(array($course2->id, $course3->id), array_keys($courses));
     $mut = new MergeUserTool();
     list($success, $log, $logid) = $mut->merge($user_keep->id, $user_remove->id);
     // Check $user_remove is suspended.
     $user_remove = $DB->get_record('user', array('id' => $user_remove->id));
     $this->assertEquals(1, $user_remove->suspended);
     // Check $user_keep is now enrolled on all three courses.
     $courses = enrol_get_all_users_courses($user_keep->id);
     ksort($courses);
     $this->assertCount(3, $courses);
     $this->assertEquals(array($course1->id, $course2->id, $course3->id), array_keys($courses));
 }
Ejemplo n.º 3
0
 /**
  * Have two users attempt different quizes and then merge them.
  */
 public function test_mergenonconflictingquizattempts()
 {
     global $DB;
     $this->submit_quiz_attempt($this->quiz1, $this->user_keep, $this->get_fiftypercent_answers());
     $this->submit_quiz_attempt($this->quiz2, $this->user_remove, $this->get_hundredpercent_answers());
     $this->assertEquals('50.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz1, $this->course1));
     $this->assertEquals('-', $this->get_user_quiz_grade($this->user_keep, $this->quiz2, $this->course2));
     $this->assertEquals('-', $this->get_user_quiz_grade($this->user_remove, $this->quiz1, $this->course1));
     $this->assertEquals('100.00', $this->get_user_quiz_grade($this->user_remove, $this->quiz2, $this->course2));
     set_config('quizattemptsaction', QuizAttemptsMerger::ACTION_RENUMBER, 'tool_mergeusers');
     $mut = new MergeUserTool();
     $mut->merge($this->user_keep->id, $this->user_remove->id);
     $this->assertEquals('50.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz1, $this->course1));
     $this->assertEquals('100.00', $this->get_user_quiz_grade($this->user_keep, $this->quiz2, $this->course2));
     $user_remove = $DB->get_record('user', array('id' => $this->user_remove->id));
     $this->assertEquals(1, $user_remove->suspended);
 }
     break;
     // proceed with the merging and show results.
 // proceed with the merging and show results.
 case 'mergeusers':
     // Verify users once more just to be sure.  Both users should already be verified, but just an extra layer of security
     list($fromuser, $oumessage) = $mus->verify_user($SESSION->mut->olduser->id, 'id');
     list($touser, $numessage) = $mus->verify_user($SESSION->mut->newuser->id, 'id');
     if ($fromuser === NULL || $touser === NULL) {
         $renderer->mu_error($oumessage . '<br />' . $numessage);
         break;
         // break execution for error
     }
     // Merge the users
     $log = array();
     $success = true;
     list($success, $log, $logid) = $mut->merge($touser->id, $fromuser->id);
     // reset mut session
     $SESSION->mut = NULL;
     // render results page
     echo $renderer->results_page($touser, $fromuser, $success, $log, $logid);
     break;
     // we have both users to merge selected, but we want to change any of them.
 // we have both users to merge selected, but we want to change any of them.
 case 'searchusers':
     echo $renderer->index_page($mergeuserform, $renderer::INDEX_PAGE_SEARCH_STEP);
     break;
     // we have both users to merge selected, and in the search step, we
     // want to proceed with the merging of the currently selected users.
 // we have both users to merge selected, and in the search step, we
 // want to proceed with the merging of the currently selected users.
 case 'continueselection':