Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 34... Línea 34...
34
 * @copyright  2016 Stephen Bourget
34
 * @copyright  2016 Stephen Bourget
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
36
 */
37
class lib_test extends \advanced_testcase {
37
class lib_test extends \advanced_testcase {
Línea 38... Línea 38...
38
 
38
 
39
    public function test_feedback_initialise() {
39
    public function test_feedback_initialise(): void {
40
        $this->resetAfterTest();
40
        $this->resetAfterTest();
Línea 41... Línea 41...
41
        $this->setAdminUser();
41
        $this->setAdminUser();
42
 
42
 
Línea 70... Línea 70...
70
    }
70
    }
Línea 71... Línea 71...
71
 
71
 
72
    /**
72
    /**
73
     * Tests for mod_feedback_refresh_events.
73
     * Tests for mod_feedback_refresh_events.
74
     */
74
     */
75
    public function test_feedback_refresh_events() {
75
    public function test_feedback_refresh_events(): void {
76
        global $DB;
76
        global $DB;
77
        $this->resetAfterTest();
77
        $this->resetAfterTest();
Línea 78... Línea 78...
78
        $this->setAdminUser();
78
        $this->setAdminUser();
Línea 115... Línea 115...
115
    }
115
    }
Línea 116... Línea 116...
116
 
116
 
117
    /**
117
    /**
118
     * Test check_updates_since callback.
118
     * Test check_updates_since callback.
119
     */
119
     */
120
    public function test_check_updates_since() {
120
    public function test_check_updates_since(): void {
Línea 121... Línea 121...
121
        global $DB;
121
        global $DB;
122
 
122
 
123
        $this->resetAfterTest();
123
        $this->resetAfterTest();
Línea 175... Línea 175...
175
    }
175
    }
Línea 176... Línea 176...
176
 
176
 
177
    /**
177
    /**
178
     * Test calendar event provide action open.
178
     * Test calendar event provide action open.
179
     */
179
     */
180
    public function test_feedback_core_calendar_provide_event_action_open() {
180
    public function test_feedback_core_calendar_provide_event_action_open(): void {
181
        $this->resetAfterTest();
181
        $this->resetAfterTest();
Línea 182... Línea 182...
182
        $this->setAdminUser();
182
        $this->setAdminUser();
183
 
183
 
Línea 198... Línea 198...
198
    }
198
    }
Línea 199... Línea 199...
199
 
199
 
200
    /**
200
    /**
201
     * Test calendar event provide action open, viewed by a different user.
201
     * Test calendar event provide action open, viewed by a different user.
202
     */
202
     */
203
    public function test_feedback_core_calendar_provide_event_action_open_for_user() {
203
    public function test_feedback_core_calendar_provide_event_action_open_for_user(): void {
Línea 204... Línea 204...
204
        global $DB;
204
        global $DB;
205
 
205
 
Línea 234... Línea 234...
234
    }
234
    }
Línea 235... Línea 235...
235
 
235
 
236
    /**
236
    /**
237
     * Test calendar event provide action closed.
237
     * Test calendar event provide action closed.
238
     */
238
     */
239
    public function test_feedback_core_calendar_provide_event_action_closed() {
239
    public function test_feedback_core_calendar_provide_event_action_closed(): void {
240
        $this->resetAfterTest();
240
        $this->resetAfterTest();
Línea 241... Línea 241...
241
        $this->setAdminUser();
241
        $this->setAdminUser();
242
 
242
 
Línea 253... Línea 253...
253
    }
253
    }
Línea 254... Línea 254...
254
 
254
 
255
    /**
255
    /**
256
     * Test calendar event provide action closed, viewed by a different user.
256
     * Test calendar event provide action closed, viewed by a different user.
257
     */
257
     */
258
    public function test_feedback_core_calendar_provide_event_action_closed_for_user() {
258
    public function test_feedback_core_calendar_provide_event_action_closed_for_user(): void {
Línea 259... Línea 259...
259
        global $DB;
259
        global $DB;
260
 
260
 
Línea 287... Línea 287...
287
    /**
287
    /**
288
     * Test calendar event action open in future.
288
     * Test calendar event action open in future.
289
     *
289
     *
290
     * @throws coding_exception
290
     * @throws coding_exception
291
     */
291
     */
292
    public function test_feedback_core_calendar_provide_event_action_open_in_future() {
292
    public function test_feedback_core_calendar_provide_event_action_open_in_future(): void {
293
        $this->resetAfterTest();
293
        $this->resetAfterTest();
294
        $this->setAdminUser();
294
        $this->setAdminUser();
Línea 295... Línea 295...
295
 
295
 
296
        $course = $this->getDataGenerator()->create_course();
296
        $course = $this->getDataGenerator()->create_course();
Línea 311... Línea 311...
311
    /**
311
    /**
312
     * Test calendar event action open in future, viewed by a different user.
312
     * Test calendar event action open in future, viewed by a different user.
313
     *
313
     *
314
     * @throws coding_exception
314
     * @throws coding_exception
315
     */
315
     */
316
    public function test_feedback_core_calendar_provide_event_action_open_in_future_for_user() {
316
    public function test_feedback_core_calendar_provide_event_action_open_in_future_for_user(): void {
317
        global $DB;
317
        global $DB;
Línea 318... Línea 318...
318
 
318
 
319
        $this->resetAfterTest();
319
        $this->resetAfterTest();
Línea 349... Línea 349...
349
    /**
349
    /**
350
     * Test calendar event with no time specified.
350
     * Test calendar event with no time specified.
351
     *
351
     *
352
     * @throws coding_exception
352
     * @throws coding_exception
353
     */
353
     */
354
    public function test_feedback_core_calendar_provide_event_action_no_time_specified() {
354
    public function test_feedback_core_calendar_provide_event_action_no_time_specified(): void {
355
        $this->resetAfterTest();
355
        $this->resetAfterTest();
356
        $this->setAdminUser();
356
        $this->setAdminUser();
Línea 357... Línea 357...
357
 
357
 
358
        $course = $this->getDataGenerator()->create_course();
358
        $course = $this->getDataGenerator()->create_course();
Línea 372... Línea 372...
372
    /**
372
    /**
373
     * Test calendar event with no time specified, viewed by a different user.
373
     * Test calendar event with no time specified, viewed by a different user.
374
     *
374
     *
375
     * @throws coding_exception
375
     * @throws coding_exception
376
     */
376
     */
377
    public function test_feedback_core_calendar_provide_event_action_no_time_specified_for_user() {
377
    public function test_feedback_core_calendar_provide_event_action_no_time_specified_for_user(): void {
378
        global $DB;
378
        global $DB;
Línea 379... Línea 379...
379
 
379
 
380
        $this->resetAfterTest();
380
        $this->resetAfterTest();
Línea 407... Línea 407...
407
    }
407
    }
Línea 408... Línea 408...
408
 
408
 
409
    /**
409
    /**
410
     * A user that can not submit feedback should not have an action.
410
     * A user that can not submit feedback should not have an action.
411
     */
411
     */
412
    public function test_feedback_core_calendar_provide_event_action_can_not_submit() {
412
    public function test_feedback_core_calendar_provide_event_action_can_not_submit(): void {
Línea 413... Línea 413...
413
        global $DB;
413
        global $DB;
414
 
414
 
Línea 434... Línea 434...
434
    }
434
    }
Línea 435... Línea 435...
435
 
435
 
436
    /**
436
    /**
437
     * A user that can not submit feedback should not have an action, viewed by a different user.
437
     * A user that can not submit feedback should not have an action, viewed by a different user.
438
     */
438
     */
439
    public function test_feedback_core_calendar_provide_event_action_can_not_submit_for_user() {
439
    public function test_feedback_core_calendar_provide_event_action_can_not_submit_for_user(): void {
Línea 440... Línea 440...
440
        global $DB;
440
        global $DB;
441
 
441
 
Línea 468... Línea 468...
468
    }
468
    }
Línea 469... Línea 469...
469
 
469
 
470
    /**
470
    /**
471
     * A user that has already submitted feedback should not have an action.
471
     * A user that has already submitted feedback should not have an action.
472
     */
472
     */
473
    public function test_feedback_core_calendar_provide_event_action_already_submitted() {
473
    public function test_feedback_core_calendar_provide_event_action_already_submitted(): void {
Línea 474... Línea 474...
474
        global $DB;
474
        global $DB;
475
 
475
 
Línea 503... Línea 503...
503
    }
503
    }
Línea 504... Línea 504...
504
 
504
 
505
    /**
505
    /**
506
     * A user that has already submitted feedback should not have an action, viewed by a different user.
506
     * A user that has already submitted feedback should not have an action, viewed by a different user.
507
     */
507
     */
508
    public function test_feedback_core_calendar_provide_event_action_already_submitted_for_user() {
508
    public function test_feedback_core_calendar_provide_event_action_already_submitted_for_user(): void {
Línea 509... Línea 509...
509
        global $DB;
509
        global $DB;
510
 
510
 
Línea 543... Línea 543...
543
        $actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory, $user->id);
543
        $actionevent = mod_feedback_core_calendar_provide_event_action($event, $factory, $user->id);
Línea 544... Línea 544...
544
 
544
 
545
        $this->assertNull($actionevent);
545
        $this->assertNull($actionevent);
Línea 546... Línea 546...
546
    }
546
    }
547
 
547
 
548
    public function test_feedback_core_calendar_provide_event_action_already_completed() {
548
    public function test_feedback_core_calendar_provide_event_action_already_completed(): void {
549
        $this->resetAfterTest();
549
        $this->resetAfterTest();
Línea 550... Línea 550...
550
        set_config('enablecompletion', 1);
550
        set_config('enablecompletion', 1);
Línea 574... Línea 574...
574
 
574
 
575
        // Ensure result was null.
575
        // Ensure result was null.
576
        $this->assertNull($actionevent);
576
        $this->assertNull($actionevent);
Línea 577... Línea 577...
577
    }
577
    }
578
 
578
 
579
    public function test_feedback_core_calendar_provide_event_action_already_completed_for_user() {
579
    public function test_feedback_core_calendar_provide_event_action_already_completed_for_user(): void {
580
        $this->resetAfterTest();
580
        $this->resetAfterTest();
Línea 581... Línea 581...
581
        set_config('enablecompletion', 1);
581
        set_config('enablecompletion', 1);
Línea 634... Línea 634...
634
    /**
634
    /**
635
     * Test the callback responsible for returning the completion rule descriptions.
635
     * Test the callback responsible for returning the completion rule descriptions.
636
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
636
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
637
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
637
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
638
     */
638
     */
639
    public function test_mod_feedback_completion_get_active_rule_descriptions() {
639
    public function test_mod_feedback_completion_get_active_rule_descriptions(): void {
640
        $this->resetAfterTest();
640
        $this->resetAfterTest();
641
        $this->setAdminUser();
641
        $this->setAdminUser();
Línea 642... Línea 642...
642
 
642
 
643
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
643
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
Línea 670... Línea 670...
670
    }
670
    }
Línea 671... Línea 671...
671
 
671
 
672
    /**
672
    /**
673
     * An unknown event should not have min or max restrictions.
673
     * An unknown event should not have min or max restrictions.
674
     */
674
     */
675
    public function test_get_valid_event_timestart_range_unknown_event() {
675
    public function test_get_valid_event_timestart_range_unknown_event(): void {
676
        global $CFG, $DB;
676
        global $CFG, $DB;
Línea 677... Línea 677...
677
        require_once($CFG->dirroot . "/calendar/lib.php");
677
        require_once($CFG->dirroot . "/calendar/lib.php");
678
 
678
 
Línea 710... Línea 710...
710
 
710
 
711
    /**
711
    /**
712
     * A FEEDBACK_EVENT_TYPE_OPEN should have a max timestart equal to the activity
712
     * A FEEDBACK_EVENT_TYPE_OPEN should have a max timestart equal to the activity
713
     * close time.
713
     * close time.
714
     */
714
     */
715
    public function test_get_valid_event_timestart_range_event_type_open() {
715
    public function test_get_valid_event_timestart_range_event_type_open(): void {
716
        global $CFG, $DB;
716
        global $CFG, $DB;
Línea 717... Línea 717...
717
        require_once($CFG->dirroot . "/calendar/lib.php");
717
        require_once($CFG->dirroot . "/calendar/lib.php");
718
 
718
 
Línea 751... Línea 751...
751
 
751
 
752
    /**
752
    /**
753
     * A FEEDBACK_EVENT_TYPE_OPEN should not have a max timestamp if the activity
753
     * A FEEDBACK_EVENT_TYPE_OPEN should not have a max timestamp if the activity
754
     * doesn't have a close date.
754
     * doesn't have a close date.
755
     */
755
     */
756
    public function test_get_valid_event_timestart_range_event_type_open_no_close() {
756
    public function test_get_valid_event_timestart_range_event_type_open_no_close(): void {
757
        global $CFG, $DB;
757
        global $CFG, $DB;
Línea 758... Línea 758...
758
        require_once($CFG->dirroot . "/calendar/lib.php");
758
        require_once($CFG->dirroot . "/calendar/lib.php");
759
 
759
 
Línea 791... Línea 791...
791
 
791
 
792
    /**
792
    /**
793
     * A FEEDBACK_EVENT_TYPE_CLOSE should have a min timestart equal to the activity
793
     * A FEEDBACK_EVENT_TYPE_CLOSE should have a min timestart equal to the activity
794
     * open time.
794
     * open time.
795
     */
795
     */
796
    public function test_get_valid_event_timestart_range_event_type_close() {
796
    public function test_get_valid_event_timestart_range_event_type_close(): void {
797
        global $CFG, $DB;
797
        global $CFG, $DB;
Línea 798... Línea 798...
798
        require_once($CFG->dirroot . "/calendar/lib.php");
798
        require_once($CFG->dirroot . "/calendar/lib.php");
799
 
799
 
Línea 832... Línea 832...
832
 
832
 
833
    /**
833
    /**
834
     * A FEEDBACK_EVENT_TYPE_CLOSE should not have a minimum timestamp if the activity
834
     * A FEEDBACK_EVENT_TYPE_CLOSE should not have a minimum timestamp if the activity
835
     * doesn't have an open date.
835
     * doesn't have an open date.
836
     */
836
     */
837
    public function test_get_valid_event_timestart_range_event_type_close_no_open() {
837
    public function test_get_valid_event_timestart_range_event_type_close_no_open(): void {
838
        global $CFG, $DB;
838
        global $CFG, $DB;
Línea 839... Línea 839...
839
        require_once($CFG->dirroot . "/calendar/lib.php");
839
        require_once($CFG->dirroot . "/calendar/lib.php");
840
 
840
 
Línea 871... Línea 871...
871
    }
871
    }
Línea 872... Línea 872...
872
 
872
 
873
    /**
873
    /**
874
     * An unkown event type should not change the feedback instance.
874
     * An unkown event type should not change the feedback instance.
875
     */
875
     */
876
    public function test_mod_feedback_core_calendar_event_timestart_updated_unknown_event() {
876
    public function test_mod_feedback_core_calendar_event_timestart_updated_unknown_event(): void {
877
        global $CFG, $DB;
877
        global $CFG, $DB;
Línea 878... Línea 878...
878
        require_once($CFG->dirroot . "/calendar/lib.php");
878
        require_once($CFG->dirroot . "/calendar/lib.php");
879
 
879
 
Línea 914... Línea 914...
914
 
914
 
915
    /**
915
    /**
916
     * A FEEDBACK_EVENT_TYPE_OPEN event should update the timeopen property of
916
     * A FEEDBACK_EVENT_TYPE_OPEN event should update the timeopen property of
917
     * the feedback activity.
917
     * the feedback activity.
918
     */
918
     */
919
    public function test_mod_feedback_core_calendar_event_timestart_updated_open_event() {
919
    public function test_mod_feedback_core_calendar_event_timestart_updated_open_event(): void {
920
        global $CFG, $DB;
920
        global $CFG, $DB;
Línea 921... Línea 921...
921
        require_once($CFG->dirroot . "/calendar/lib.php");
921
        require_once($CFG->dirroot . "/calendar/lib.php");
922
 
922
 
Línea 964... Línea 964...
964
 
964
 
965
    /**
965
    /**
966
     * A FEEDBACK_EVENT_TYPE_CLOSE event should update the timeclose property of
966
     * A FEEDBACK_EVENT_TYPE_CLOSE event should update the timeclose property of
967
     * the feedback activity.
967
     * the feedback activity.
968
     */
968
     */
969
    public function test_mod_feedback_core_calendar_event_timestart_updated_close_event() {
969
    public function test_mod_feedback_core_calendar_event_timestart_updated_close_event(): void {
970
        global $CFG, $DB;
970
        global $CFG, $DB;
Línea 971... Línea 971...
971
        require_once($CFG->dirroot . "/calendar/lib.php");
971
        require_once($CFG->dirroot . "/calendar/lib.php");
972
 
972
 
Línea 1015... Línea 1015...
1015
    /**
1015
    /**
1016
     * If a student somehow finds a way to update the calendar event
1016
     * If a student somehow finds a way to update the calendar event
1017
     * then the callback should not be executed to update the activity
1017
     * then the callback should not be executed to update the activity
1018
     * properties as well because that would be a security issue.
1018
     * properties as well because that would be a security issue.
1019
     */
1019
     */
1020
    public function test_student_role_cant_update_time_close_event() {
1020
    public function test_student_role_cant_update_time_close_event(): void {
1021
        global $CFG, $DB;
1021
        global $CFG, $DB;
1022
        require_once($CFG->dirroot . '/calendar/lib.php');
1022
        require_once($CFG->dirroot . '/calendar/lib.php');
Línea 1023... Línea 1023...
1023
 
1023
 
1024
        $this->resetAfterTest();
1024
        $this->resetAfterTest();
Línea 1074... Línea 1074...
1074
 
1074
 
1075
    /**
1075
    /**
1076
     * The activity should update if a teacher modifies the calendar
1076
     * The activity should update if a teacher modifies the calendar
1077
     * event.
1077
     * event.
1078
     */
1078
     */
1079
    public function test_teacher_role_can_update_time_close_event() {
1079
    public function test_teacher_role_can_update_time_close_event(): void {
1080
        global $CFG, $DB;
1080
        global $CFG, $DB;
Línea 1081... Línea 1081...
1081
        require_once($CFG->dirroot . '/calendar/lib.php');
1081
        require_once($CFG->dirroot . '/calendar/lib.php');
1082
 
1082
 
Línea 1142... Línea 1142...
1142
    }
1142
    }
Línea 1143... Línea 1143...
1143
 
1143
 
1144
    /**
1144
    /**
1145
     * A user who does not have capabilities to add events to the calendar should be able to create an feedback.
1145
     * A user who does not have capabilities to add events to the calendar should be able to create an feedback.
1146
     */
1146
     */
1147
    public function test_creation_with_no_calendar_capabilities() {
1147
    public function test_creation_with_no_calendar_capabilities(): void {
1148
        $this->resetAfterTest();
1148
        $this->resetAfterTest();
1149
        $course = self::getDataGenerator()->create_course();
1149
        $course = self::getDataGenerator()->create_course();
1150
        $context = \context_course::instance($course->id);
1150
        $context = \context_course::instance($course->id);
1151
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
1151
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');