Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 39... Línea 39...
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
39
 * @license    http://www.gnu.org/copyleft/gpl.html GNU Public License
40
 */
40
 */
41
class lib_test extends \advanced_testcase {
41
class lib_test extends \advanced_testcase {
42
    use \quiz_question_helper_test_trait;
42
    use \quiz_question_helper_test_trait;
Línea 43... Línea 43...
43
 
43
 
44
    public function test_quiz_has_grades() {
44
    public function test_quiz_has_grades(): void {
45
        $quiz = new \stdClass();
45
        $quiz = new \stdClass();
46
        $quiz->grade = '100.0000';
46
        $quiz->grade = '100.0000';
47
        $quiz->sumgrades = '100.0000';
47
        $quiz->sumgrades = '100.0000';
48
        $this->assertTrue(quiz_has_grades($quiz));
48
        $this->assertTrue(quiz_has_grades($quiz));
Línea 52... Línea 52...
52
        $this->assertFalse(quiz_has_grades($quiz));
52
        $this->assertFalse(quiz_has_grades($quiz));
53
        $quiz->sumgrades = '100.0000';
53
        $quiz->sumgrades = '100.0000';
54
        $this->assertFalse(quiz_has_grades($quiz));
54
        $this->assertFalse(quiz_has_grades($quiz));
55
    }
55
    }
Línea 56... Línea 56...
56
 
56
 
57
    public function test_quiz_format_grade() {
57
    public function test_quiz_format_grade(): void {
58
        $quiz = new \stdClass();
58
        $quiz = new \stdClass();
59
        $quiz->decimalpoints = 2;
59
        $quiz->decimalpoints = 2;
60
        $this->assertEquals(quiz_format_grade($quiz, 0.12345678), format_float(0.12, 2));
60
        $this->assertEquals(quiz_format_grade($quiz, 0.12345678), format_float(0.12, 2));
61
        $this->assertEquals(quiz_format_grade($quiz, 0), format_float(0, 2));
61
        $this->assertEquals(quiz_format_grade($quiz, 0), format_float(0, 2));
62
        $this->assertEquals(quiz_format_grade($quiz, 1.000000000000), format_float(1, 2));
62
        $this->assertEquals(quiz_format_grade($quiz, 1.000000000000), format_float(1, 2));
63
        $quiz->decimalpoints = 0;
63
        $quiz->decimalpoints = 0;
64
        $this->assertEquals(quiz_format_grade($quiz, 0.12345678), '0');
64
        $this->assertEquals(quiz_format_grade($quiz, 0.12345678), '0');
Línea 65... Línea 65...
65
    }
65
    }
66
 
66
 
67
    public function test_quiz_get_grade_format() {
67
    public function test_quiz_get_grade_format(): void {
68
        $quiz = new \stdClass();
68
        $quiz = new \stdClass();
69
        $quiz->decimalpoints = 2;
69
        $quiz->decimalpoints = 2;
70
        $this->assertEquals(quiz_get_grade_format($quiz), 2);
70
        $this->assertEquals(quiz_get_grade_format($quiz), 2);
Línea 76... Línea 76...
76
        $this->assertEquals(quiz_get_grade_format($quiz), 3);
76
        $this->assertEquals(quiz_get_grade_format($quiz), 3);
77
        $quiz->questiondecimalpoints = 4;
77
        $quiz->questiondecimalpoints = 4;
78
        $this->assertEquals(quiz_get_grade_format($quiz), 4);
78
        $this->assertEquals(quiz_get_grade_format($quiz), 4);
79
    }
79
    }
Línea 80... Línea 80...
80
 
80
 
81
    public function test_quiz_format_question_grade() {
81
    public function test_quiz_format_question_grade(): void {
82
        $quiz = new \stdClass();
82
        $quiz = new \stdClass();
83
        $quiz->decimalpoints = 2;
83
        $quiz->decimalpoints = 2;
84
        $quiz->questiondecimalpoints = 2;
84
        $quiz->questiondecimalpoints = 2;
85
        $this->assertEquals(quiz_format_question_grade($quiz, 0.12345678), format_float(0.12, 2));
85
        $this->assertEquals(quiz_format_question_grade($quiz, 0.12345678), format_float(0.12, 2));
Línea 97... Línea 97...
97
    }
97
    }
Línea 98... Línea 98...
98
 
98
 
99
    /**
99
    /**
100
     * Test deleting a quiz instance.
100
     * Test deleting a quiz instance.
101
     */
101
     */
102
    public function test_quiz_delete_instance() {
102
    public function test_quiz_delete_instance(): void {
103
        global $SITE, $DB;
103
        global $SITE, $DB;
104
        $this->resetAfterTest(true);
104
        $this->resetAfterTest(true);
Línea 105... Línea 105...
105
        $this->setAdminUser();
105
        $this->setAdminUser();
Línea 137... Línea 137...
137
        // Check that any question references linked to this quiz are gone.
137
        // Check that any question references linked to this quiz are gone.
138
        $this->assertEquals(0, $DB->count_records('question_references', ['usingcontextid' => $context->id]));
138
        $this->assertEquals(0, $DB->count_records('question_references', ['usingcontextid' => $context->id]));
139
        $this->assertEquals(0, $DB->count_records('question_set_references', ['usingcontextid' => $context->id]));
139
        $this->assertEquals(0, $DB->count_records('question_set_references', ['usingcontextid' => $context->id]));
140
    }
140
    }
Línea 141... Línea 141...
141
 
141
 
142
    public function test_quiz_get_user_attempts() {
142
    public function test_quiz_get_user_attempts(): void {
143
        global $DB;
143
        global $DB;
Línea 144... Línea 144...
144
        $this->resetAfterTest();
144
        $this->resetAfterTest();
145
 
145
 
Línea 361... Línea 361...
361
    }
361
    }
Línea 362... Línea 362...
362
 
362
 
363
    /**
363
    /**
364
     * Test for quiz_get_group_override_priorities().
364
     * Test for quiz_get_group_override_priorities().
365
     */
365
     */
366
    public function test_quiz_get_group_override_priorities() {
366
    public function test_quiz_get_group_override_priorities(): void {
367
        global $DB;
367
        global $DB;
Línea 368... Línea 368...
368
        $this->resetAfterTest();
368
        $this->resetAfterTest();
369
 
369
 
Línea 407... Línea 407...
407
        // Override 1's time close has higher priority since it is later than override 2's.
407
        // Override 1's time close has higher priority since it is later than override 2's.
408
        $this->assertEquals(1, $closepriorities[$override1->timeclose]);
408
        $this->assertEquals(1, $closepriorities[$override1->timeclose]);
409
        $this->assertEquals(2, $closepriorities[$override2->timeclose]);
409
        $this->assertEquals(2, $closepriorities[$override2->timeclose]);
410
    }
410
    }
Línea 411... Línea 411...
411
 
411
 
412
    public function test_quiz_core_calendar_provide_event_action_open() {
412
    public function test_quiz_core_calendar_provide_event_action_open(): void {
Línea 413... Línea 413...
413
        $this->resetAfterTest();
413
        $this->resetAfterTest();
Línea 414... Línea 414...
414
 
414
 
Línea 438... Línea 438...
438
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
438
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
439
        $this->assertEquals(1, $actionevent->get_item_count());
439
        $this->assertEquals(1, $actionevent->get_item_count());
440
        $this->assertTrue($actionevent->is_actionable());
440
        $this->assertTrue($actionevent->is_actionable());
441
    }
441
    }
Línea 442... Línea 442...
442
 
442
 
443
    public function test_quiz_core_calendar_provide_event_action_open_for_user() {
443
    public function test_quiz_core_calendar_provide_event_action_open_for_user(): void {
Línea 444... Línea 444...
444
        $this->resetAfterTest();
444
        $this->resetAfterTest();
Línea 445... Línea 445...
445
 
445
 
Línea 468... Línea 468...
468
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
468
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
469
        $this->assertEquals(1, $actionevent->get_item_count());
469
        $this->assertEquals(1, $actionevent->get_item_count());
470
        $this->assertTrue($actionevent->is_actionable());
470
        $this->assertTrue($actionevent->is_actionable());
471
    }
471
    }
Línea 472... Línea 472...
472
 
472
 
473
    public function test_quiz_core_calendar_provide_event_action_closed() {
473
    public function test_quiz_core_calendar_provide_event_action_closed(): void {
Línea 474... Línea 474...
474
        $this->resetAfterTest();
474
        $this->resetAfterTest();
Línea 475... Línea 475...
475
 
475
 
Línea 490... Línea 490...
490
 
490
 
491
        // Confirm the result was null.
491
        // Confirm the result was null.
492
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
492
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
Línea 493... Línea 493...
493
    }
493
    }
494
 
494
 
Línea 495... Línea 495...
495
    public function test_quiz_core_calendar_provide_event_action_closed_for_user() {
495
    public function test_quiz_core_calendar_provide_event_action_closed_for_user(): void {
Línea 496... Línea 496...
496
        $this->resetAfterTest();
496
        $this->resetAfterTest();
Línea 515... Línea 515...
515
 
515
 
516
        // Confirm the result was null.
516
        // Confirm the result was null.
517
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
517
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
Línea 518... Línea 518...
518
    }
518
    }
519
 
519
 
Línea 520... Línea 520...
520
    public function test_quiz_core_calendar_provide_event_action_open_in_future() {
520
    public function test_quiz_core_calendar_provide_event_action_open_in_future(): void {
Línea 521... Línea 521...
521
        $this->resetAfterTest();
521
        $this->resetAfterTest();
Línea 546... Línea 546...
546
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
546
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
547
        $this->assertEquals(1, $actionevent->get_item_count());
547
        $this->assertEquals(1, $actionevent->get_item_count());
548
        $this->assertFalse($actionevent->is_actionable());
548
        $this->assertFalse($actionevent->is_actionable());
549
    }
549
    }
Línea 550... Línea 550...
550
 
550
 
551
    public function test_quiz_core_calendar_provide_event_action_open_in_future_for_user() {
551
    public function test_quiz_core_calendar_provide_event_action_open_in_future_for_user(): void {
Línea 552... Línea 552...
552
        $this->resetAfterTest();
552
        $this->resetAfterTest();
Línea 553... Línea 553...
553
 
553
 
Línea 576... Línea 576...
576
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
576
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
577
        $this->assertEquals(1, $actionevent->get_item_count());
577
        $this->assertEquals(1, $actionevent->get_item_count());
578
        $this->assertFalse($actionevent->is_actionable());
578
        $this->assertFalse($actionevent->is_actionable());
579
    }
579
    }
Línea 580... Línea 580...
580
 
580
 
581
    public function test_quiz_core_calendar_provide_event_action_no_capability() {
581
    public function test_quiz_core_calendar_provide_event_action_no_capability(): void {
Línea 582... Línea 582...
582
        global $DB;
582
        global $DB;
583
 
583
 
Línea 613... Línea 613...
613
 
613
 
614
        // Confirm null is returned.
614
        // Confirm null is returned.
615
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
615
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
Línea 616... Línea 616...
616
    }
616
    }
617
 
617
 
Línea 618... Línea 618...
618
    public function test_quiz_core_calendar_provide_event_action_no_capability_for_user() {
618
    public function test_quiz_core_calendar_provide_event_action_no_capability_for_user(): void {
619
        global $DB;
619
        global $DB;
Línea 647... Línea 647...
647
 
647
 
648
        // Confirm null is returned.
648
        // Confirm null is returned.
649
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
649
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
Línea 650... Línea 650...
650
    }
650
    }
651
 
651
 
Línea 652... Línea 652...
652
    public function test_quiz_core_calendar_provide_event_action_already_finished() {
652
    public function test_quiz_core_calendar_provide_event_action_already_finished(): void {
Línea 653... Línea 653...
653
        global $DB;
653
        global $DB;
Línea 702... Línea 702...
702
 
702
 
703
        // Confirm null is returned.
703
        // Confirm null is returned.
704
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
704
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory));
Línea 705... Línea 705...
705
    }
705
    }
706
 
706
 
Línea 707... Línea 707...
707
    public function test_quiz_core_calendar_provide_event_action_already_finished_for_user() {
707
    public function test_quiz_core_calendar_provide_event_action_already_finished_for_user(): void {
Línea 708... Línea 708...
708
        global $DB;
708
        global $DB;
Línea 754... Línea 754...
754
 
754
 
755
        // Confirm null is returned.
755
        // Confirm null is returned.
756
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
756
        $this->assertNull(mod_quiz_core_calendar_provide_event_action($event, $factory, $student->id));
Línea 757... Línea 757...
757
    }
757
    }
758
 
758
 
759
    public function test_quiz_core_calendar_provide_event_action_already_completed() {
759
    public function test_quiz_core_calendar_provide_event_action_already_completed(): void {
760
        $this->resetAfterTest();
760
        $this->resetAfterTest();
Línea 761... Línea 761...
761
        set_config('enablecompletion', 1);
761
        set_config('enablecompletion', 1);
Línea 785... Línea 785...
785
 
785
 
786
        // Ensure result was null.
786
        // Ensure result was null.
787
        $this->assertNull($actionevent);
787
        $this->assertNull($actionevent);
Línea 788... Línea 788...
788
    }
788
    }
789
 
789
 
790
    public function test_quiz_core_calendar_provide_event_action_already_completed_for_user() {
790
    public function test_quiz_core_calendar_provide_event_action_already_completed_for_user(): void {
791
        $this->resetAfterTest();
791
        $this->resetAfterTest();
Línea 792... Línea 792...
792
        set_config('enablecompletion', 1);
792
        set_config('enablecompletion', 1);
Línea 845... Línea 845...
845
    /**
845
    /**
846
     * Test the callback responsible for returning the completion rule descriptions.
846
     * Test the callback responsible for returning the completion rule descriptions.
847
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
847
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
848
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
848
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
849
     */
849
     */
850
    public function test_mod_quiz_completion_get_active_rule_descriptions() {
850
    public function test_mod_quiz_completion_get_active_rule_descriptions(): void {
851
        $this->resetAfterTest();
851
        $this->resetAfterTest();
852
        $this->setAdminUser();
852
        $this->setAdminUser();
Línea 853... Línea 853...
853
 
853
 
854
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
854
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
Línea 887... Línea 887...
887
    }
887
    }
Línea 888... Línea 888...
888
 
888
 
889
    /**
889
    /**
890
     * A user who does not have capabilities to add events to the calendar should be able to create a quiz.
890
     * A user who does not have capabilities to add events to the calendar should be able to create a quiz.
891
     */
891
     */
892
    public function test_creation_with_no_calendar_capabilities() {
892
    public function test_creation_with_no_calendar_capabilities(): void {
893
        $this->resetAfterTest();
893
        $this->resetAfterTest();
894
        $course = self::getDataGenerator()->create_course();
894
        $course = self::getDataGenerator()->create_course();
895
        $context = \context_course::instance($course->id);
895
        $context = \context_course::instance($course->id);
896
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');
896
        $user = self::getDataGenerator()->create_and_enrol($course, 'editingteacher');