Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 45... Línea 45...
45
 
45
 
46
    /**
46
    /**
47
     * Test choice_view
47
     * Test choice_view
48
     * @return void
48
     * @return void
49
     */
49
     */
50
    public function test_choice_view() {
50
    public function test_choice_view(): void {
Línea 51... Línea 51...
51
        global $CFG;
51
        global $CFG;
Línea 52... Línea 52...
52
 
52
 
Línea 79... Línea 79...
79
 
79
 
80
    /**
80
    /**
81
     * Test choice_can_view_results
81
     * Test choice_can_view_results
82
     * @return void
82
     * @return void
83
     */
83
     */
84
    public function test_choice_can_view_results() {
84
    public function test_choice_can_view_results(): void {
Línea 85... Línea 85...
85
        global $DB, $USER;
85
        global $DB, $USER;
Línea 86... Línea 86...
86
 
86
 
Línea 137... Línea 137...
137
        $canview = choice_can_view_results($choice);
137
        $canview = choice_can_view_results($choice);
138
        $this->assertTrue($canview);
138
        $this->assertTrue($canview);
Línea 139... Línea 139...
139
 
139
 
Línea 140... Línea 140...
140
    }
140
    }
141
 
141
 
Línea 142... Línea 142...
142
    public function test_choice_user_submit_response_validation() {
142
    public function test_choice_user_submit_response_validation(): void {
Línea 143... Línea 143...
143
        global $USER;
143
        global $USER;
Línea 163... Línea 163...
163
 
163
 
164
    /**
164
    /**
165
     * Test choice_get_user_response
165
     * Test choice_get_user_response
166
     * @return void
166
     * @return void
167
     */
167
     */
168
    public function test_choice_get_user_response() {
168
    public function test_choice_get_user_response(): void {
Línea 169... Línea 169...
169
        $this->resetAfterTest();
169
        $this->resetAfterTest();
170
 
170
 
171
        $this->setAdminUser();
171
        $this->setAdminUser();
Línea 204... Línea 204...
204
 
204
 
205
    /**
205
    /**
206
     * Test choice_get_my_response
206
     * Test choice_get_my_response
207
     * @return void
207
     * @return void
208
     */
208
     */
209
    public function test_choice_get_my_response() {
209
    public function test_choice_get_my_response(): void {
Línea 210... Línea 210...
210
        global $USER;
210
        global $USER;
Línea 211... Línea 211...
211
 
211
 
Línea 246... Línea 246...
246
 
246
 
247
    /**
247
    /**
248
     * Test choice_get_availability_status
248
     * Test choice_get_availability_status
249
     * @return void
249
     * @return void
250
     */
250
     */
251
    public function test_choice_get_availability_status() {
251
    public function test_choice_get_availability_status(): void {
Línea 252... Línea 252...
252
        global $USER;
252
        global $USER;
Línea 253... Línea 253...
253
 
253
 
Línea 306... Línea 306...
306
    }
306
    }
Línea 307... Línea 307...
307
 
307
 
308
    /*
308
    /*
309
     * The choice's event should not be shown to a user when the user cannot view the choice activity at all.
309
     * The choice's event should not be shown to a user when the user cannot view the choice activity at all.
310
     */
310
     */
311
    public function test_choice_core_calendar_provide_event_action_in_hidden_section() {
311
    public function test_choice_core_calendar_provide_event_action_in_hidden_section(): void {
Línea 312... Línea 312...
312
        global $CFG;
312
        global $CFG;
Línea 313... Línea 313...
313
 
313
 
Línea 346... Línea 346...
346
    }
346
    }
Línea 347... Línea 347...
347
 
347
 
348
    /*
348
    /*
349
     * The choice's event should not be shown to a user who does not have permission to view the choice.
349
     * The choice's event should not be shown to a user who does not have permission to view the choice.
350
     */
350
     */
351
    public function test_choice_core_calendar_provide_event_action_for_non_user() {
351
    public function test_choice_core_calendar_provide_event_action_for_non_user(): void {
Línea 352... Línea 352...
352
        global $CFG;
352
        global $CFG;
Línea 353... Línea 353...
353
 
353
 
Línea 377... Línea 377...
377
 
377
 
378
        // Confirm the event is not shown at all.
378
        // Confirm the event is not shown at all.
379
        $this->assertNull($actionevent);
379
        $this->assertNull($actionevent);
Línea 380... Línea 380...
380
    }
380
    }
381
 
381
 
Línea 382... Línea 382...
382
    public function test_choice_core_calendar_provide_event_action_open() {
382
    public function test_choice_core_calendar_provide_event_action_open(): void {
Línea 383... Línea 383...
383
        $this->resetAfterTest();
383
        $this->resetAfterTest();
Línea 406... Línea 406...
406
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
406
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
407
        $this->assertEquals(1, $actionevent->get_item_count());
407
        $this->assertEquals(1, $actionevent->get_item_count());
408
        $this->assertTrue($actionevent->is_actionable());
408
        $this->assertTrue($actionevent->is_actionable());
409
    }
409
    }
Línea 410... Línea 410...
410
 
410
 
411
    public function test_choice_core_calendar_provide_event_action_open_for_user() {
411
    public function test_choice_core_calendar_provide_event_action_open_for_user(): void {
Línea 412... Línea 412...
412
        $this->resetAfterTest();
412
        $this->resetAfterTest();
Línea 413... Línea 413...
413
 
413
 
Línea 442... Línea 442...
442
 
442
 
443
    /**
443
    /**
444
     * An event should not have an action if the user has already submitted a response
444
     * An event should not have an action if the user has already submitted a response
445
     * to the choice activity.
445
     * to the choice activity.
446
     */
446
     */
447
    public function test_choice_core_calendar_provide_event_action_already_submitted() {
447
    public function test_choice_core_calendar_provide_event_action_already_submitted(): void {
Línea 448... Línea 448...
448
        $this->resetAfterTest();
448
        $this->resetAfterTest();
Línea 449... Línea 449...
449
 
449
 
Línea 483... Línea 483...
483
 
483
 
484
    /**
484
    /**
485
     * An event should not have an action if the user has already submitted a response
485
     * An event should not have an action if the user has already submitted a response
486
     * to the choice activity.
486
     * to the choice activity.
487
     */
487
     */
488
    public function test_choice_core_calendar_provide_event_action_already_submitted_for_user() {
488
    public function test_choice_core_calendar_provide_event_action_already_submitted_for_user(): void {
Línea 489... Línea 489...
489
        $this->resetAfterTest();
489
        $this->resetAfterTest();
Línea 490... Línea 490...
490
 
490
 
Línea 518... Línea 518...
518
        // Confirm no action was returned if the user has already submitted the
518
        // Confirm no action was returned if the user has already submitted the
519
        // choice activity.
519
        // choice activity.
520
        $this->assertNull($action);
520
        $this->assertNull($action);
521
    }
521
    }
Línea 522... Línea 522...
522
 
522
 
523
    public function test_choice_core_calendar_provide_event_action_closed() {
523
    public function test_choice_core_calendar_provide_event_action_closed(): void {
Línea 524... Línea 524...
524
        $this->resetAfterTest();
524
        $this->resetAfterTest();
Línea 525... Línea 525...
525
 
525
 
Línea 544... Línea 544...
544
 
544
 
545
        // Confirm not action was provided for a closed activity.
545
        // Confirm not action was provided for a closed activity.
546
        $this->assertNull($action);
546
        $this->assertNull($action);
Línea 547... Línea 547...
547
    }
547
    }
548
 
548
 
Línea 549... Línea 549...
549
    public function test_choice_core_calendar_provide_event_action_closed_for_user() {
549
    public function test_choice_core_calendar_provide_event_action_closed_for_user(): void {
Línea 550... Línea 550...
550
        $this->resetAfterTest();
550
        $this->resetAfterTest();
Línea 573... Línea 573...
573
 
573
 
574
        // Confirm not action was provided for a closed activity.
574
        // Confirm not action was provided for a closed activity.
575
        $this->assertNull($action);
575
        $this->assertNull($action);
Línea 576... Línea 576...
576
    }
576
    }
577
 
577
 
Línea 578... Línea 578...
578
    public function test_choice_core_calendar_provide_event_action_open_in_future() {
578
    public function test_choice_core_calendar_provide_event_action_open_in_future(): void {
Línea 579... Línea 579...
579
        $this->resetAfterTest();
579
        $this->resetAfterTest();
Línea 605... Línea 605...
605
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
605
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
606
        $this->assertEquals(1, $actionevent->get_item_count());
606
        $this->assertEquals(1, $actionevent->get_item_count());
607
        $this->assertFalse($actionevent->is_actionable());
607
        $this->assertFalse($actionevent->is_actionable());
608
    }
608
    }
Línea 609... Línea 609...
609
 
609
 
610
    public function test_choice_core_calendar_provide_event_action_open_in_future_for_user() {
610
    public function test_choice_core_calendar_provide_event_action_open_in_future_for_user(): void {
Línea 611... Línea 611...
611
        global $CFG;
611
        global $CFG;
Línea 612... Línea 612...
612
 
612
 
Línea 646... Línea 646...
646
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
646
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
647
        $this->assertEquals(1, $actionevent->get_item_count());
647
        $this->assertEquals(1, $actionevent->get_item_count());
648
        $this->assertFalse($actionevent->is_actionable());
648
        $this->assertFalse($actionevent->is_actionable());
649
    }
649
    }
Línea 650... Línea 650...
650
 
650
 
651
    public function test_choice_core_calendar_provide_event_action_no_time_specified() {
651
    public function test_choice_core_calendar_provide_event_action_no_time_specified(): void {
Línea 652... Línea 652...
652
        $this->resetAfterTest();
652
        $this->resetAfterTest();
Línea 653... Línea 653...
653
 
653
 
Línea 674... Línea 674...
674
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
674
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
675
        $this->assertEquals(1, $actionevent->get_item_count());
675
        $this->assertEquals(1, $actionevent->get_item_count());
676
        $this->assertTrue($actionevent->is_actionable());
676
        $this->assertTrue($actionevent->is_actionable());
677
    }
677
    }
Línea 678... Línea 678...
678
 
678
 
679
    public function test_choice_core_calendar_provide_event_action_no_time_specified_for_user() {
679
    public function test_choice_core_calendar_provide_event_action_no_time_specified_for_user(): void {
Línea 680... Línea 680...
680
        global $CFG;
680
        global $CFG;
Línea 681... Línea 681...
681
 
681
 
Línea 711... Línea 711...
711
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
711
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
712
        $this->assertEquals(1, $actionevent->get_item_count());
712
        $this->assertEquals(1, $actionevent->get_item_count());
713
        $this->assertTrue($actionevent->is_actionable());
713
        $this->assertTrue($actionevent->is_actionable());
714
    }
714
    }
Línea 715... Línea 715...
715
 
715
 
716
    public function test_choice_core_calendar_provide_event_action_already_completed() {
716
    public function test_choice_core_calendar_provide_event_action_already_completed(): void {
717
        $this->resetAfterTest();
717
        $this->resetAfterTest();
718
        set_config('enablecompletion', 1);
718
        set_config('enablecompletion', 1);
Línea 719... Línea 719...
719
        $this->setAdminUser();
719
        $this->setAdminUser();
Línea 742... Línea 742...
742
 
742
 
743
        // Ensure result was null.
743
        // Ensure result was null.
744
        $this->assertNull($actionevent);
744
        $this->assertNull($actionevent);
Línea 745... Línea 745...
745
    }
745
    }
746
 
746
 
747
    public function test_choice_core_calendar_provide_event_action_already_completed_for_user() {
747
    public function test_choice_core_calendar_provide_event_action_already_completed_for_user(): void {
748
        $this->resetAfterTest();
748
        $this->resetAfterTest();
Línea 749... Línea 749...
749
        set_config('enablecompletion', 1);
749
        set_config('enablecompletion', 1);
Línea 808... Línea 808...
808
    /**
808
    /**
809
     * Test the callback responsible for returning the completion rule descriptions.
809
     * Test the callback responsible for returning the completion rule descriptions.
810
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
810
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
811
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
811
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
812
     */
812
     */
813
    public function test_mod_choice_completion_get_active_rule_descriptions() {
813
    public function test_mod_choice_completion_get_active_rule_descriptions(): void {
814
        $this->resetAfterTest();
814
        $this->resetAfterTest();
815
        $this->setAdminUser();
815
        $this->setAdminUser();
Línea 816... Línea 816...
816
 
816
 
817
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
817
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
Línea 844... Línea 844...
844
    }
844
    }
Línea 845... Línea 845...
845
 
845
 
846
    /**
846
    /**
847
     * An unkown event type should not change the choice instance.
847
     * An unkown event type should not change the choice instance.
848
     */
848
     */
849
    public function test_mod_choice_core_calendar_event_timestart_updated_unknown_event() {
849
    public function test_mod_choice_core_calendar_event_timestart_updated_unknown_event(): void {
850
        global $CFG, $DB;
850
        global $CFG, $DB;
Línea 851... Línea 851...
851
        require_once($CFG->dirroot . "/calendar/lib.php");
851
        require_once($CFG->dirroot . "/calendar/lib.php");
852
 
852
 
Línea 887... Línea 887...
887
 
887
 
888
    /**
888
    /**
889
     * A CHOICE_EVENT_TYPE_OPEN event should update the timeopen property of
889
     * A CHOICE_EVENT_TYPE_OPEN event should update the timeopen property of
890
     * the choice activity.
890
     * the choice activity.
891
     */
891
     */
892
    public function test_mod_choice_core_calendar_event_timestart_updated_open_event() {
892
    public function test_mod_choice_core_calendar_event_timestart_updated_open_event(): void {
893
        global $CFG, $DB;
893
        global $CFG, $DB;
Línea 894... Línea 894...
894
        require_once($CFG->dirroot . "/calendar/lib.php");
894
        require_once($CFG->dirroot . "/calendar/lib.php");
895
 
895
 
Línea 948... Línea 948...
948
 
948
 
949
    /**
949
    /**
950
     * A CHOICE_EVENT_TYPE_CLOSE event should update the timeclose property of
950
     * A CHOICE_EVENT_TYPE_CLOSE event should update the timeclose property of
951
     * the choice activity.
951
     * the choice activity.
952
     */
952
     */
953
    public function test_mod_choice_core_calendar_event_timestart_updated_close_event() {
953
    public function test_mod_choice_core_calendar_event_timestart_updated_close_event(): void {
954
        global $CFG, $DB;
954
        global $CFG, $DB;
Línea 955... Línea 955...
955
        require_once($CFG->dirroot . "/calendar/lib.php");
955
        require_once($CFG->dirroot . "/calendar/lib.php");
956
 
956
 
Línea 1008... Línea 1008...
1008
    }
1008
    }
Línea 1009... Línea 1009...
1009
 
1009
 
1010
    /**
1010
    /**
1011
     * An unkown event type should not have any limits
1011
     * An unkown event type should not have any limits
1012
     */
1012
     */
1013
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_unknown_event() {
1013
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_unknown_event(): void {
1014
        global $CFG, $DB;
1014
        global $CFG, $DB;
Línea 1015... Línea 1015...
1015
        require_once($CFG->dirroot . "/calendar/lib.php");
1015
        require_once($CFG->dirroot . "/calendar/lib.php");
1016
 
1016
 
Línea 1046... Línea 1046...
1046
    }
1046
    }
Línea 1047... Línea 1047...
1047
 
1047
 
1048
    /**
1048
    /**
1049
     * The open event should be limited by the choice's timeclose property, if it's set.
1049
     * The open event should be limited by the choice's timeclose property, if it's set.
1050
     */
1050
     */
1051
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_open_event() {
1051
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_open_event(): void {
1052
        global $CFG, $DB;
1052
        global $CFG, $DB;
Línea 1053... Línea 1053...
1053
        require_once($CFG->dirroot . "/calendar/lib.php");
1053
        require_once($CFG->dirroot . "/calendar/lib.php");
1054
 
1054
 
Línea 1093... Línea 1093...
1093
    }
1093
    }
Línea 1094... Línea 1094...
1094
 
1094
 
1095
    /**
1095
    /**
1096
     * The close event should be limited by the choice's timeopen property, if it's set.
1096
     * The close event should be limited by the choice's timeopen property, if it's set.
1097
     */
1097
     */
1098
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_close_event() {
1098
    public function test_mod_choice_core_calendar_get_valid_event_timestart_range_close_event(): void {
1099
        global $CFG, $DB;
1099
        global $CFG, $DB;
Línea 1100... Línea 1100...
1100
        require_once($CFG->dirroot . "/calendar/lib.php");
1100
        require_once($CFG->dirroot . "/calendar/lib.php");
1101
 
1101
 
Línea 1143... Línea 1143...
1143
     * Test choice_user_submit_response for a choice with specific options.
1143
     * Test choice_user_submit_response for a choice with specific options.
1144
     * Options:
1144
     * Options:
1145
     * allowmultiple: false
1145
     * allowmultiple: false
1146
     * limitanswers: false
1146
     * limitanswers: false
1147
     */
1147
     */
1148
    public function test_choice_user_submit_response_no_multiple_no_limits() {
1148
    public function test_choice_user_submit_response_no_multiple_no_limits(): void {
1149
        global $DB;
1149
        global $DB;
1150
        $this->resetAfterTest(true);
1150
        $this->resetAfterTest(true);
Línea 1151... Línea 1151...
1151
 
1151
 
1152
        $generator = $this->getDataGenerator();
1152
        $generator = $this->getDataGenerator();
Línea 1191... Línea 1191...
1191
     * Test choice_user_submit_response for a choice with specific options.
1191
     * Test choice_user_submit_response for a choice with specific options.
1192
     * Options:
1192
     * Options:
1193
     * allowmultiple: true
1193
     * allowmultiple: true
1194
     * limitanswers: false
1194
     * limitanswers: false
1195
     */
1195
     */
1196
    public function test_choice_user_submit_response_multiples_no_limits() {
1196
    public function test_choice_user_submit_response_multiples_no_limits(): void {
1197
        global $DB;
1197
        global $DB;
1198
        $this->resetAfterTest(true);
1198
        $this->resetAfterTest(true);
Línea 1199... Línea 1199...
1199
 
1199
 
1200
        $generator = $this->getDataGenerator();
1200
        $generator = $this->getDataGenerator();
Línea 1242... Línea 1242...
1242
     * Test choice_user_submit_response for a choice with specific options.
1242
     * Test choice_user_submit_response for a choice with specific options.
1243
     * Options:
1243
     * Options:
1244
     * allowmultiple: false
1244
     * allowmultiple: false
1245
     * limitanswers: true
1245
     * limitanswers: true
1246
     */
1246
     */
1247
    public function test_choice_user_submit_response_no_multiples_limits() {
1247
    public function test_choice_user_submit_response_no_multiples_limits(): void {
1248
        global $DB;
1248
        global $DB;
1249
        $this->resetAfterTest(true);
1249
        $this->resetAfterTest(true);
Línea 1250... Línea 1250...
1250
 
1250
 
1251
        $generator = $this->getDataGenerator();
1251
        $generator = $this->getDataGenerator();
Línea 1288... Línea 1288...
1288
     * Test choice_user_submit_response for a choice with specific options.
1288
     * Test choice_user_submit_response for a choice with specific options.
1289
     * Options:
1289
     * Options:
1290
     * allowmultiple: true
1290
     * allowmultiple: true
1291
     * limitanswers: true
1291
     * limitanswers: true
1292
     */
1292
     */
1293
    public function test_choice_user_submit_response_multiples_limits() {
1293
    public function test_choice_user_submit_response_multiples_limits(): void {
1294
        global $DB;
1294
        global $DB;
1295
        $this->resetAfterTest(true);
1295
        $this->resetAfterTest(true);
Línea 1296... Línea 1296...
1296
 
1296
 
1297
        $generator = $this->getDataGenerator();
1297
        $generator = $this->getDataGenerator();
Línea 1334... Línea 1334...
1334
    }
1334
    }
Línea 1335... Línea 1335...
1335
 
1335
 
1336
    /**
1336
    /**
1337
     * A user who does not have capabilities to add events to the calendar should be able to create an choice.
1337
     * A user who does not have capabilities to add events to the calendar should be able to create an choice.
1338
     */
1338
     */
1339
    public function test_creation_with_no_calendar_capabilities() {
1339
    public function test_creation_with_no_calendar_capabilities(): void {
1340
        $this->resetAfterTest();
1340
        $this->resetAfterTest();
1341
        $course = self::getDataGenerator()->create_course();
1341
        $course = self::getDataGenerator()->create_course();
1342
        $context = \context_course::instance($course->id);
1342
        $context = \context_course::instance($course->id);
1343
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
1343
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');