Línea 37... |
Línea 37... |
37 |
|
37 |
|
38 |
|
38 |
|
39 |
/**
|
39 |
/**
|
40 |
* Test cases for the internal workshop api
|
40 |
* Test cases for the internal workshop api
|
Línea 41... |
Línea 41... |
41 |
*/
|
41 |
*/
|
42 |
class locallib_test extends \advanced_testcase {
|
42 |
final class locallib_test extends \advanced_testcase {
|
Línea 43... |
Línea 43... |
43 |
|
43 |
|
Línea 476... |
Línea 476... |
476 |
$this->assertEquals(array($student1->id, $student2->id, $student3->id), $users);
|
476 |
$this->assertEquals(array($student1->id, $student2->id, $student3->id), $users);
|
477 |
$this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
|
477 |
$this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
|
478 |
$this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
|
478 |
$this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
|
479 |
$this->assertEquals(array($student3->id), array_keys($result[$group3->id]));
|
479 |
$this->assertEquals(array($student3->id), array_keys($result[$group3->id]));
|
Línea 480... |
Línea -... |
480 |
|
- |
|
481 |
// Test get_users_with_capability_sql (via get_potential_authors).
|
480 |
|
482 |
$users = $this->workshop->get_potential_authors(false);
|
481 |
$users = $this->workshop->get_potential_authors(false);
|
483 |
$this->assertCount(3, $users);
|
482 |
$this->assertCount(3, $users);
|
484 |
$users = $this->workshop->get_potential_authors(false, $group2->id);
|
483 |
$users = $this->workshop->get_potential_authors(false, $group2->id);
|
Línea 500... |
Línea 499... |
500 |
sort($users);
|
499 |
sort($users);
|
501 |
$this->assertEquals(array($student1->id, $student2->id), $users);
|
500 |
$this->assertEquals(array($student1->id, $student2->id), $users);
|
502 |
$this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
|
501 |
$this->assertEquals(array($student1->id), array_keys($result[$group1->id]));
|
503 |
$this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
|
502 |
$this->assertEquals(array($student2->id), array_keys($result[$group2->id]));
|
Línea 504... |
Línea -... |
504 |
|
- |
|
505 |
// Test get_users_with_capability_sql (via get_potential_authors).
|
503 |
|
506 |
$users = $workshopgrouping->get_potential_authors(false);
|
504 |
$users = $workshopgrouping->get_potential_authors(false);
|
507 |
$userids = array_keys($users);
|
505 |
$userids = array_keys($users);
|
508 |
sort($userids);
|
506 |
sort($userids);
|
509 |
$this->assertEquals(array($student1->id, $student2->id), $userids);
|
507 |
$this->assertEquals(array($student1->id, $student2->id), $userids);
|
Línea 528... |
Línea 526... |
528 |
// one of the get_potential_xxx functions, so it works.)
|
526 |
// one of the get_potential_xxx functions, so it works.)
|
529 |
$result = $workshoprestricted->get_grouped($allusers);
|
527 |
$result = $workshoprestricted->get_grouped($allusers);
|
530 |
$this->assertCount(4, $result);
|
528 |
$this->assertCount(4, $result);
|
531 |
$this->assertCount(3, $result[0]);
|
529 |
$this->assertCount(3, $result[0]);
|
Línea 532... |
Línea -... |
532 |
|
- |
|
533 |
// The get_users_with_capability_sql-based functions should apply it.
|
530 |
|
534 |
$users = $workshoprestricted->get_potential_authors(false);
|
531 |
$users = $workshoprestricted->get_potential_authors(false);
|
535 |
$userids = array_keys($users);
|
532 |
$userids = array_keys($users);
|
536 |
sort($userids);
|
533 |
sort($userids);
|
537 |
$this->assertEquals(array($student1->id, $student2->id), $userids);
|
534 |
$this->assertEquals(array($student1->id, $student2->id), $userids);
|
Línea 868... |
Línea 865... |
868 |
$initialbarprefsprop = $reflector->getProperty('initialbarprefs');
|
865 |
$initialbarprefsprop = $reflector->getProperty('initialbarprefs');
|
869 |
$initialbarprefs = $initialbarprefsprop->getValue($this->workshop);
|
866 |
$initialbarprefs = $initialbarprefsprop->getValue($this->workshop);
|
Línea 870... |
Línea 867... |
870 |
|
867 |
|
871 |
return $initialbarprefs;
|
868 |
return $initialbarprefs;
|
- |
|
869 |
}
|
- |
|
870 |
|
- |
|
871 |
/**
|
- |
|
872 |
* Test count_submissions and count_assessments methods.
|
- |
|
873 |
*
|
- |
|
874 |
* @covers \workshop::count_submissions
|
- |
|
875 |
* @covers \workshop::count_assessments
|
- |
|
876 |
*/
|
- |
|
877 |
public function test_count_submissions_count_assessments(): void {
|
- |
|
878 |
$this->resetAfterTest();
|
- |
|
879 |
$this->setAdminUser();
|
- |
|
880 |
|
- |
|
881 |
$course = $this->getDataGenerator()->create_course();
|
- |
|
882 |
$group1 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
|
- |
|
883 |
$group2 = $this->getDataGenerator()->create_group(['courseid' => $course->id]);
|
- |
|
884 |
$student1 = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
- |
|
885 |
$student2 = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
- |
|
886 |
$student3 = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
- |
|
887 |
$student4 = $this->getDataGenerator()->create_and_enrol($course, 'student');
|
- |
|
888 |
|
- |
|
889 |
groups_add_member($group1, $student1);
|
- |
|
890 |
groups_add_member($group1, $student3);
|
- |
|
891 |
groups_add_member($group2, $student2);
|
- |
|
892 |
|
- |
|
893 |
$activity = $this->getDataGenerator()->create_module(
|
- |
|
894 |
'workshop',
|
- |
|
895 |
['course' => $course->id , 'groupmode' => SEPARATEGROUPS],
|
- |
|
896 |
);
|
- |
|
897 |
$cm = get_fast_modinfo($course)->get_cm($activity->cmid);
|
- |
|
898 |
|
- |
|
899 |
// Set up a generator to create content.
|
- |
|
900 |
/** @var \mod_workshop_generator $generator */
|
- |
|
901 |
$generator = $this->getDataGenerator()->get_plugin_generator('mod_workshop');
|
- |
|
902 |
|
- |
|
903 |
// Create some submissions.
|
- |
|
904 |
$submission1id = $generator->create_submission(
|
- |
|
905 |
$activity->id,
|
- |
|
906 |
$student1->id,
|
- |
|
907 |
['title' => 'My custom title', 'grade' => 85.00000],
|
- |
|
908 |
);
|
- |
|
909 |
$submission2id = $generator->create_submission(
|
- |
|
910 |
$activity->id,
|
- |
|
911 |
$student2->id,
|
- |
|
912 |
['title' => 'My custom title', 'grade' => null],
|
- |
|
913 |
);
|
- |
|
914 |
$submission3id = $generator->create_submission(
|
- |
|
915 |
$activity->id,
|
- |
|
916 |
$student3->id,
|
- |
|
917 |
['title' => 'My custom title', 'grade' => null],
|
- |
|
918 |
);
|
- |
|
919 |
$submission4id = $generator->create_submission(
|
- |
|
920 |
$activity->id,
|
- |
|
921 |
$student4->id,
|
- |
|
922 |
['title' => 'My custom title', 'grade' => null],
|
- |
|
923 |
);
|
- |
|
924 |
// Assess one submission.
|
- |
|
925 |
$generator->create_assessment(
|
- |
|
926 |
$submission1id,
|
- |
|
927 |
$student1->id,
|
- |
|
928 |
['weight' => 3, 'grade' => 95.00000],
|
- |
|
929 |
);
|
- |
|
930 |
$generator->create_assessment(
|
- |
|
931 |
$submission2id,
|
- |
|
932 |
$student2->id,
|
- |
|
933 |
['weight' => 3, 'grade' => null],
|
- |
|
934 |
);
|
- |
|
935 |
$generator->create_assessment(
|
- |
|
936 |
$submission3id,
|
- |
|
937 |
$student3->id,
|
- |
|
938 |
['weight' => 3, 'grade' => null],
|
- |
|
939 |
);
|
- |
|
940 |
$generator->create_assessment(
|
- |
|
941 |
$submission4id,
|
- |
|
942 |
$student4->id,
|
- |
|
943 |
['weight' => 3, 'grade' => 35.00000],
|
- |
|
944 |
);
|
- |
|
945 |
|
- |
|
946 |
$manager = new workshop($activity, $cm, $course, $cm->context);
|
- |
|
947 |
|
- |
|
948 |
$this->assertEquals(4, $manager->count_submissions());
|
- |
|
949 |
$this->assertEquals(4, $manager->count_submissions('all'));
|
- |
|
950 |
$this->assertEquals(1, $manager->count_submissions($student1->id));
|
- |
|
951 |
$this->assertEquals(1, $manager->count_submissions($student2->id));
|
- |
|
952 |
|
- |
|
953 |
$this->assertEquals(2, $manager->count_submissions('all', $group1->id));
|
- |
|
954 |
$this->assertEquals(1, $manager->count_submissions('all', $group2->id));
|
- |
|
955 |
$this->assertEquals(1, $manager->count_submissions($student1->id, $group1->id));
|
- |
|
956 |
$this->assertEquals(0, $manager->count_submissions($student2->id, $group1->id));
|
- |
|
957 |
|
- |
|
958 |
$this->assertEquals(4, $manager->count_assessments());
|
- |
|
959 |
$this->assertEquals(2, $manager->count_assessments(true));
|
- |
|
960 |
|
- |
|
961 |
$this->assertEquals(2, $manager->count_assessments(false, $group1->id));
|
- |
|
962 |
$this->assertEquals(1, $manager->count_assessments(true, $group1->id));
|
- |
|
963 |
|
- |
|
964 |
$this->assertEquals(1, $manager->count_assessments(false, $group2->id));
|
- |
|
965 |
$this->assertEquals(0, $manager->count_assessments(true, $group2->id));
|
872 |
}
|
966 |
}
|