Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 11
Línea 132... Línea 132...
132
 
132
 
133
        $event = new \calendar_event($prop);
133
        $event = new \calendar_event($prop);
134
        return $event->create($prop);
134
        return $event->create($prop);
Línea 135... Línea 135...
135
    }
135
    }
136
 
136
 
Línea 137... Línea 137...
137
    public function test_create_calendar_events() {
137
    public function test_create_calendar_events(): void {
138
        global $DB, $USER;
138
        global $DB, $USER;
139
 
139
 
Línea 160... Línea 160...
160
    }
160
    }
Línea 161... Línea 161...
161
 
161
 
162
    /**
162
    /**
163
     * Test delete_calendar_events
163
     * Test delete_calendar_events
164
     */
164
     */
165
    public function test_delete_calendar_events() {
165
    public function test_delete_calendar_events(): void {
Línea 166... Línea 166...
166
        global $DB, $USER;
166
        global $DB, $USER;
167
 
167
 
Línea 289... Línea 289...
289
    }
289
    }
Línea 290... Línea 290...
290
 
290
 
291
    /**
291
    /**
292
     * Test get_calendar_events
292
     * Test get_calendar_events
293
     */
293
     */
294
    public function test_get_calendar_events() {
294
    public function test_get_calendar_events(): void {
Línea 295... Línea 295...
295
        global $DB, $USER;
295
        global $DB, $USER;
296
 
296
 
297
        $this->resetAfterTest(true);
297
        $this->resetAfterTest(true);
Línea 546... Línea 546...
546
    }
546
    }
Línea 547... Línea 547...
547
 
547
 
548
    /**
548
    /**
549
     * Test get_calendar_events with mathjax in the name.
549
     * Test get_calendar_events with mathjax in the name.
550
     */
550
     */
551
    public function test_get_calendar_events_with_mathjax() {
551
    public function test_get_calendar_events_with_mathjax(): void {
Línea 552... Línea 552...
552
        global $USER;
552
        global $USER;
553
 
553
 
554
        $this->resetAfterTest(true);
554
        $this->resetAfterTest(true);
Línea 582... Línea 582...
582
    }
582
    }
Línea 583... Línea 583...
583
 
583
 
584
    /**
584
    /**
585
     * Test core_calendar_external::create_calendar_events
585
     * Test core_calendar_external::create_calendar_events
586
     */
586
     */
587
    public function test_core_create_calendar_events() {
587
    public function test_core_create_calendar_events(): void {
Línea 588... Línea 588...
588
        global $DB, $USER, $SITE;
588
        global $DB, $USER, $SITE;
589
 
589
 
Línea 666... Línea 666...
666
     * be return.
666
     * be return.
667
     *
667
     *
668
     * If there are no events on or after the given time then an empty result set should
668
     * If there are no events on or after the given time then an empty result set should
669
     * be returned.
669
     * be returned.
670
     */
670
     */
671
    public function test_get_calendar_action_events_by_timesort_after_time() {
671
    public function test_get_calendar_action_events_by_timesort_after_time(): void {
672
        $user = $this->getDataGenerator()->create_user();
672
        $user = $this->getDataGenerator()->create_user();
673
        $course = $this->getDataGenerator()->create_course();
673
        $course = $this->getDataGenerator()->create_course();
674
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
674
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
675
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
675
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
Línea 743... Línea 743...
743
     * should not be returned.
743
     * should not be returned.
744
     *
744
     *
745
     * If there are no events before the given time then an empty result set should be
745
     * If there are no events before the given time then an empty result set should be
746
     * returned.
746
     * returned.
747
     */
747
     */
748
    public function test_get_calendar_action_events_by_timesort_before_time() {
748
    public function test_get_calendar_action_events_by_timesort_before_time(): void {
749
        $user = $this->getDataGenerator()->create_user();
749
        $user = $this->getDataGenerator()->create_user();
750
        $course = $this->getDataGenerator()->create_course();
750
        $course = $this->getDataGenerator()->create_course();
751
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
751
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
752
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
752
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
Línea 816... Línea 816...
816
    }
816
    }
Línea 817... Línea 817...
817
 
817
 
818
    /**
818
    /**
819
     * Test retrieving event that was overridden for a user
819
     * Test retrieving event that was overridden for a user
820
     */
820
     */
821
    public function test_get_calendar_events_override() {
821
    public function test_get_calendar_events_override(): void {
822
        $user = $this->getDataGenerator()->create_user();
822
        $user = $this->getDataGenerator()->create_user();
823
        $user2 = $this->getDataGenerator()->create_user();
823
        $user2 = $this->getDataGenerator()->create_user();
824
        $teacher = $this->getDataGenerator()->create_user();
824
        $teacher = $this->getDataGenerator()->create_user();
825
        $anotheruser = $this->getDataGenerator()->create_user();
825
        $anotheruser = $this->getDataGenerator()->create_user();
Línea 886... Línea 886...
886
     * a sort time between the lower and upper time bound (inclusive).
886
     * a sort time between the lower and upper time bound (inclusive).
887
     *
887
     *
888
     * If there are no events in the given time range then an empty result set should be
888
     * If there are no events in the given time range then an empty result set should be
889
     * returned.
889
     * returned.
890
     */
890
     */
891
    public function test_get_calendar_action_events_by_timesort_time_range() {
891
    public function test_get_calendar_action_events_by_timesort_time_range(): void {
892
        $user = $this->getDataGenerator()->create_user();
892
        $user = $this->getDataGenerator()->create_user();
893
        $course = $this->getDataGenerator()->create_course();
893
        $course = $this->getDataGenerator()->create_course();
894
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
894
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
895
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
895
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
Línea 946... Línea 946...
946
     * and uppper time bound (inclusive) where the result set is shifted by the offset value.
946
     * and uppper time bound (inclusive) where the result set is shifted by the offset value.
947
     *
947
     *
948
     * If there are no events in the given time range then an empty result set should be
948
     * If there are no events in the given time range then an empty result set should be
949
     * returned.
949
     * returned.
950
     */
950
     */
951
    public function test_get_calendar_action_events_by_timesort_time_limit_offset() {
951
    public function test_get_calendar_action_events_by_timesort_time_limit_offset(): void {
952
        $user = $this->getDataGenerator()->create_user();
952
        $user = $this->getDataGenerator()->create_user();
953
        $course = $this->getDataGenerator()->create_course();
953
        $course = $this->getDataGenerator()->create_course();
954
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
954
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
955
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
955
        $moduleinstance = $generator->create_instance(['course' => $course->id]);
Línea 1012... Línea 1012...
1012
    }
1012
    }
Línea 1013... Línea 1013...
1013
 
1013
 
1014
    /**
1014
    /**
1015
     * Check that it is possible to restrict the calendar events to events where the user is not suspended in the course.
1015
     * Check that it is possible to restrict the calendar events to events where the user is not suspended in the course.
1016
     */
1016
     */
1017
    public function test_get_calendar_action_events_by_timesort_suspended_course() {
1017
    public function test_get_calendar_action_events_by_timesort_suspended_course(): void {
1018
        $this->resetAfterTest();
1018
        $this->resetAfterTest();
1019
        $user1 = $this->getDataGenerator()->create_user();
1019
        $user1 = $this->getDataGenerator()->create_user();
1020
        $user2 = $this->getDataGenerator()->create_user();
1020
        $user2 = $this->getDataGenerator()->create_user();
1021
        $course = $this->getDataGenerator()->create_course();
1021
        $course = $this->getDataGenerator()->create_course();
Línea 1040... Línea 1040...
1040
    }
1040
    }
Línea 1041... Línea 1041...
1041
 
1041
 
1042
    /**
1042
    /**
1043
     * Check that it is possible to get other user's events without the permission.
1043
     * Check that it is possible to get other user's events without the permission.
1044
     */
1044
     */
1045
    public function test_get_calendar_action_events_by_timesort_for_other_users() {
1045
    public function test_get_calendar_action_events_by_timesort_for_other_users(): void {
1046
        $this->resetAfterTest();
1046
        $this->resetAfterTest();
1047
        // Create test users.
1047
        // Create test users.
1048
        $user1 = $this->getDataGenerator()->create_user(['email' => 'student1@localhost.com']);
1048
        $user1 = $this->getDataGenerator()->create_user(['email' => 'student1@localhost.com']);
1049
        $user2 = $this->getDataGenerator()->create_user(['email' => 'student2@localhost.com']);
1049
        $user2 = $this->getDataGenerator()->create_user(['email' => 'student2@localhost.com']);
Línea 1093... Línea 1093...
1093
     * to that time should not be return.
1093
     * to that time should not be return.
1094
     *
1094
     *
1095
     * If there are no events on or after the given time then an empty result set should
1095
     * If there are no events on or after the given time then an empty result set should
1096
     * be returned.
1096
     * be returned.
1097
     */
1097
     */
1098
    public function test_get_calendar_action_events_by_course_after_time() {
1098
    public function test_get_calendar_action_events_by_course_after_time(): void {
1099
        $user = $this->getDataGenerator()->create_user();
1099
        $user = $this->getDataGenerator()->create_user();
1100
        $course1 = $this->getDataGenerator()->create_course();
1100
        $course1 = $this->getDataGenerator()->create_course();
1101
        $course2 = $this->getDataGenerator()->create_course();
1101
        $course2 = $this->getDataGenerator()->create_course();
1102
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1102
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1103
        $instance1 = $generator->create_instance(['course' => $course1->id]);
1103
        $instance1 = $generator->create_instance(['course' => $course1->id]);
Línea 1157... Línea 1157...
1157
     * events after that time should not be returned.
1157
     * events after that time should not be returned.
1158
     *
1158
     *
1159
     * If there are no events before the given time then an empty result set should be
1159
     * If there are no events before the given time then an empty result set should be
1160
     * returned.
1160
     * returned.
1161
     */
1161
     */
1162
    public function test_get_calendar_action_events_by_course_before_time() {
1162
    public function test_get_calendar_action_events_by_course_before_time(): void {
1163
        $user = $this->getDataGenerator()->create_user();
1163
        $user = $this->getDataGenerator()->create_user();
1164
        $course1 = $this->getDataGenerator()->create_course();
1164
        $course1 = $this->getDataGenerator()->create_course();
1165
        $course2 = $this->getDataGenerator()->create_course();
1165
        $course2 = $this->getDataGenerator()->create_course();
1166
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1166
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1167
        $instance1 = $generator->create_instance(['course' => $course1->id]);
1167
        $instance1 = $generator->create_instance(['course' => $course1->id]);
Línea 1221... Línea 1221...
1221
     * (inclusive).
1221
     * (inclusive).
1222
     *
1222
     *
1223
     * If there are no events in the given time range then an empty result set should be
1223
     * If there are no events in the given time range then an empty result set should be
1224
     * returned.
1224
     * returned.
1225
     */
1225
     */
1226
    public function test_get_calendar_action_events_by_course_time_range() {
1226
    public function test_get_calendar_action_events_by_course_time_range(): void {
1227
        $user = $this->getDataGenerator()->create_user();
1227
        $user = $this->getDataGenerator()->create_user();
1228
        $course1 = $this->getDataGenerator()->create_course();
1228
        $course1 = $this->getDataGenerator()->create_course();
1229
        $course2 = $this->getDataGenerator()->create_course();
1229
        $course2 = $this->getDataGenerator()->create_course();
1230
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1230
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1231
        $instance1 = $generator->create_instance(['course' => $course1->id]);
1231
        $instance1 = $generator->create_instance(['course' => $course1->id]);
Línea 1286... Línea 1286...
1286
     * set is shifted by the offset value.
1286
     * set is shifted by the offset value.
1287
     *
1287
     *
1288
     * If there are no events in the given time range then an empty result set should be
1288
     * If there are no events in the given time range then an empty result set should be
1289
     * returned.
1289
     * returned.
1290
     */
1290
     */
1291
    public function test_get_calendar_action_events_by_course_time_limit_offset() {
1291
    public function test_get_calendar_action_events_by_course_time_limit_offset(): void {
1292
        $user = $this->getDataGenerator()->create_user();
1292
        $user = $this->getDataGenerator()->create_user();
1293
        $course1 = $this->getDataGenerator()->create_course();
1293
        $course1 = $this->getDataGenerator()->create_course();
1294
        $course2 = $this->getDataGenerator()->create_course();
1294
        $course2 = $this->getDataGenerator()->create_course();
1295
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1295
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1296
        $instance1 = $generator->create_instance(['course' => $course1->id]);
1296
        $instance1 = $generator->create_instance(['course' => $course1->id]);
Línea 1357... Línea 1357...
1357
    }
1357
    }
Línea 1358... Línea 1358...
1358
 
1358
 
1359
    /**
1359
    /**
1360
     * Test get_calendar_action_events_by_course with search feature
1360
     * Test get_calendar_action_events_by_course with search feature
1361
     */
1361
     */
1362
    public function test_get_calendar_action_events_by_course_with_search() {
1362
    public function test_get_calendar_action_events_by_course_with_search(): void {
1363
        // Generate data.
1363
        // Generate data.
1364
        $user = $this->getDataGenerator()->create_user();
1364
        $user = $this->getDataGenerator()->create_user();
1365
        $course = $this->getDataGenerator()->create_course();
1365
        $course = $this->getDataGenerator()->create_course();
1366
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
1366
        $generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
Línea 1423... Línea 1423...
1423
 
1423
 
1424
    /**
1424
    /**
1425
     * Test that get_action_events_by_courses will return a list of events for each
1425
     * Test that get_action_events_by_courses will return a list of events for each
1426
     * course you provided as long as the user is enrolled in the course.
1426
     * course you provided as long as the user is enrolled in the course.
1427
     */
1427
     */
1428
    public function test_get_action_events_by_courses() {
1428
    public function test_get_action_events_by_courses(): void {
1429
        $user = $this->getDataGenerator()->create_user();
1429
        $user = $this->getDataGenerator()->create_user();
1430
        $course1 = $this->getDataGenerator()->create_course();
1430
        $course1 = $this->getDataGenerator()->create_course();
1431
        $course2 = $this->getDataGenerator()->create_course();
1431
        $course2 = $this->getDataGenerator()->create_course();
1432
        $course3 = $this->getDataGenerator()->create_course();
1432
        $course3 = $this->getDataGenerator()->create_course();
Línea 1556... Línea 1556...
1556
    }
1556
    }
Línea 1557... Línea 1557...
1557
 
1557
 
1558
    /**
1558
    /**
1559
     * Test get_action_events_by_courses with search feature
1559
     * Test get_action_events_by_courses with search feature
1560
     */
1560
     */
1561
    public function test_get_action_events_by_courses_with_search() {
1561
    public function test_get_action_events_by_courses_with_search(): void {
1562
        // Generate data.
1562
        // Generate data.
1563
        $user = $this->getDataGenerator()->create_user();
1563
        $user = $this->getDataGenerator()->create_user();
1564
        $course1 = $this->getDataGenerator()->create_course();
1564
        $course1 = $this->getDataGenerator()->create_course();
1565
        $course2 = $this->getDataGenerator()->create_course();
1565
        $course2 = $this->getDataGenerator()->create_course();
Línea 1662... Línea 1662...
1662
    }
1662
    }
Línea 1663... Línea 1663...
1663
 
1663
 
1664
    /**
1664
    /**
1665
     * Test for deleting module events.
1665
     * Test for deleting module events.
1666
     */
1666
     */
1667
    public function test_delete_calendar_events_for_modules() {
1667
    public function test_delete_calendar_events_for_modules(): void {
1668
        $this->resetAfterTest();
1668
        $this->resetAfterTest();
1669
        $this->setAdminUser();
1669
        $this->setAdminUser();
1670
        $course = $this->getDataGenerator()->create_course();
1670
        $course = $this->getDataGenerator()->create_course();
1671
        $nexttime = time() + DAYSECS;
1671
        $nexttime = time() + DAYSECS;
Línea 1686... Línea 1686...
1686
 
1686
 
1687
    /**
1687
    /**
1688
     * Updating the event start day should change the date value but leave
1688
     * Updating the event start day should change the date value but leave
1689
     * the time of day unchanged.
1689
     * the time of day unchanged.
1690
     */
1690
     */
1691
    public function test_update_event_start_day() {
1691
    public function test_update_event_start_day(): void {
1692
        $generator = $this->getDataGenerator();
1692
        $generator = $this->getDataGenerator();
1693
        $user = $generator->create_user();
1693
        $user = $generator->create_user();
1694
        $roleid = $generator->create_role();
1694
        $roleid = $generator->create_role();
1695
        $context = \context_system::instance();
1695
        $context = \context_system::instance();
Línea 1726... Línea 1726...
1726
 
1726
 
1727
    /**
1727
    /**
1728
     * A user should not be able to edit an event that they don't have
1728
     * A user should not be able to edit an event that they don't have
1729
     * capabilities for.
1729
     * capabilities for.
1730
     */
1730
     */
1731
    public function test_update_event_start_day_no_permission() {
1731
    public function test_update_event_start_day_no_permission(): void {
1732
        $generator = $this->getDataGenerator();
1732
        $generator = $this->getDataGenerator();
1733
        $user = $generator->create_user();
1733
        $user = $generator->create_user();
1734
        $roleid = $generator->create_role();
1734
        $roleid = $generator->create_role();
1735
        $context = \context_system::instance();
1735
        $context = \context_system::instance();
Línea 1765... Línea 1765...
1765
    }
1765
    }
Línea 1766... Línea 1766...
1766
 
1766
 
1767
    /**
1767
    /**
1768
     * A user should not be able to update a module event.
1768
     * A user should not be able to update a module event.
1769
     */
1769
     */
1770
    public function test_update_event_start_day_module_event() {
1770
    public function test_update_event_start_day_module_event(): void {
1771
        $generator = $this->getDataGenerator();
1771
        $generator = $this->getDataGenerator();
1772
        $user = $generator->create_user();
1772
        $user = $generator->create_user();
1773
        $course = $generator->create_course();
1773
        $course = $generator->create_course();
1774
        $plugingenerator = $generator->get_plugin_generator('mod_assign');
1774
        $plugingenerator = $generator->get_plugin_generator('mod_assign');
Línea 1810... Línea 1810...
1810
 
1810
 
1811
    /**
1811
    /**
1812
     * Submit a request where the time duration until is earlier than the time
1812
     * Submit a request where the time duration until is earlier than the time
1813
     * start in order to get a validation error from the server.
1813
     * start in order to get a validation error from the server.
1814
     */
1814
     */
1815
    public function test_submit_create_update_form_validation_error() {
1815
    public function test_submit_create_update_form_validation_error(): void {
1816
        $user = $this->getDataGenerator()->create_user();
1816
        $user = $this->getDataGenerator()->create_user();
1817
        $timestart = new \DateTime();
1817
        $timestart = new \DateTime();
1818
        $interval = new \DateInterval("P1D"); // One day.
1818
        $interval = new \DateInterval("P1D"); // One day.
1819
        $timedurationuntil = new \DateTime();
1819
        $timedurationuntil = new \DateTime();
Línea 1865... Línea 1865...
1865
 
1865
 
1866
    /**
1866
    /**
1867
     * A user with the moodle/calendar:manageownentries capability at the
1867
     * A user with the moodle/calendar:manageownentries capability at the
1868
     * system context should be able to create a user event.
1868
     * system context should be able to create a user event.
1869
     */
1869
     */
1870
    public function test_submit_create_update_form_create_user_event() {
1870
    public function test_submit_create_update_form_create_user_event(): void {
1871
        $generator = $this->getDataGenerator();
1871
        $generator = $this->getDataGenerator();
1872
        $user = $generator->create_user();
1872
        $user = $generator->create_user();
1873
        $roleid = $generator->create_role();
1873
        $roleid = $generator->create_role();
1874
        $context = \context_system::instance();
1874
        $context = \context_system::instance();
Línea 1930... Línea 1930...
1930
 
1930
 
1931
    /**
1931
    /**
1932
     * A user without the moodle/calendar:manageownentries capability at the
1932
     * A user without the moodle/calendar:manageownentries capability at the
1933
     * system context should not be able to create a user event.
1933
     * system context should not be able to create a user event.
1934
     */
1934
     */
1935
    public function test_submit_create_update_form_create_user_event_no_permission() {
1935
    public function test_submit_create_update_form_create_user_event_no_permission(): void {
1936
        $generator = $this->getDataGenerator();
1936
        $generator = $this->getDataGenerator();
1937
        $user = $generator->create_user();
1937
        $user = $generator->create_user();
1938
        $roleid = $generator->create_role();
1938
        $roleid = $generator->create_role();
1939
        $context = \context_system::instance();
1939
        $context = \context_system::instance();
Línea 1991... Línea 1991...
1991
 
1991
 
1992
    /**
1992
    /**
1993
     * A user with the moodle/calendar:manageentries capability at the
1993
     * A user with the moodle/calendar:manageentries capability at the
1994
     * site course context should be able to create a site event.
1994
     * site course context should be able to create a site event.
1995
     */
1995
     */
1996
    public function test_submit_create_update_form_create_site_event() {
1996
    public function test_submit_create_update_form_create_site_event(): void {
1997
        $generator = $this->getDataGenerator();
1997
        $generator = $this->getDataGenerator();
1998
        $user = $generator->create_user();
1998
        $user = $generator->create_user();
1999
        $context = \context_system::instance();
1999
        $context = \context_system::instance();
2000
        $roleid = $generator->create_role();
2000
        $roleid = $generator->create_role();
Línea 2057... Línea 2057...
2057
 
2057
 
2058
    /**
2058
    /**
2059
     * A user without the moodle/calendar:manageentries capability at the
2059
     * A user without the moodle/calendar:manageentries capability at the
2060
     * site course context should not be able to create a site event.
2060
     * site course context should not be able to create a site event.
2061
     */
2061
     */
2062
    public function test_submit_create_update_form_create_site_event_no_permission() {
2062
    public function test_submit_create_update_form_create_site_event_no_permission(): void {
2063
        $generator = $this->getDataGenerator();
2063
        $generator = $this->getDataGenerator();
2064
        $user = $generator->create_user();
2064
        $user = $generator->create_user();
2065
        $context = \context_course::instance(SITEID);
2065
        $context = \context_course::instance(SITEID);
2066
        $roleid = $generator->create_role();
2066
        $roleid = $generator->create_role();
Línea 2119... Línea 2119...
2119
 
2119
 
2120
    /**
2120
    /**
2121
     * A user that has the moodle/calendar:manageentries in a course that they
2121
     * A user that has the moodle/calendar:manageentries in a course that they
2122
     * are enrolled in should be able to create a course event in that course.
2122
     * are enrolled in should be able to create a course event in that course.
2123
     */
2123
     */
2124
    public function test_submit_create_update_form_create_course_event() {
2124
    public function test_submit_create_update_form_create_course_event(): void {
2125
        $generator = $this->getDataGenerator();
2125
        $generator = $this->getDataGenerator();
2126
        $user = $generator->create_user();
2126
        $user = $generator->create_user();
2127
        $course = $generator->create_course();
2127
        $course = $generator->create_course();
2128
        $context = \context_course::instance($course->id);
2128
        $context = \context_course::instance($course->id);
Línea 2189... Línea 2189...
2189
 
2189
 
2190
    /**
2190
    /**
2191
     * A user without the moodle/calendar:manageentries capability in a course
2191
     * A user without the moodle/calendar:manageentries capability in a course
2192
     * that they are enrolled in should not be able to create a course event in that course.
2192
     * that they are enrolled in should not be able to create a course event in that course.
2193
     */
2193
     */
2194
    public function test_submit_create_update_form_create_course_event_no_permission() {
2194
    public function test_submit_create_update_form_create_course_event_no_permission(): void {
2195
        $generator = $this->getDataGenerator();
2195
        $generator = $this->getDataGenerator();
2196
        $user = $generator->create_user();
2196
        $user = $generator->create_user();
2197
        $course = $generator->create_course();
2197
        $course = $generator->create_course();
2198
        $context = \context_course::instance($course->id);
2198
        $context = \context_course::instance($course->id);
Línea 2254... Línea 2254...
2254
 
2254
 
2255
    /**
2255
    /**
2256
     * A user should not be able to create an event for a course that they are
2256
     * A user should not be able to create an event for a course that they are
2257
     * not enrolled in.
2257
     * not enrolled in.
2258
     */
2258
     */
2259
    public function test_submit_create_update_form_create_course_event_not_enrolled() {
2259
    public function test_submit_create_update_form_create_course_event_not_enrolled(): void {
2260
        $generator = $this->getDataGenerator();
2260
        $generator = $this->getDataGenerator();
2261
        $user = $generator->create_user();
2261
        $user = $generator->create_user();
2262
        $course = $generator->create_course();
2262
        $course = $generator->create_course();
2263
        $course2 = $generator->create_course();
2263
        $course2 = $generator->create_course();
Línea 2320... Línea 2320...
2320
 
2320
 
2321
    /**
2321
    /**
2322
     * A user should be able to create an event for a group that they are a member of in
2322
     * A user should be able to create an event for a group that they are a member of in
2323
     * a course in which they are enrolled and have the moodle/calendar:manageentries capability.
2323
     * a course in which they are enrolled and have the moodle/calendar:manageentries capability.
2324
     */
2324
     */
2325
    public function test_submit_create_update_form_create_group_event_group_member_manage_course() {
2325
    public function test_submit_create_update_form_create_group_event_group_member_manage_course(): void {
2326
        $generator = $this->getDataGenerator();
2326
        $generator = $this->getDataGenerator();
2327
        $user = $generator->create_user();
2327
        $user = $generator->create_user();
2328
        $course = $generator->create_course();
2328
        $course = $generator->create_course();
2329
        $group = $generator->create_group(array('courseid' => $course->id));
2329
        $group = $generator->create_group(array('courseid' => $course->id));
Línea 2393... Línea 2393...
2393
 
2393
 
2394
    /**
2394
    /**
2395
     * A user should be able to create an event for a group that they are a member of in
2395
     * A user should be able to create an event for a group that they are a member of in
2396
     * a course in which they are enrolled and have the moodle/calendar:managegroupentries capability.
2396
     * a course in which they are enrolled and have the moodle/calendar:managegroupentries capability.
2397
     */
2397
     */
2398
    public function test_submit_create_update_form_create_group_event_group_member_manage_group_entries() {
2398
    public function test_submit_create_update_form_create_group_event_group_member_manage_group_entries(): void {
2399
        $generator = $this->getDataGenerator();
2399
        $generator = $this->getDataGenerator();
2400
        $user = $generator->create_user();
2400
        $user = $generator->create_user();
2401
        $course = $generator->create_course();
2401
        $course = $generator->create_course();
2402
        $group = $generator->create_group(array('courseid' => $course->id));
2402
        $group = $generator->create_group(array('courseid' => $course->id));
Línea 2467... Línea 2467...
2467
 
2467
 
2468
    /**
2468
    /**
2469
     * A user should be able to create an event for any group in a course in which
2469
     * A user should be able to create an event for any group in a course in which
2470
     * they are enrolled and have the moodle/site:accessallgroups capability.
2470
     * they are enrolled and have the moodle/site:accessallgroups capability.
2471
     */
2471
     */
2472
    public function test_submit_create_update_form_create_group_event_access_all_groups() {
2472
    public function test_submit_create_update_form_create_group_event_access_all_groups(): void {
2473
        $generator = $this->getDataGenerator();
2473
        $generator = $this->getDataGenerator();
2474
        $user = $generator->create_user();
2474
        $user = $generator->create_user();
2475
        $course = $generator->create_course();
2475
        $course = $generator->create_course();
2476
        $group = $generator->create_group(array('courseid' => $course->id));
2476
        $group = $generator->create_group(array('courseid' => $course->id));
Línea 2541... Línea 2541...
2541
    /**
2541
    /**
2542
     * A user should not be able to create an event for any group that they are not a
2542
     * A user should not be able to create an event for any group that they are not a
2543
     * member of in a course in which they are enrolled but don't have the
2543
     * member of in a course in which they are enrolled but don't have the
2544
     * moodle/site:accessallgroups capability.
2544
     * moodle/site:accessallgroups capability.
2545
     */
2545
     */
2546
    public function test_submit_create_update_form_create_group_event_non_member_no_permission() {
2546
    public function test_submit_create_update_form_create_group_event_non_member_no_permission(): void {
2547
        $generator = $this->getDataGenerator();
2547
        $generator = $this->getDataGenerator();
2548
        $user = $generator->create_user();
2548
        $user = $generator->create_user();
2549
        $course = $generator->create_course();
2549
        $course = $generator->create_course();
2550
        $group = $generator->create_group(array('courseid' => $course->id));
2550
        $group = $generator->create_group(array('courseid' => $course->id));
2551
        $context = \context_course::instance($course->id);
2551
        $context = \context_course::instance($course->id);
Línea 2608... Línea 2608...
2608
    }
2608
    }
Línea 2609... Línea 2609...
2609
 
2609
 
2610
    /**
2610
    /**
2611
     * A user should not be able load the calendar monthly view for a course they cannot access.
2611
     * A user should not be able load the calendar monthly view for a course they cannot access.
2612
     */
2612
     */
2613
    public function test_get_calendar_monthly_view_no_course_permission() {
2613
    public function test_get_calendar_monthly_view_no_course_permission(): void {
2614
        global $USER;
2614
        global $USER;
2615
        $this->resetAfterTest(true);
2615
        $this->resetAfterTest(true);
Línea 2616... Línea 2616...
2616
        $this->setAdminUser();
2616
        $this->setAdminUser();
Línea 2652... Línea 2652...
2652
    }
2652
    }
Línea 2653... Línea 2653...
2653
 
2653
 
2654
    /**
2654
    /**
2655
     * Test get_calendar_monthly_view when a day parameter is provided.
2655
     * Test get_calendar_monthly_view when a day parameter is provided.
2656
     */
2656
     */
2657
    public function test_get_calendar_monthly_view_with_day_provided() {
2657
    public function test_get_calendar_monthly_view_with_day_provided(): void {
2658
        $this->resetAfterTest();
2658
        $this->resetAfterTest();
Línea 2659... Línea 2659...
2659
        $this->setAdminUser();
2659
        $this->setAdminUser();
2660
 
2660
 
Línea 2668... Línea 2668...
2668
    }
2668
    }
Línea 2669... Línea 2669...
2669
 
2669
 
2670
    /**
2670
    /**
2671
     * A user should not be able load the calendar day view for a course they cannot access.
2671
     * A user should not be able load the calendar day view for a course they cannot access.
2672
     */
2672
     */
2673
    public function test_get_calendar_day_view_no_course_permission() {
2673
    public function test_get_calendar_day_view_no_course_permission(): void {
2674
        global $USER;
2674
        global $USER;
2675
        $this->resetAfterTest(true);
2675
        $this->resetAfterTest(true);
Línea 2676... Línea 2676...
2676
        $this->setAdminUser();
2676
        $this->setAdminUser();
Línea 2712... Línea 2712...
2712
    }
2712
    }
Línea 2713... Línea 2713...
2713
 
2713
 
2714
    /**
2714
    /**
2715
     * A user should not be able load the calendar upcoming view for a course they cannot access.
2715
     * A user should not be able load the calendar upcoming view for a course they cannot access.
2716
     */
2716
     */
2717
    public function test_get_calendar_upcoming_view_no_course_permission() {
2717
    public function test_get_calendar_upcoming_view_no_course_permission(): void {
2718
        global $USER;
2718
        global $USER;
2719
        $this->resetAfterTest(true);
2719
        $this->resetAfterTest(true);
Línea 2720... Línea 2720...
2720
        $this->setAdminUser();
2720
        $this->setAdminUser();
Línea 2752... Línea 2752...
2752
    }
2752
    }
Línea 2753... Línea 2753...
2753
 
2753
 
2754
    /**
2754
    /**
2755
     * A user should not be able load the calendar event for a course they cannot access.
2755
     * A user should not be able load the calendar event for a course they cannot access.
2756
     */
2756
     */
2757
    public function test_get_calendar_event_by_id_no_course_permission() {
2757
    public function test_get_calendar_event_by_id_no_course_permission(): void {
2758
        global $USER;
2758
        global $USER;
2759
        $this->resetAfterTest(true);
2759
        $this->resetAfterTest(true);
Línea 2760... Línea 2760...
2760
        $this->setAdminUser();
2760
        $this->setAdminUser();
Línea 2819... Línea 2819...
2819
     * @param null|string   $readerrolename    Role name
2819
     * @param null|string   $readerrolename    Role name
2820
     * @param bool          $expectexception   Should the test throw exception
2820
     * @param bool          $expectexception   Should the test throw exception
2821
     */
2821
     */
2822
    public function test_get_calendar_event_by_id_prevent_read_other_users_events(
2822
    public function test_get_calendar_event_by_id_prevent_read_other_users_events(
2823
            bool $isadminevent, bool $isadmin, ?\stdClass $readerrolecontext,
2823
            bool $isadminevent, bool $isadmin, ?\stdClass $readerrolecontext,
2824
            ?string $readerrolename, bool $expectexception) {
2824
            ?string $readerrolename, bool $expectexception): void {
2825
        global $USER, $DB;
2825
        global $USER, $DB;
Línea 2826... Línea 2826...
2826
 
2826
 
2827
        $this->resetAfterTest();
2827
        $this->resetAfterTest();
Línea 2888... Línea 2888...
2888
     * @param stdClass|null $writerrolecontext The reader role context.
2888
     * @param stdClass|null $writerrolecontext The reader role context.
2889
     * @param string|null   $writerrolename The role name.
2889
     * @param string|null   $writerrolename The role name.
2890
     * @param bool          $expectexception Whether the test should throw an exception or not.
2890
     * @param bool          $expectexception Whether the test should throw an exception or not.
2891
     */
2891
     */
2892
    public function test_delete_other_users_events(bool $isadmin, bool $isadminevent,
2892
    public function test_delete_other_users_events(bool $isadmin, bool $isadminevent,
2893
            ?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception) {
2893
            ?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception): void {
2894
        global $DB, $USER;
2894
        global $DB, $USER;
Línea 2895... Línea 2895...
2895
 
2895
 
2896
        $this->resetAfterTest();
2896
        $this->resetAfterTest();
Línea 2935... Línea 2935...
2935
     * @param stdClass|null $writerrolecontext The reader role context.
2935
     * @param stdClass|null $writerrolecontext The reader role context.
2936
     * @param string|null   $writerrolename The role name.
2936
     * @param string|null   $writerrolename The role name.
2937
     * @param bool          $expectexception Whether the test should throw an exception or not.
2937
     * @param bool          $expectexception Whether the test should throw an exception or not.
2938
     */
2938
     */
2939
    public function test_edit_other_users_events(bool $isadmin, bool $isadminevent,
2939
    public function test_edit_other_users_events(bool $isadmin, bool $isadminevent,
2940
            ?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception) {
2940
            ?\stdClass $writerrolecontext, ?string $writerrolename, bool $expectexception): void {
2941
        global $DB, $USER;
2941
        global $DB, $USER;
Línea 2942... Línea 2942...
2942
 
2942
 
Línea 2943... Línea 2943...
2943
        $this->resetAfterTest();
2943
        $this->resetAfterTest();
Línea 2996... Línea 2996...
2996
    }
2996
    }
Línea 2997... Línea 2997...
2997
 
2997
 
2998
    /**
2998
    /**
2999
     * A user should not be able load the calendar events for a category they cannot see.
2999
     * A user should not be able load the calendar events for a category they cannot see.
3000
     */
3000
     */
3001
    public function test_get_calendar_events_hidden_category() {
3001
    public function test_get_calendar_events_hidden_category(): void {
3002
        global $USER;
3002
        global $USER;
3003
        $this->resetAfterTest(true);
3003
        $this->resetAfterTest(true);
Línea 3004... Línea 3004...
3004
        $this->setAdminUser();
3004
        $this->setAdminUser();
Línea 3032... Línea 3032...
3032
    }
3032
    }
Línea 3033... Línea 3033...
3033
 
3033
 
3034
    /**
3034
    /**
3035
     * Test get_calendar_access_information for admins.
3035
     * Test get_calendar_access_information for admins.
3036
     */
3036
     */
3037
    public function test_get_calendar_access_information_for_admins() {
3037
    public function test_get_calendar_access_information_for_admins(): void {
3038
        global $CFG;
3038
        global $CFG;
3039
        $this->resetAfterTest(true);
3039
        $this->resetAfterTest(true);
Línea 3040... Línea 3040...
3040
        $this->setAdminUser();
3040
        $this->setAdminUser();
Línea 3051... Línea 3051...
3051
    }
3051
    }
Línea 3052... Línea 3052...
3052
 
3052
 
3053
    /**
3053
    /**
3054
     * Test get_calendar_access_information for authenticated users.
3054
     * Test get_calendar_access_information for authenticated users.
3055
     */
3055
     */
3056
    public function test_get_calendar_access_information_for_authenticated_users() {
3056
    public function test_get_calendar_access_information_for_authenticated_users(): void {
3057
        $this->resetAfterTest(true);
3057
        $this->resetAfterTest(true);
Línea 3058... Línea 3058...
3058
        $this->setUser($this->getDataGenerator()->create_user());
3058
        $this->setUser($this->getDataGenerator()->create_user());
3059
 
3059
 
Línea 3067... Línea 3067...
3067
    }
3067
    }
Línea 3068... Línea 3068...
3068
 
3068
 
3069
    /**
3069
    /**
3070
     * Test get_calendar_access_information for student users.
3070
     * Test get_calendar_access_information for student users.
3071
     */
3071
     */
3072
    public function test_get_calendar_access_information_for_student_users() {
3072
    public function test_get_calendar_access_information_for_student_users(): void {
3073
        global $DB;
3073
        global $DB;
Línea 3074... Línea 3074...
3074
        $this->resetAfterTest(true);
3074
        $this->resetAfterTest(true);
3075
 
3075
 
Línea 3090... Línea 3090...
3090
    }
3090
    }
Línea 3091... Línea 3091...
3091
 
3091
 
3092
    /**
3092
    /**
3093
     * Test get_calendar_access_information for teacher users.
3093
     * Test get_calendar_access_information for teacher users.
3094
     */
3094
     */
3095
    public function test_get_calendar_access_information_for_teacher_users() {
3095
    public function test_get_calendar_access_information_for_teacher_users(): void {
3096
        global $DB;
3096
        global $DB;
Línea 3097... Línea 3097...
3097
        $this->resetAfterTest(true);
3097
        $this->resetAfterTest(true);
3098
 
3098
 
Línea 3114... Línea 3114...
3114
    }
3114
    }
Línea 3115... Línea 3115...
3115
 
3115
 
3116
    /**
3116
    /**
3117
     * Test get_allowed_event_types for admins.
3117
     * Test get_allowed_event_types for admins.
3118
     */
3118
     */
3119
    public function test_get_allowed_event_types_for_admins() {
3119
    public function test_get_allowed_event_types_for_admins(): void {
3120
        global $CFG;
3120
        global $CFG;
3121
        $this->resetAfterTest(true);
3121
        $this->resetAfterTest(true);
3122
        $this->setAdminUser();
3122
        $this->setAdminUser();
3123
        $CFG->calendar_adminseesall = 1;
3123
        $CFG->calendar_adminseesall = 1;
Línea 3128... Línea 3128...
3128
        $this->assertEquals(['user', 'site', 'course', 'category'], $data['allowedeventtypes']);
3128
        $this->assertEquals(['user', 'site', 'course', 'category'], $data['allowedeventtypes']);
3129
    }
3129
    }
3130
    /**
3130
    /**
3131
     * Test get_allowed_event_types for authenticated users.
3131
     * Test get_allowed_event_types for authenticated users.
3132
     */
3132
     */
3133
    public function test_get_allowed_event_types_for_authenticated_users() {
3133
    public function test_get_allowed_event_types_for_authenticated_users(): void {
3134
        $this->resetAfterTest(true);
3134
        $this->resetAfterTest(true);
3135
        $this->setUser($this->getDataGenerator()->create_user());
3135
        $this->setUser($this->getDataGenerator()->create_user());
3136
        $data = external_api::clean_returnvalue(
3136
        $data = external_api::clean_returnvalue(
3137
            core_calendar_external::get_allowed_event_types_returns(),
3137
            core_calendar_external::get_allowed_event_types_returns(),
3138
            core_calendar_external::get_allowed_event_types()
3138
            core_calendar_external::get_allowed_event_types()
Línea 3140... Línea 3140...
3140
        $this->assertEquals(['user'], $data['allowedeventtypes']);
3140
        $this->assertEquals(['user'], $data['allowedeventtypes']);
3141
    }
3141
    }
3142
    /**
3142
    /**
3143
     * Test get_allowed_event_types for student users.
3143
     * Test get_allowed_event_types for student users.
3144
     */
3144
     */
3145
    public function test_get_allowed_event_types_for_student_users() {
3145
    public function test_get_allowed_event_types_for_student_users(): void {
3146
        global $DB;
3146
        global $DB;
3147
        $this->resetAfterTest(true);
3147
        $this->resetAfterTest(true);
3148
        $user = $this->getDataGenerator()->create_user();
3148
        $user = $this->getDataGenerator()->create_user();
3149
        $course = $this->getDataGenerator()->create_course();
3149
        $course = $this->getDataGenerator()->create_course();
3150
        $role = $DB->get_record('role', array('shortname' => 'student'));
3150
        $role = $DB->get_record('role', array('shortname' => 'student'));
Línea 3157... Línea 3157...
3157
        $this->assertEquals(['user'], $data['allowedeventtypes']);
3157
        $this->assertEquals(['user'], $data['allowedeventtypes']);
3158
    }
3158
    }
3159
    /**
3159
    /**
3160
     * Test get_allowed_event_types for teacher users.
3160
     * Test get_allowed_event_types for teacher users.
3161
     */
3161
     */
3162
    public function test_get_allowed_event_types_for_teacher_users() {
3162
    public function test_get_allowed_event_types_for_teacher_users(): void {
3163
        global $DB;
3163
        global $DB;
3164
        $this->resetAfterTest(true);
3164
        $this->resetAfterTest(true);
3165
        $user = $this->getDataGenerator()->create_user();
3165
        $user = $this->getDataGenerator()->create_user();
3166
        $course = $this->getDataGenerator()->create_course(['groupmode' => 1]);
3166
        $course = $this->getDataGenerator()->create_course(['groupmode' => 1]);
3167
        $role = $DB->get_record('role', array('shortname' => 'editingteacher'));
3167
        $role = $DB->get_record('role', array('shortname' => 'editingteacher'));
Línea 3176... Línea 3176...
3176
    }
3176
    }
Línea 3177... Línea 3177...
3177
 
3177
 
3178
    /**
3178
    /**
3179
     * Test get_timestamps with string keys, with and without optional hour/minute values.
3179
     * Test get_timestamps with string keys, with and without optional hour/minute values.
3180
     */
3180
     */
3181
    public function test_get_timestamps_string_keys() {
3181
    public function test_get_timestamps_string_keys(): void {
3182
        $this->resetAfterTest(true);
3182
        $this->resetAfterTest(true);
Línea 3183... Línea 3183...
3183
        $this->setAdminUser();
3183
        $this->setAdminUser();
3184
 
3184
 
Línea 3219... Línea 3219...
3219
    }
3219
    }
Línea 3220... Línea 3220...
3220
 
3220
 
3221
    /**
3221
    /**
3222
     * Test get_timestamps with no keys specified, with and without optional hour/minute values.
3222
     * Test get_timestamps with no keys specified, with and without optional hour/minute values.
3223
     */
3223
     */
3224
    public function test_get_timestamps_no_keys() {
3224
    public function test_get_timestamps_no_keys(): void {
3225
        $this->resetAfterTest(true);
3225
        $this->resetAfterTest(true);
Línea 3226... Línea 3226...
3226
        $this->setAdminUser();
3226
        $this->setAdminUser();
3227
 
3227