コード例 #1
0
ファイル: events_test.php プロジェクト: Gavinthisisit/Moodle
 public function test_assessment_reevaluated()
 {
     $this->resetAfterTest();
     $this->setAdminUser();
     $cm = get_coursemodule_from_instance('teamwork', $this->teamwork->id, $this->course->id, false, MUST_EXIST);
     $teamwork = new testable_teamwork($this->teamwork, $cm, $this->course);
     $assessments = array();
     $assessments[] = (object) array('reviewerid' => 2, 'gradinggrade' => null, 'gradinggradeover' => null, 'aggregationid' => 2, 'aggregatedgrade' => 12);
     // Trigger and capture the event.
     $sink = $this->redirectEvents();
     $teamwork->aggregate_grading_grades_process($assessments);
     $events = $sink->get_events();
     $event = reset($events);
     $this->assertInstanceOf('\\mod_teamwork\\event\\assessment_reevaluated', $event);
     $this->assertEquals('teamwork_aggregations', $event->objecttable);
     $this->assertEquals(context_module::instance($cm->id), $event->get_context());
     $expected = array($this->course->id, 'teamwork', 'update aggregate grade', 'view.php?id=' . $event->get_context()->instanceid, $event->objectid, $event->get_context()->instanceid);
     $this->assertEventLegacyLogData($expected, $event);
     $this->assertEventContextNotUsed($event);
     $sink->close();
 }
コード例 #2
0
 /**
  * Tests user restrictions, as they affect lists of users returned by
  * core API functions.
  *
  * This includes the groupingid option (when group mode is in use), and
  * standard activity restrictions using the availability API.
  */
 public function test_user_restrictions()
 {
     global $DB, $CFG;
     $this->resetAfterTest();
     // Use existing sample course from setUp.
     $courseid = $this->teamwork->course->id;
     // Make a test grouping and two groups.
     $generator = $this->getDataGenerator();
     $grouping = $generator->create_grouping(array('courseid' => $courseid));
     $group1 = $generator->create_group(array('courseid' => $courseid));
     groups_assign_grouping($grouping->id, $group1->id);
     $group2 = $generator->create_group(array('courseid' => $courseid));
     groups_assign_grouping($grouping->id, $group2->id);
     // Group 3 is not in the grouping.
     $group3 = $generator->create_group(array('courseid' => $courseid));
     // Enrol some students.
     $roleids = $DB->get_records_menu('role', null, '', 'shortname, id');
     $student1 = $generator->create_user();
     $student2 = $generator->create_user();
     $student3 = $generator->create_user();
     $generator->enrol_user($student1->id, $courseid, $roleids['student']);
     $generator->enrol_user($student2->id, $courseid, $roleids['student']);
     $generator->enrol_user($student3->id, $courseid, $roleids['student']);
     // Place students in groups (except student 3).
     groups_add_member($group1, $student1);
     groups_add_member($group2, $student2);
     groups_add_member($group3, $student3);
     // The existing teamwork doesn't have any restrictions, so user lists
     // should include all three users.
     $allusers = get_enrolled_users(context_course::instance($courseid));
     $result = $this->teamwork->get_grouped($allusers);
     $this->assertCount(4, $result);
     $users = array_keys($result[0]);
     sort($users);
     $this->assertEquals(array($student1->id, $student2->id, $student3->id), $users);
     $this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
     $this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
     $this->assertEquals(array($student3->id), array_keys($result[$group3->id]));
     // Test get_users_with_capability_sql (via get_potential_authors).
     $users = $this->teamwork->get_potential_authors(false);
     $this->assertCount(3, $users);
     $users = $this->teamwork->get_potential_authors(false, $group2->id);
     $this->assertEquals(array($student2->id), array_keys($users));
     // Create another test teamwork with grouping set.
     $teamworkitem = $this->getDataGenerator()->create_module('teamwork', array('course' => $courseid, 'groupmode' => SEPARATEGROUPS, 'groupingid' => $grouping->id));
     $cm = get_coursemodule_from_instance('teamwork', $teamworkitem->id, $courseid, false, MUST_EXIST);
     $teamworkgrouping = new testable_teamwork($teamworkitem, $cm, $this->teamwork->course);
     // This time the result should only include users and groups in the
     // selected grouping.
     $result = $teamworkgrouping->get_grouped($allusers);
     $this->assertCount(3, $result);
     $users = array_keys($result[0]);
     sort($users);
     $this->assertEquals(array($student1->id, $student2->id), $users);
     $this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
     $this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
     // Test get_users_with_capability_sql (via get_potential_authors).
     $users = $teamworkgrouping->get_potential_authors(false);
     $userids = array_keys($users);
     sort($userids);
     $this->assertEquals(array($student1->id, $student2->id), $userids);
     $users = $teamworkgrouping->get_potential_authors(false, $group2->id);
     $this->assertEquals(array($student2->id), array_keys($users));
     // Enable the availability system and create another test teamwork with
     // availability restriction on grouping.
     $CFG->enableavailability = true;
     $teamworkitem = $this->getDataGenerator()->create_module('teamwork', array('course' => $courseid, 'availability' => json_encode(\core_availability\tree::get_root_json(array(\availability_grouping\condition::get_json($grouping->id)), \core_availability\tree::OP_AND, false))));
     $cm = get_coursemodule_from_instance('teamwork', $teamworkitem->id, $courseid, false, MUST_EXIST);
     $teamworkrestricted = new testable_teamwork($teamworkitem, $cm, $this->teamwork->course);
     // The get_grouped function isn't intended to apply this restriction,
     // so it should be the same as the base teamwork. (Note: in reality,
     // get_grouped is always run with the parameter being the result of
     // one of the get_potential_xxx functions, so it works.)
     $result = $teamworkrestricted->get_grouped($allusers);
     $this->assertCount(4, $result);
     $this->assertCount(3, $result[0]);
     // The get_users_with_capability_sql-based functions should apply it.
     $users = $teamworkrestricted->get_potential_authors(false);
     $userids = array_keys($users);
     sort($userids);
     $this->assertEquals(array($student1->id, $student2->id), $userids);
     $users = $teamworkrestricted->get_potential_authors(false, $group2->id);
     $this->assertEquals(array($student2->id), array_keys($users));
 }