Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 67... Línea 67...
67
        }
67
        }
68
        assign_capability($capability, $permission, $this->get_roleid($contextid), $contextid, true);
68
        assign_capability($capability, $permission, $this->get_roleid($contextid), $contextid, true);
69
        accesslib_clear_all_caches_for_unit_testing();
69
        accesslib_clear_all_caches_for_unit_testing();
70
    }
70
    }
Línea 71... Línea 71...
71
 
71
 
72
    public function test_create_coursecat() {
72
    public function test_create_coursecat(): void {
73
        // Create the category.
73
        // Create the category.
74
        $data = new \stdClass();
74
        $data = new \stdClass();
75
        $data->name = 'aaa';
75
        $data->name = 'aaa';
76
        $data->description = 'aaa';
76
        $data->description = 'aaa';
Línea 94... Línea 94...
94
 
94
 
95
        $this->assertGreaterThan($category1->sortorder, $category2->sortorder);
95
        $this->assertGreaterThan($category1->sortorder, $category2->sortorder);
96
        $this->assertGreaterThan($category2->sortorder, $category3->sortorder);
96
        $this->assertGreaterThan($category2->sortorder, $category3->sortorder);
Línea 97... Línea 97...
97
    }
97
    }
98
 
98
 
99
    public function test_name_idnumber_exceptions() {
99
    public function test_name_idnumber_exceptions(): void {
100
        try {
100
        try {
101
            core_course_category::create(array('name' => ''));
101
            core_course_category::create(array('name' => ''));
102
            $this->fail('Missing category name exception expected in core_course_category::create');
102
            $this->fail('Missing category name exception expected in core_course_category::create');
Línea 138... Línea 138...
138
        } catch (\Exception $e) {
138
        } catch (\Exception $e) {
139
            $this->assertInstanceOf('moodle_exception', $e);
139
            $this->assertInstanceOf('moodle_exception', $e);
140
        }
140
        }
141
    }
141
    }
Línea 142... Línea 142...
142
 
142
 
143
    public function test_visibility() {
143
    public function test_visibility(): void {
144
        $this->assign_capability('moodle/category:viewhiddencategories');
144
        $this->assign_capability('moodle/category:viewhiddencategories');
Línea 145... Línea 145...
145
        $this->assign_capability('moodle/category:manage');
145
        $this->assign_capability('moodle/category:manage');
146
 
146
 
Línea 206... Línea 206...
206
        $category5->change_parent(0);
206
        $category5->change_parent(0);
207
        $this->assertEquals(0, $category5->visible);
207
        $this->assertEquals(0, $category5->visible);
208
        $this->assertEquals(1, $category5->visibleold);
208
        $this->assertEquals(1, $category5->visibleold);
209
    }
209
    }
Línea 210... Línea 210...
210
 
210
 
211
    public function test_hierarchy() {
211
    public function test_hierarchy(): void {
212
        $this->assign_capability('moodle/category:viewhiddencategories');
212
        $this->assign_capability('moodle/category:viewhiddencategories');
Línea 213... Línea 213...
213
        $this->assign_capability('moodle/category:manage');
213
        $this->assign_capability('moodle/category:manage');
214
 
214
 
Línea 239... Línea 239...
239
        $this->assertEquals(array(), $category4->get_parents());
239
        $this->assertEquals(array(), $category4->get_parents());
240
        $this->assertEquals(array($category2->id, $category3->id), array_keys($category1->get_children()));
240
        $this->assertEquals(array($category2->id, $category3->id), array_keys($category1->get_children()));
241
        $this->assertEquals(array(), array_keys($category2->get_children()));
241
        $this->assertEquals(array(), array_keys($category2->get_children()));
242
    }
242
    }
Línea 243... Línea 243...
243
 
243
 
244
    public function test_update() {
244
    public function test_update(): void {
245
        $category1 = core_course_category::create(array('name' => 'Cat1'));
245
        $category1 = core_course_category::create(array('name' => 'Cat1'));
246
        $timecreated = $category1->timemodified;
246
        $timecreated = $category1->timemodified;
247
        $this->assertSame('Cat1', $category1->name);
247
        $this->assertSame('Cat1', $category1->name);
248
        $this->assertTrue(empty($category1->description));
248
        $this->assertTrue(empty($category1->description));
Línea 257... Línea 257...
257
        $this->assertSame($testdescription, $category1->description);
257
        $this->assertSame($testdescription, $category1->description);
Línea 258... Línea 258...
258
 
258
 
259
        $this->assertGreaterThan($timecreated, $category1->timemodified);
259
        $this->assertGreaterThan($timecreated, $category1->timemodified);
Línea 260... Línea 260...
260
    }
260
    }
261
 
261
 
Línea 262... Línea 262...
262
    public function test_delete() {
262
    public function test_delete(): void {
263
        global $DB;
263
        global $DB;
Línea 334... Línea 334...
334
        $this->assertEquals(1, $DB->get_field_sql('SELECT count(*) FROM {course} WHERE id <> ?', array(SITEID)));
334
        $this->assertEquals(1, $DB->get_field_sql('SELECT count(*) FROM {course} WHERE id <> ?', array(SITEID)));
335
        $this->assertEquals(array('id' => $course4->id, 'category' => $category1->id),
335
        $this->assertEquals(array('id' => $course4->id, 'category' => $category1->id),
336
                (array)$DB->get_record_sql('SELECT id, category from {course} where id <> ?', array(SITEID)));
336
                (array)$DB->get_record_sql('SELECT id, category from {course} where id <> ?', array(SITEID)));
337
    }
337
    }
Línea 338... Línea 338...
338
 
338
 
339
    public function test_get_children() {
339
    public function test_get_children(): void {
340
        $category1 = core_course_category::create(array('name' => 'Cat1'));
340
        $category1 = core_course_category::create(array('name' => 'Cat1'));
341
        $category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
341
        $category2 = core_course_category::create(array('name' => 'Cat2', 'parent' => $category1->id));
342
        $category3 = core_course_category::create(array('name' => 'Cat3', 'parent' => $category1->id, 'visible' => 0));
342
        $category3 = core_course_category::create(array('name' => 'Cat3', 'parent' => $category1->id, 'visible' => 0));
343
        $category4 = core_course_category::create(array('name' => 'Cat4', 'idnumber' => '12', 'parent' => $category1->id));
343
        $category4 = core_course_category::create(array('name' => 'Cat4', 'idnumber' => '12', 'parent' => $category1->id));
Línea 378... Línea 378...
378
    }
378
    }
Línea 379... Línea 379...
379
 
379
 
380
    /**
380
    /**
381
     * Test the get_all_children_ids function.
381
     * Test the get_all_children_ids function.
382
     */
382
     */
383
    public function test_get_all_children_ids() {
383
    public function test_get_all_children_ids(): void {
384
        $category1 = core_course_category::create(array('name' => 'Cat1'));
384
        $category1 = core_course_category::create(array('name' => 'Cat1'));
385
        $category2 = core_course_category::create(array('name' => 'Cat2'));
385
        $category2 = core_course_category::create(array('name' => 'Cat2'));
386
        $category11 = core_course_category::create(array('name' => 'Cat11', 'parent' => $category1->id));
386
        $category11 = core_course_category::create(array('name' => 'Cat11', 'parent' => $category1->id));
387
        $category12 = core_course_category::create(array('name' => 'Cat12', 'parent' => $category1->id));
387
        $category12 = core_course_category::create(array('name' => 'Cat12', 'parent' => $category1->id));
Línea 409... Línea 409...
409
    }
409
    }
Línea 410... Línea 410...
410
 
410
 
411
    /**
411
    /**
412
     * Test the countall function
412
     * Test the countall function
413
     */
413
     */
414
    public function test_count_all() {
414
    public function test_count_all(): void {
415
        global $DB;
415
        global $DB;
416
        // Dont assume there is just one. An add-on might create a category as part of the install.
416
        // Dont assume there is just one. An add-on might create a category as part of the install.
417
        $numcategories = $DB->count_records('course_categories');
417
        $numcategories = $DB->count_records('course_categories');
418
        $this->assertEquals($numcategories, core_course_category::count_all());
418
        $this->assertEquals($numcategories, core_course_category::count_all());
Línea 433... Línea 433...
433
    }
433
    }
Línea 434... Línea 434...
434
 
434
 
435
    /**
435
    /**
436
     * Test the is_simple_site function
436
     * Test the is_simple_site function
437
     */
437
     */
438
    public function test_is_simple_site() {
438
    public function test_is_simple_site(): void {
439
        // By default site has one category and is considered simple.
439
        // By default site has one category and is considered simple.
440
        $this->assertEquals(true, core_course_category::is_simple_site());
440
        $this->assertEquals(true, core_course_category::is_simple_site());
441
        $default = core_course_category::get_default();
441
        $default = core_course_category::get_default();
442
        // When there is only one category but it is hidden, it is not a simple site.
442
        // When there is only one category but it is hidden, it is not a simple site.
Línea 450... Línea 450...
450
    }
450
    }
Línea 451... Línea 451...
451
 
451
 
452
    /**
452
    /**
453
     * Test a categories ability to resort courses.
453
     * Test a categories ability to resort courses.
454
     */
454
     */
455
    public function test_resort_courses() {
455
    public function test_resort_courses(): void {
456
        $this->resetAfterTest(true);
456
        $this->resetAfterTest(true);
457
        $generator = $this->getDataGenerator();
457
        $generator = $this->getDataGenerator();
458
        $category = $generator->create_category();
458
        $category = $generator->create_category();
459
        $course1 = $generator->create_course(array(
459
        $course1 = $generator->create_course(array(
Línea 510... Línea 510...
510
        }
510
        }
511
        $this->assertTrue($coursecat->resort_courses('fullname'));
511
        $this->assertTrue($coursecat->resort_courses('fullname'));
512
        $this->assertSame($expected, array_keys($coursecat->get_courses()));
512
        $this->assertSame($expected, array_keys($coursecat->get_courses()));
513
    }
513
    }
Línea 514... Línea 514...
514
 
514
 
515
    public function test_get_search_courses() {
515
    public function test_get_search_courses(): void {
Línea 516... Línea 516...
516
        global $DB;
516
        global $DB;
517
 
517
 
518
        $cat1 = core_course_category::create(array('name' => 'Cat1'));
518
        $cat1 = core_course_category::create(array('name' => 'Cat1'));
Línea 620... Línea 620...
620
            'search' => '',
620
            'search' => '',
621
            'limittoenrolled' => 1,
621
            'limittoenrolled' => 1,
622
        ]));
622
        ]));
623
    }
623
    }
Línea 624... Línea 624...
624
 
624
 
625
    public function test_course_contacts() {
625
    public function test_course_contacts(): void {
Línea 626... Línea 626...
626
        global $DB, $CFG;
626
        global $DB, $CFG;
Línea 627... Línea 627...
627
 
627
 
Línea 749... Línea 749...
749
        $this->assertEquals('F5 L5', $contact['username']);
749
        $this->assertEquals('F5 L5', $contact['username']);
Línea 750... Línea 750...
750
 
750
 
751
        $CFG->coursecontact = $oldcoursecontact;
751
        $CFG->coursecontact = $oldcoursecontact;
Línea 752... Línea 752...
752
    }
752
    }
753
 
753
 
Línea 754... Línea 754...
754
    public function test_course_contacts_with_duplicates() {
754
    public function test_course_contacts_with_duplicates(): void {
Línea 755... Línea 755...
755
        global $DB, $CFG;
755
        global $DB, $CFG;
Línea 905... Línea 905...
905
        $this->assertEquals('F5 L5', $contact['username']);
905
        $this->assertEquals('F5 L5', $contact['username']);
Línea 906... Línea 906...
906
 
906
 
907
        $CFG->coursecontact = $oldcoursecontact;
907
        $CFG->coursecontact = $oldcoursecontact;
Línea 908... Línea 908...
908
    }
908
    }
909
 
909
 
910
    public function test_overview_files() {
910
    public function test_overview_files(): void {
911
        global $CFG;
911
        global $CFG;
Línea 912... Línea 912...
912
        $this->setAdminUser();
912
        $this->setAdminUser();
Línea 996... Línea 996...
996
        $this->assertEquals(0, count($courses[$c3->id]->get_course_overviewfiles()));
996
        $this->assertEquals(0, count($courses[$c3->id]->get_course_overviewfiles()));
997
        $this->assertEquals(2, count($courses[$c4->id]->get_course_overviewfiles()));
997
        $this->assertEquals(2, count($courses[$c4->id]->get_course_overviewfiles()));
998
        $this->assertEquals(1, count($courses[$c5->id]->get_course_overviewfiles()));
998
        $this->assertEquals(1, count($courses[$c5->id]->get_course_overviewfiles()));
999
    }
999
    }
Línea 1000... Línea 1000...
1000
 
1000
 
1001
    public function test_get_nested_name() {
1001
    public function test_get_nested_name(): void {
1002
        $cat1name = 'Cat1';
1002
        $cat1name = 'Cat1';
1003
        $cat2name = 'Cat2';
1003
        $cat2name = 'Cat2';
1004
        $cat3name = 'Cat3';
1004
        $cat3name = 'Cat3';
1005
        $cat4name = 'Cat4';
1005
        $cat4name = 'Cat4';
Línea 1012... Línea 1012...
1012
        $this->assertEquals("{$cat1name} / {$cat2name}", $category2->get_nested_name(false));
1012
        $this->assertEquals("{$cat1name} / {$cat2name}", $category2->get_nested_name(false));
1013
        $this->assertEquals("{$cat1name} / {$cat2name} / {$cat3name}", $category3->get_nested_name(false));
1013
        $this->assertEquals("{$cat1name} / {$cat2name} / {$cat3name}", $category3->get_nested_name(false));
1014
        $this->assertEquals("{$cat1name} / {$cat2name} / {$cat4name}", $category4->get_nested_name(false));
1014
        $this->assertEquals("{$cat1name} / {$cat2name} / {$cat4name}", $category4->get_nested_name(false));
1015
    }
1015
    }
Línea 1016... Línea 1016...
1016
 
1016
 
1017
    public function test_coursecat_is_uservisible() {
1017
    public function test_coursecat_is_uservisible(): void {
Línea 1018... Línea 1018...
1018
        global $USER;
1018
        global $USER;
1019
 
1019
 
1020
        // Create category 1 as visible.
1020
        // Create category 1 as visible.
Línea 1042... Línea 1042...
1042
 
1042
 
1043
        $this->assertTrue($category1->is_uservisible());
1043
        $this->assertTrue($category1->is_uservisible());
1044
        $this->assertFalse($category2->is_uservisible());
1044
        $this->assertFalse($category2->is_uservisible());
Línea 1045... Línea 1045...
1045
    }
1045
    }
1046
 
1046
 
Línea 1047... Línea 1047...
1047
    public function test_current_user_coursecat_get() {
1047
    public function test_current_user_coursecat_get(): void {
1048
        $this->assign_capability('moodle/category:viewhiddencategories');
1048
        $this->assign_capability('moodle/category:viewhiddencategories');
1049
 
1049
 
Línea 1063... Línea 1063...
1063
        $this->expectException('moodle_exception');
1063
        $this->expectException('moodle_exception');
1064
        $this->expectExceptionMessage(get_string('cannotviewcategory', 'error'));
1064
        $this->expectExceptionMessage(get_string('cannotviewcategory', 'error'));
1065
        core_course_category::get($category2->id);
1065
        core_course_category::get($category2->id);
1066
    }
1066
    }
Línea 1067... Línea 1067...
1067
 
1067
 
1068
    public function test_another_user_coursecat_get() {
1068
    public function test_another_user_coursecat_get(): void {
Línea 1069... Línea 1069...
1069
        global $USER;
1069
        global $USER;
Línea 1070... Línea 1070...
1070
 
1070
 
Línea 1113... Línea 1113...
1113
    }
1113
    }
Línea 1114... Línea 1114...
1114
 
1114
 
1115
    /**
1115
    /**
1116
     * This test ensures that is the list of courses in a category can be retrieved while a course is being deleted.
1116
     * This test ensures that is the list of courses in a category can be retrieved while a course is being deleted.
1117
     */
1117
     */
1118
    public function test_get_courses_during_delete() {
1118
    public function test_get_courses_during_delete(): void {
1119
        global $DB;
1119
        global $DB;
1120
        $category = self::getDataGenerator()->create_category();
1120
        $category = self::getDataGenerator()->create_category();
1121
        $course = self::getDataGenerator()->create_course(['category' => $category->id]);
1121
        $course = self::getDataGenerator()->create_course(['category' => $category->id]);
1122
        $othercourse = self::getDataGenerator()->create_course(['category' => $category->id]);
1122
        $othercourse = self::getDataGenerator()->create_course(['category' => $category->id]);
Línea 1381... Línea 1381...
1381
    /**
1381
    /**
1382
     * This test ensures that the filter context list is populated by the correct filter contexts from make_category_list.
1382
     * This test ensures that the filter context list is populated by the correct filter contexts from make_category_list.
1383
     *
1383
     *
1384
     * @coversNothing
1384
     * @coversNothing
1385
     */
1385
     */
1386
    public function test_make_category_list_context() {
1386
    public function test_make_category_list_context(): void {
1387
        global $DB;
1387
        global $DB;
1388
        // Ensure that the category list is empty.
1388
        // Ensure that the category list is empty.
1389
        $DB->delete_records('course_categories');
1389
        $DB->delete_records('course_categories');
1390
        set_config('perfdebug', 15);
1390
        set_config('perfdebug', 15);