Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 76... Línea 76...
76
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
76
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
77
        $this->expectException(\coding_exception::class);
77
        $this->expectException(\coding_exception::class);
78
        $co->proceed();
78
        $co->proceed();
79
    }
79
    }
Línea 80... Línea 80...
80
 
80
 
81
    public function test_proceed_when_prepare_failed() {
81
    public function test_proceed_when_prepare_failed(): void {
82
        $this->initialise_test();
82
        $this->initialise_test();
83
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
83
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
84
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
84
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
85
        $data = array();
85
        $data = array();
86
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
86
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
87
        $this->assertFalse($co->prepare());
87
        $this->assertFalse($co->prepare());
88
        $this->expectException(\moodle_exception::class);
88
        $this->expectException(\moodle_exception::class);
89
        $co->proceed();
89
        $co->proceed();
Línea 90... Línea 90...
90
    }
90
    }
91
 
91
 
92
    public function test_proceed_when_already_started() {
92
    public function test_proceed_when_already_started(): void {
93
        $this->initialise_test();
93
        $this->initialise_test();
94
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
94
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
95
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
95
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
Línea 99... Línea 99...
99
        $co->proceed();
99
        $co->proceed();
100
        $this->expectException('coding_exception');
100
        $this->expectException('coding_exception');
101
        $co->proceed();
101
        $co->proceed();
102
    }
102
    }
Línea 103... Línea 103...
103
 
103
 
104
    public function test_invalid_shortname() {
104
    public function test_invalid_shortname(): void {
105
        $this->initialise_test();
105
        $this->initialise_test();
106
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
106
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
107
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
107
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
108
        $data = array('shortname' => '<invalid>', 'fullname' => 'New course', 'summary' => 'New', 'category' => 1);
108
        $data = array('shortname' => '<invalid>', 'fullname' => 'New course', 'summary' => 'New', 'category' => 1);
109
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
109
        $co = new tool_uploadcourse_course($mode, $updatemode, $data);
110
        $this->assertFalse($co->prepare());
110
        $this->assertFalse($co->prepare());
111
        $this->assertArrayHasKey('invalidshortname', $co->get_errors());
111
        $this->assertArrayHasKey('invalidshortname', $co->get_errors());
Línea 112... Línea 112...
112
    }
112
    }
113
 
113
 
Línea 114... Línea 114...
114
    public function test_invalid_shortname_too_long() {
114
    public function test_invalid_shortname_too_long(): void {
115
        $this->resetAfterTest();
115
        $this->resetAfterTest();
Línea 125... Línea 125...
125
 
125
 
126
        $this->assertFalse($upload->prepare());
126
        $this->assertFalse($upload->prepare());
127
        $this->assertArrayHasKey('invalidshortnametoolong', $upload->get_errors());
127
        $this->assertArrayHasKey('invalidshortnametoolong', $upload->get_errors());
Línea 128... Línea 128...
128
    }
128
    }
129
 
129
 
Línea 130... Línea 130...
130
    public function test_invalid_fullname_too_long() {
130
    public function test_invalid_fullname_too_long(): void {
131
        $this->initialise_test();
131
        $this->initialise_test();
Línea 140... Línea 140...
140
 
140
 
141
        $this->assertFalse($upload->prepare());
141
        $this->assertFalse($upload->prepare());
142
        $this->assertArrayHasKey('invalidfullnametoolong', $upload->get_errors());
142
        $this->assertArrayHasKey('invalidfullnametoolong', $upload->get_errors());
Línea 143... Línea 143...
143
    }
143
    }
144
 
144
 
145
    public function test_invalid_visibility() {
145
    public function test_invalid_visibility(): void {
146
        $this->initialise_test();
146
        $this->initialise_test();
147
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
147
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
148
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
148
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
Línea 271... Línea 271...
271
                $this->assertArrayHasKey('courseuploadnotallowed', $co->get_errors());
271
                $this->assertArrayHasKey('courseuploadnotallowed', $co->get_errors());
272
            }
272
            }
273
        }
273
        }
274
    }
274
    }
Línea 275... Línea 275...
275
 
275
 
276
    public function test_create() {
276
    public function test_create(): void {
277
        global $DB;
277
        global $DB;
Línea 278... Línea 278...
278
        $this->initialise_test();
278
        $this->initialise_test();
279
 
279
 
Línea 320... Línea 320...
320
        $co->proceed();
320
        $co->proceed();
321
        $course = $DB->get_record('course', array('shortname' => 'c3'), '*', MUST_EXIST);
321
        $course = $DB->get_record('course', array('shortname' => 'c3'), '*', MUST_EXIST);
322
        $this->assertEquals(1, course_get_format($course)->get_course()->coursedisplay);
322
        $this->assertEquals(1, course_get_format($course)->get_course()->coursedisplay);
323
    }
323
    }
Línea 324... Línea 324...
324
 
324
 
325
    public function test_create_with_sections() {
325
    public function test_create_with_sections(): void {
326
        global $DB;
326
        global $DB;
327
        $this->initialise_test();
327
        $this->initialise_test();
328
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
328
        $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
Línea 350... Línea 350...
350
        $this->assertNotEmpty($courseid);
350
        $this->assertNotEmpty($courseid);
351
        $this->assertEquals(15 + 1,
351
        $this->assertEquals(15 + 1,
352
            $DB->count_records('course_sections', ['course' => $courseid]));
352
            $DB->count_records('course_sections', ['course' => $courseid]));
353
    }
353
    }
Línea 354... Línea 354...
354
 
354
 
355
    public function test_delete() {
355
    public function test_delete(): void {
356
        global $DB;
356
        global $DB;
Línea 357... Línea 357...
357
        $this->initialise_test();
357
        $this->initialise_test();
358
 
358
 
Línea 395... Línea 395...
395
        $co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
395
        $co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
396
        $this->assertFalse($co->prepare());
396
        $this->assertFalse($co->prepare());
397
        $this->assertArrayHasKey('cannotdeletecoursenotexist', $co->get_errors());
397
        $this->assertArrayHasKey('cannotdeletecoursenotexist', $co->get_errors());
398
    }
398
    }
Línea 399... Línea 399...
399
 
399
 
400
    public function test_update() {
400
    public function test_update(): void {
401
        global $DB;
401
        global $DB;
Línea 402... Línea 402...
402
        $this->initialise_test();
402
        $this->initialise_test();
Línea 472... Línea 472...
472
        $co->proceed();
472
        $co->proceed();
473
        $course = $DB->get_record('course', array('shortname' => 'c1'), '*', MUST_EXIST);
473
        $course = $DB->get_record('course', array('shortname' => 'c1'), '*', MUST_EXIST);
474
        $this->assertEquals(1, course_get_format($course)->get_course()->coursedisplay);
474
        $this->assertEquals(1, course_get_format($course)->get_course()->coursedisplay);
475
    }
475
    }
Línea 476... Línea 476...
476
 
476
 
477
    public function test_data_saved() {
477
    public function test_data_saved(): void {
Línea 478... Línea 478...
478
        global $DB;
478
        global $DB;
Línea 479... Línea 479...
479
 
479
 
Línea 690... Línea 690...
690
        $this->assertNotEmpty($enroldata['self']);
690
        $this->assertNotEmpty($enroldata['self']);
691
        $this->assertEquals($data['enrolment_2_roleid'], $enroldata['self']->roleid);
691
        $this->assertEquals($data['enrolment_2_roleid'], $enroldata['self']->roleid);
692
        $this->assertEquals(ENROL_INSTANCE_ENABLED, $enroldata['self']->status);
692
        $this->assertEquals(ENROL_INSTANCE_ENABLED, $enroldata['self']->status);
693
    }
693
    }
Línea 694... Línea 694...
694
 
694
 
695
    public function test_default_data_saved() {
695
    public function test_default_data_saved(): void {
Línea 696... Línea 696...
696
        global $DB;
696
        global $DB;
Línea 697... Línea 697...
697
 
697
 
Línea 815... Línea 815...
815
        $this->assertEquals($defaultdata['groupmodeforce'], $course->groupmodeforce);
815
        $this->assertEquals($defaultdata['groupmodeforce'], $course->groupmodeforce);
816
        $this->assertEquals($defaultdata['enablecompletion'], $course->enablecompletion);
816
        $this->assertEquals($defaultdata['enablecompletion'], $course->enablecompletion);
817
        $this->assertEquals($defaultdata['showactivitydates'], $course->showactivitydates);
817
        $this->assertEquals($defaultdata['showactivitydates'], $course->showactivitydates);
818
    }
818
    }
Línea 819... Línea 819...
819
 
819
 
820
    public function test_rename() {
820
    public function test_rename(): void {
821
        global $DB;
821
        global $DB;
Línea 822... Línea 822...
822
        $this->initialise_test();
822
        $this->initialise_test();
823
 
823
 
Línea 910... Línea 910...
910
        $co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
910
        $co = new tool_uploadcourse_course($mode, $updatemode, $data, array(), $importoptions);
911
        $this->assertFalse($co->prepare());
911
        $this->assertFalse($co->prepare());
912
        $this->assertArrayHasKey('cannotrenameshortnamealreadyinuse', $co->get_errors());
912
        $this->assertArrayHasKey('cannotrenameshortnamealreadyinuse', $co->get_errors());
913
    }
913
    }
Línea 914... Línea 914...
914
 
914
 
915
    public function test_restore_course() {
915
    public function test_restore_course(): void {
916
        global $DB;
916
        global $DB;
917
        $this->initialise_test();
917
        $this->initialise_test();
Línea 918... Línea 918...
918
        $this->setAdminUser();
918
        $this->setAdminUser();
Línea 954... Línea 954...
954
            }
954
            }
955
        }
955
        }
956
        $this->assertTrue($found);
956
        $this->assertTrue($found);
957
    }
957
    }
Línea 958... Línea 958...
958
 
958
 
959
    public function test_restore_file() {
959
    public function test_restore_file(): void {
960
        global $DB;
960
        global $DB;
961
        $this->initialise_test();
961
        $this->initialise_test();
Línea 962... Línea 962...
962
        $this->setAdminUser();
962
        $this->setAdminUser();
Línea 1006... Línea 1006...
1006
    }
1006
    }
Línea 1007... Línea 1007...
1007
 
1007
 
1008
    /**
1008
    /**
1009
     * Test that specifying course template respects default restore settings
1009
     * Test that specifying course template respects default restore settings
1010
     */
1010
     */
1011
    public function test_restore_file_settings() {
1011
    public function test_restore_file_settings(): void {
1012
        global $DB;
1012
        global $DB;
1013
        $this->initialise_test();
1013
        $this->initialise_test();
Línea 1014... Línea 1014...
1014
        $this->setAdminUser();
1014
        $this->setAdminUser();
Línea 1030... Línea 1030...
1030
        // Make sure the glossary is not restored.
1030
        // Make sure the glossary is not restored.
1031
        $modinfo = get_fast_modinfo($course);
1031
        $modinfo = get_fast_modinfo($course);
1032
        $this->assertEmpty($modinfo->get_instances_of('glossary'));
1032
        $this->assertEmpty($modinfo->get_instances_of('glossary'));
1033
    }
1033
    }
Línea 1034... Línea 1034...
1034
 
1034
 
1035
    public function test_restore_invalid_file() {
1035
    public function test_restore_invalid_file(): void {
Línea 1036... Línea 1036...
1036
        $this->initialise_test();
1036
        $this->initialise_test();
1037
 
1037
 
1038
        // Restore from a non-existing file should not be allowed.
1038
        // Restore from a non-existing file should not be allowed.
Línea 1057... Línea 1057...
1057
        // Zip packer throws a debugging message, this assertion is only here to prevent
1057
        // Zip packer throws a debugging message, this assertion is only here to prevent
1058
        // the message from being displayed.
1058
        // the message from being displayed.
1059
        $this->assertDebuggingCalled();
1059
        $this->assertDebuggingCalled();
1060
    }
1060
    }
Línea 1061... Línea 1061...
1061
 
1061
 
1062
    public function test_restore_invalid_course() {
1062
    public function test_restore_invalid_course(): void {
Línea 1063... Línea 1063...
1063
        $this->initialise_test();
1063
        $this->initialise_test();
1064
 
1064
 
1065
        // Restore from an invalid file should not be allowed.
1065
        // Restore from an invalid file should not be allowed.
Línea 1073... Línea 1073...
1073
    }
1073
    }
Línea 1074... Línea 1074...
1074
 
1074
 
1075
    /**
1075
    /**
1076
     * Testing the reset on groups, group members and enrolments.
1076
     * Testing the reset on groups, group members and enrolments.
1077
     */
1077
     */
1078
    public function test_reset() {
1078
    public function test_reset(): void {
1079
        global $DB;
1079
        global $DB;
Línea 1080... Línea 1080...
1080
        $this->initialise_test();
1080
        $this->initialise_test();
1081
 
1081
 
Línea 1165... Línea 1165...
1165
        $this->assertTrue($co->prepare());
1165
        $this->assertTrue($co->prepare());
1166
        $co->proceed();
1166
        $co->proceed();
1167
        $this->assertFalse($DB->record_exists('groups', array('id' => $g1->id)));
1167
        $this->assertFalse($DB->record_exists('groups', array('id' => $g1->id)));
1168
    }
1168
    }
Línea 1169... Línea 1169...
1169
 
1169
 
1170
    public function test_create_bad_category() {
1170
    public function test_create_bad_category(): void {
1171
        global $DB;
1171
        global $DB;
Línea 1172... Línea 1172...
1172
        $this->initialise_test();
1172
        $this->initialise_test();
1173
 
1173
 
Línea 1220... Línea 1220...
1220
        $this->assertEmpty($co->get_statuses());
1220
        $this->assertEmpty($co->get_statuses());
1221
        $co->proceed();
1221
        $co->proceed();
1222
        $this->assertEquals($c1->category, $DB->get_field('course', 'category', array('id' => $c1->id)));
1222
        $this->assertEquals($c1->category, $DB->get_field('course', 'category', array('id' => $c1->id)));
1223
    }
1223
    }
Línea 1224... Línea 1224...
1224
 
1224
 
1225
    public function test_enrolment_data() {
1225
    public function test_enrolment_data(): void {
Línea 1226... Línea 1226...
1226
        $this->initialise_test();
1226
        $this->initialise_test();
1227
 
1227
 
Línea 1372... Línea 1372...
1372
    }
1372
    }
Línea 1373... Línea 1373...
1373
 
1373
 
1374
    /**
1374
    /**
1375
     * Test upload processing of course custom fields
1375
     * Test upload processing of course custom fields
1376
     */
1376
     */
1377
    public function test_custom_fields_data() {
1377
    public function test_custom_fields_data(): void {
1378
        $this->resetAfterTest();
1378
        $this->resetAfterTest();
Línea 1379... Línea 1379...
1379
        $this->setAdminUser();
1379
        $this->setAdminUser();
Línea 1408... Línea 1408...
1408
    }
1408
    }
Línea 1409... Línea 1409...
1409
 
1409
 
1410
    /**
1410
    /**
1411
     * Test upload processing of course custom field that is required but empty
1411
     * Test upload processing of course custom field that is required but empty
1412
     */
1412
     */
1413
    public function test_custom_fields_data_required() {
1413
    public function test_custom_fields_data_required(): void {
1414
        $this->resetAfterTest();
1414
        $this->resetAfterTest();
Línea 1415... Línea 1415...
1415
        $this->setAdminUser();
1415
        $this->setAdminUser();
Línea 1446... Línea 1446...
1446
    }
1446
    }
Línea 1447... Línea 1447...
1447
 
1447
 
1448
    /**
1448
    /**
1449
     * Test upload processing of course custom field with an invalid select option
1449
     * Test upload processing of course custom field with an invalid select option
1450
     */
1450
     */
1451
    public function test_custom_fields_data_invalid_select_option() {
1451
    public function test_custom_fields_data_invalid_select_option(): void {
1452
        $this->resetAfterTest();
1452
        $this->resetAfterTest();
Línea 1453... Línea 1453...
1453
        $this->setAdminUser();
1453
        $this->setAdminUser();
Línea 1476... Línea 1476...
1476
    }
1476
    }
Línea 1477... Línea 1477...
1477
 
1477
 
1478
    /**
1478
    /**
1479
     * Test upload processing of course custom field with an out of range date
1479
     * Test upload processing of course custom field with an out of range date
1480
     */
1480
     */
1481
    public function test_custom_fields_data_invalid_date() {
1481
    public function test_custom_fields_data_invalid_date(): void {
1482
        $this->resetAfterTest();
1482
        $this->resetAfterTest();
Línea 1483... Línea 1483...
1483
        $this->setAdminUser();
1483
        $this->setAdminUser();
Línea 1499... Línea 1499...
1499
        $uploader = new tool_uploadcourse_course($mode, $updatemode, $dataupload);
1499
        $uploader = new tool_uploadcourse_course($mode, $updatemode, $dataupload);
1500
        $this->assertFalse($uploader->prepare());
1500
        $this->assertFalse($uploader->prepare());
1501
        $this->assertArrayHasKey('customfieldinvalid', $uploader->get_errors());
1501
        $this->assertArrayHasKey('customfieldinvalid', $uploader->get_errors());
1502
    }
1502
    }
Línea 1503... Línea 1503...
1503
 
1503
 
1504
    public function test_idnumber_problems() {
1504
    public function test_idnumber_problems(): void {
Línea 1505... Línea 1505...
1505
        $this->initialise_test();
1505
        $this->initialise_test();
1506
 
1506
 
Línea 1550... Línea 1550...
1550
        $data = $co->get_data();
1550
        $data = $co->get_data();
1551
        $this->assertEquals('sntaken_2', $data['shortname']);
1551
        $this->assertEquals('sntaken_2', $data['shortname']);
1552
        $this->assertEquals('nottaken', $data['idnumber']);
1552
        $this->assertEquals('nottaken', $data['idnumber']);
1553
    }
1553
    }
Línea 1554... Línea 1554...
1554
 
1554
 
1555
    public function test_generate_shortname() {
1555
    public function test_generate_shortname(): void {
Línea 1556... Línea 1556...
1556
        $this->initialise_test();
1556
        $this->initialise_test();
Línea 1557... Línea 1557...
1557
 
1557
 
Línea 1602... Línea 1602...
1602
        $this->assertTrue($co->prepare());
1602
        $this->assertTrue($co->prepare());
1603
        $this->assertArrayHasKey('courseshortnamegenerated', $co->get_statuses());
1603
        $this->assertArrayHasKey('courseshortnamegenerated', $co->get_statuses());
1604
        $this->assertArrayHasKey('courseshortnameincremented', $co->get_statuses());
1604
        $this->assertArrayHasKey('courseshortnameincremented', $co->get_statuses());
1605
    }
1605
    }
Línea 1606... Línea 1606...
1606
 
1606
 
1607
    public function test_mess_with_frontpage() {
1607
    public function test_mess_with_frontpage(): void {
1608
        global $SITE;
1608
        global $SITE;
Línea 1609... Línea 1609...
1609
        $this->initialise_test();
1609
        $this->initialise_test();
1610
 
1610
 
Línea 1649... Línea 1649...
1649
    /**
1649
    /**
1650
     * Test when role doesn't exist.
1650
     * Test when role doesn't exist.
1651
     *
1651
     *
1652
     * @covers \tool_uploadcourse_course::prepare
1652
     * @covers \tool_uploadcourse_course::prepare
1653
     */
1653
     */
1654
    public function test_role_not_exist() {
1654
    public function test_role_not_exist(): void {
1655
        $this->resetAfterTest();
1655
        $this->resetAfterTest();
1656
        $this->setAdminUser();
1656
        $this->setAdminUser();
Línea 1657... Línea 1657...
1657
 
1657
 
1658
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
1658
        $mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
Línea 1673... Línea 1673...
1673
    /**
1673
    /**
1674
     * Test when role not allowed in course context.
1674
     * Test when role not allowed in course context.
1675
     *
1675
     *
1676
     * @covers \tool_uploadcourse_course::proceed
1676
     * @covers \tool_uploadcourse_course::proceed
1677
     */
1677
     */
1678
    public function test_role_not_allowed() {
1678
    public function test_role_not_allowed(): void {
1679
        $this->resetAfterTest();
1679
        $this->resetAfterTest();
1680
        $this->setAdminUser();
1680
        $this->setAdminUser();
Línea 1681... Línea 1681...
1681
 
1681
 
1682
        $roleid = create_role('New student role', 'student2', 'New student description', 'student');
1682
        $roleid = create_role('New student role', 'student2', 'New student description', 'student');
Línea 1700... Línea 1700...
1700
    /**
1700
    /**
1701
     * Test when role is allowed.
1701
     * Test when role is allowed.
1702
     *
1702
     *
1703
     * @covers \tool_uploadcourse_course::proceed
1703
     * @covers \tool_uploadcourse_course::proceed
1704
     */
1704
     */
1705
    public function test_role_allowed() {
1705
    public function test_role_allowed(): void {
1706
        global $DB;
1706
        global $DB;
Línea 1707... Línea 1707...
1707
 
1707
 
1708
        $this->resetAfterTest();
1708
        $this->resetAfterTest();