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
class external_test extends externallib_advanced_testcase {
45
class external_test extends externallib_advanced_testcase {
Línea 46... Línea 46...
46
 
46
 
47
    /**
47
    /**
48
     * Test get_glossaries_by_courses
48
     * Test get_glossaries_by_courses
49
     */
49
     */
50
    public function test_get_glossaries_by_courses() {
50
    public function test_get_glossaries_by_courses(): void {
Línea 51... Línea 51...
51
        $this->resetAfterTest(true);
51
        $this->resetAfterTest(true);
52
 
52
 
53
        // As admin.
53
        // As admin.
Línea 94... Línea 94...
94
        $this->assertCount(1, $glossaries['glossaries']);
94
        $this->assertCount(1, $glossaries['glossaries']);
95
        $this->assertEquals('Third Glossary', $glossaries['glossaries'][0]['name']);
95
        $this->assertEquals('Third Glossary', $glossaries['glossaries'][0]['name']);
96
        $this->assertEquals(1, $glossaries['glossaries'][0]['canaddentry']);
96
        $this->assertEquals(1, $glossaries['glossaries'][0]['canaddentry']);
97
    }
97
    }
Línea 98... Línea 98...
98
 
98
 
99
    public function test_view_glossary() {
99
    public function test_view_glossary(): void {
Línea 100... Línea 100...
100
        $this->resetAfterTest(true);
100
        $this->resetAfterTest(true);
101
 
101
 
102
        // Generate all the things.
102
        // Generate all the things.
Línea 117... Línea 117...
117
        $this->assertCount(1, $events);
117
        $this->assertCount(1, $events);
118
        $this->assertEquals('\mod_glossary\event\course_module_viewed', $events[0]->eventname);
118
        $this->assertEquals('\mod_glossary\event\course_module_viewed', $events[0]->eventname);
119
        $sink->close();
119
        $sink->close();
120
    }
120
    }
Línea 121... Línea 121...
121
 
121
 
122
    public function test_view_glossary_without_permission() {
122
    public function test_view_glossary_without_permission(): void {
Línea 123... Línea 123...
123
        $this->resetAfterTest(true);
123
        $this->resetAfterTest(true);
124
 
124
 
125
        // Generate all the things.
125
        // Generate all the things.
Línea 140... Línea 140...
140
        $this->expectException(\require_login_exception::class);
140
        $this->expectException(\require_login_exception::class);
141
        $this->expectExceptionMessage('Activity is hidden');
141
        $this->expectExceptionMessage('Activity is hidden');
142
        mod_glossary_external::view_glossary($g1->id, 'letter');
142
        mod_glossary_external::view_glossary($g1->id, 'letter');
143
    }
143
    }
Línea 144... Línea 144...
144
 
144
 
145
    public function test_view_entry() {
145
    public function test_view_entry(): void {
Línea 146... Línea 146...
146
        $this->resetAfterTest(true);
146
        $this->resetAfterTest(true);
147
 
147
 
148
        // Generate all the things.
148
        // Generate all the things.
Línea 192... Línea 192...
192
        $this->expectException(\require_login_exception::class);
192
        $this->expectException(\require_login_exception::class);
193
        $this->expectExceptionMessage('Activity is hidden');
193
        $this->expectExceptionMessage('Activity is hidden');
194
        mod_glossary_external::view_entry($e4->id);
194
        mod_glossary_external::view_entry($e4->id);
195
    }
195
    }
Línea 196... Línea 196...
196
 
196
 
197
    public function test_get_entries_by_letter() {
197
    public function test_get_entries_by_letter(): void {
Línea 198... Línea 198...
198
        $this->resetAfterTest(true);
198
        $this->resetAfterTest(true);
199
 
199
 
200
        // Generate all the things.
200
        // Generate all the things.
Línea 253... Línea 253...
253
        $this->assertEquals($e1d->id, $return['entries'][0]['id']);
253
        $this->assertEquals($e1d->id, $return['entries'][0]['id']);
254
        $this->assertEquals($e1c->id, $return['entries'][1]['id']);
254
        $this->assertEquals($e1c->id, $return['entries'][1]['id']);
255
        $this->assertEquals($e1b->id, $return['entries'][2]['id']);
255
        $this->assertEquals($e1b->id, $return['entries'][2]['id']);
256
    }
256
    }
Línea 257... Línea 257...
257
 
257
 
258
    public function test_get_entries_by_letter_with_parameters() {
258
    public function test_get_entries_by_letter_with_parameters(): void {
Línea 259... Línea 259...
259
        $this->resetAfterTest(true);
259
        $this->resetAfterTest(true);
260
 
260
 
261
        // Generate all the things.
261
        // Generate all the things.
Línea 299... Línea 299...
299
        $this->assertEquals(3, $return['count']);
299
        $this->assertEquals(3, $return['count']);
300
        $this->assertEquals($e1c->id, $return['entries'][0]['id']);
300
        $this->assertEquals($e1c->id, $return['entries'][0]['id']);
301
        $this->assertEquals($e1b->id, $return['entries'][1]['id']);
301
        $this->assertEquals($e1b->id, $return['entries'][1]['id']);
302
    }
302
    }
Línea 303... Línea 303...
303
 
303
 
304
    public function test_get_entries_by_date() {
304
    public function test_get_entries_by_date(): void {
305
        global $DB;
305
        global $DB;
Línea 306... Línea 306...
306
        $this->resetAfterTest(true);
306
        $this->resetAfterTest(true);
307
 
307
 
Línea 391... Línea 391...
391
        $this->assertEquals(4, $return['count']);
391
        $this->assertEquals(4, $return['count']);
392
        $this->assertEquals($e1d->id, $return['entries'][0]['id']);
392
        $this->assertEquals($e1d->id, $return['entries'][0]['id']);
393
        $this->assertEquals($e1b->id, $return['entries'][1]['id']);
393
        $this->assertEquals($e1b->id, $return['entries'][1]['id']);
394
    }
394
    }
Línea 395... Línea 395...
395
 
395
 
396
    public function test_get_categories() {
396
    public function test_get_categories(): void {
397
        $this->resetAfterTest(true);
397
        $this->resetAfterTest(true);
Línea 398... Línea 398...
398
        $this->setAdminUser();
398
        $this->setAdminUser();
399
 
399
 
Línea 420... Línea 420...
420
        $this->assertEquals(3, $return['count']);
420
        $this->assertEquals(3, $return['count']);
421
        $this->assertEquals($cat1b->id, $return['categories'][0]['id']);
421
        $this->assertEquals($cat1b->id, $return['categories'][0]['id']);
422
        $this->assertEquals($cat1c->id, $return['categories'][1]['id']);
422
        $this->assertEquals($cat1c->id, $return['categories'][1]['id']);
423
    }
423
    }
Línea 424... Línea 424...
424
 
424
 
425
    public function test_get_entries_by_category() {
425
    public function test_get_entries_by_category(): void {
Línea 426... Línea 426...
426
        $this->resetAfterTest(true);
426
        $this->resetAfterTest(true);
427
 
427
 
428
        $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
428
        $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
Línea 503... Línea 503...
503
        $this->assertEquals(6, $return['count']);
503
        $this->assertEquals(6, $return['count']);
504
        $this->assertEquals($e1a2->id, $return['entries'][0]['id']);
504
        $this->assertEquals($e1a2->id, $return['entries'][0]['id']);
505
        $this->assertEquals($e1a3->id, $return['entries'][1]['id']);
505
        $this->assertEquals($e1a3->id, $return['entries'][1]['id']);
506
    }
506
    }
Línea 507... Línea 507...
507
 
507
 
508
    public function test_get_authors() {
508
    public function test_get_authors(): void {
Línea 509... Línea 509...
509
        $this->resetAfterTest(true);
509
        $this->resetAfterTest(true);
510
 
510
 
511
        $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
511
        $gg = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
Línea 550... Línea 550...
550
        $this->assertCount(1, $return['authors']);
550
        $this->assertCount(1, $return['authors']);
551
        $this->assertEquals(3, $return['count']);
551
        $this->assertEquals(3, $return['count']);
552
        $this->assertEquals($u3->id, $return['authors'][0]['id']);
552
        $this->assertEquals($u3->id, $return['authors'][0]['id']);
553
    }
553
    }
Línea 554... Línea 554...
554
 
554
 
555
    public function test_get_entries_by_author() {
555
    public function test_get_entries_by_author(): void {
Línea 556... Línea 556...
556
        $this->resetAfterTest(true);
556
        $this->resetAfterTest(true);
557
 
557
 
558
        // Generate all the things.
558
        // Generate all the things.
Línea 666... Línea 666...
666
        $this->assertEquals($e1a1->id, $return['entries'][1]['id']);
666
        $this->assertEquals($e1a1->id, $return['entries'][1]['id']);
667
        $this->assertEquals($e1a2->id, $return['entries'][2]['id']);
667
        $this->assertEquals($e1a2->id, $return['entries'][2]['id']);
668
        $this->assertEquals($e1a3->id, $return['entries'][3]['id']);
668
        $this->assertEquals($e1a3->id, $return['entries'][3]['id']);
669
    }
669
    }
Línea 670... Línea 670...
670
 
670
 
671
    public function test_get_entries_by_author_id() {
671
    public function test_get_entries_by_author_id(): void {
Línea 672... Línea 672...
672
        $this->resetAfterTest(true);
672
        $this->resetAfterTest(true);
673
 
673
 
674
        // Generate all the things.
674
        // Generate all the things.
Línea 774... Línea 774...
774
        $this->assertEquals(4, $return['count']);
774
        $this->assertEquals(4, $return['count']);
775
        $this->assertEquals($e1a4->id, $return['entries'][0]['id']);
775
        $this->assertEquals($e1a4->id, $return['entries'][0]['id']);
776
        $this->assertEquals($e1a3->id, $return['entries'][1]['id']);
776
        $this->assertEquals($e1a3->id, $return['entries'][1]['id']);
777
    }
777
    }
Línea 778... Línea 778...
778
 
778
 
779
    public function test_get_entries_by_search() {
779
    public function test_get_entries_by_search(): void {
Línea 780... Línea 780...
780
        $this->resetAfterTest(true);
780
        $this->resetAfterTest(true);
781
 
781
 
782
        // Generate all the things.
782
        // Generate all the things.
Línea 890... Línea 890...
890
        $this->assertEquals(2, $return['count']);
890
        $this->assertEquals(2, $return['count']);
891
        $this->assertEquals($e6->id, $return['entries'][0]['id']);
891
        $this->assertEquals($e6->id, $return['entries'][0]['id']);
892
        $this->assertEquals($e8->id, $return['entries'][1]['id']);
892
        $this->assertEquals($e8->id, $return['entries'][1]['id']);
893
    }
893
    }
Línea 894... Línea 894...
894
 
894
 
895
    public function test_get_entries_by_term() {
895
    public function test_get_entries_by_term(): void {
Línea 896... Línea 896...
896
        $this->resetAfterTest(true);
896
        $this->resetAfterTest(true);
897
 
897
 
898
        // Generate all the things.
898
        // Generate all the things.
Línea 964... Línea 964...
964
        $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
964
        $return = external_api::clean_returnvalue(mod_glossary_external::get_entries_by_term_returns(), $return);
965
        $this->assertCount(1, $return['entries']);
965
        $this->assertCount(1, $return['entries']);
966
        $this->assertEquals(3, $return['count']);
966
        $this->assertEquals(3, $return['count']);
967
    }
967
    }
Línea 968... Línea 968...
968
 
968
 
969
    public function test_get_entries_to_approve() {
969
    public function test_get_entries_to_approve(): void {
Línea 970... Línea 970...
970
        $this->resetAfterTest(true);
970
        $this->resetAfterTest(true);
971
 
971
 
972
        // Generate all the things.
972
        // Generate all the things.
Línea 1070... Línea 1070...
1070
        $this->expectException('required_capability_exception');
1070
        $this->expectException('required_capability_exception');
1071
        mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 0, 1);
1071
        mod_glossary_external::get_entries_to_approve($g1->id, 'ALL', 'CONCEPT', 'ASC', 0, 1);
1072
        $this->fail('Do not test anything else after this.');
1072
        $this->fail('Do not test anything else after this.');
1073
    }
1073
    }
Línea 1074... Línea 1074...
1074
 
1074
 
1075
    public function test_get_entry_by_id() {
1075
    public function test_get_entry_by_id(): void {
Línea 1076... Línea 1076...
1076
        $this->resetAfterTest(true);
1076
        $this->resetAfterTest(true);
1077
 
1077
 
1078
        // Generate all the things.
1078
        // Generate all the things.
Línea 1148... Línea 1148...
1148
        $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
1148
        $return = external_api::clean_returnvalue(mod_glossary_external::get_entry_by_id_returns(), $return);
1149
        $this->assertEquals($e1->id, $return['entry']['id']);
1149
        $this->assertEquals($e1->id, $return['entry']['id']);
1150
        $this->assertFalse($return['permissions']['candelete']);
1150
        $this->assertFalse($return['permissions']['candelete']);
1151
    }
1151
    }
Línea 1152... Línea 1152...
1152
 
1152
 
1153
    public function test_add_entry_without_optional_settings() {
1153
    public function test_add_entry_without_optional_settings(): void {
1154
        global $CFG, $DB;
1154
        global $CFG, $DB;
Línea 1155... Línea 1155...
1155
        $this->resetAfterTest(true);
1155
        $this->resetAfterTest(true);
1156
 
1156
 
Línea 1173... Línea 1173...
1173
        $this->assertEquals($CFG->glossary_fullmatch, $entry->fullmatch);
1173
        $this->assertEquals($CFG->glossary_fullmatch, $entry->fullmatch);
1174
        $this->assertEmpty($DB->get_records('glossary_alias', array('entryid' => $return['entryid'])));
1174
        $this->assertEmpty($DB->get_records('glossary_alias', array('entryid' => $return['entryid'])));
1175
        $this->assertEmpty($DB->get_records('glossary_entries_categories', array('entryid' => $return['entryid'])));
1175
        $this->assertEmpty($DB->get_records('glossary_entries_categories', array('entryid' => $return['entryid'])));
1176
    }
1176
    }
Línea 1177... Línea 1177...
1177
 
1177
 
1178
    public function test_add_entry_with_aliases() {
1178
    public function test_add_entry_with_aliases(): void {
1179
        global $DB;
1179
        global $DB;
Línea 1180... Línea 1180...
1180
        $this->resetAfterTest(true);
1180
        $this->resetAfterTest(true);
1181
 
1181
 
Línea 1200... Línea 1200...
1200
        foreach ($aliases as $alias) {
1200
        foreach ($aliases as $alias) {
1201
            $this->assertStringContainsString($alias->alias, $paramaliases);
1201
            $this->assertStringContainsString($alias->alias, $paramaliases);
1202
        }
1202
        }
1203
    }
1203
    }
Línea 1204... Línea 1204...
1204
 
1204
 
1205
    public function test_add_entry_in_categories() {
1205
    public function test_add_entry_in_categories(): void {
1206
        global $DB;
1206
        global $DB;
Línea 1207... Línea 1207...
1207
        $this->resetAfterTest(true);
1207
        $this->resetAfterTest(true);
1208
 
1208
 
Línea 1230... Línea 1230...
1230
        foreach ($categories as $category) {
1230
        foreach ($categories as $category) {
1231
            $this->assertStringContainsString($category->categoryid, $paramcategories);
1231
            $this->assertStringContainsString($category->categoryid, $paramcategories);
1232
        }
1232
        }
1233
    }
1233
    }
Línea 1234... Línea 1234...
1234
 
1234
 
1235
    public function test_add_entry_with_attachments() {
1235
    public function test_add_entry_with_attachments(): void {
1236
        global $DB, $USER;
1236
        global $DB, $USER;
Línea 1237... Línea 1237...
1237
        $this->resetAfterTest(true);
1237
        $this->resetAfterTest(true);
1238
 
1238
 
Línea 1290... Línea 1290...
1290
    }
1290
    }
Línea 1291... Línea 1291...
1291
 
1291
 
1292
    /**
1292
    /**
1293
     *   Test get entry including rating information.
1293
     *   Test get entry including rating information.
1294
     */
1294
     */
1295
    public function test_get_entry_rating_information() {
1295
    public function test_get_entry_rating_information(): void {
Línea 1296... Línea 1296...
1296
        $this->resetAfterTest(true);
1296
        $this->resetAfterTest(true);
1297
 
1297