Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 11
Línea 36... Línea 36...
36
 * @copyright  2015 Frédéric Massart - FMCorz.net
36
 * @copyright  2015 Frédéric Massart - FMCorz.net
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
38
 */
39
class lib_test extends \advanced_testcase {
39
class lib_test extends \advanced_testcase {
Línea 40... Línea 40...
40
 
40
 
41
    public function test_glossary_view() {
41
    public function test_glossary_view(): void {
42
        global $CFG;
42
        global $CFG;
43
        $origcompletion = $CFG->enablecompletion;
43
        $origcompletion = $CFG->enablecompletion;
44
        $CFG->enablecompletion = true;
44
        $CFG->enablecompletion = true;
Línea 92... Línea 92...
92
        // Tear down.
92
        // Tear down.
93
        $sink->close();
93
        $sink->close();
94
        $CFG->enablecompletion = $origcompletion;
94
        $CFG->enablecompletion = $origcompletion;
95
    }
95
    }
Línea 96... Línea 96...
96
 
96
 
97
    public function test_glossary_entry_view() {
97
    public function test_glossary_entry_view(): void {
Línea 98... Línea 98...
98
        $this->resetAfterTest(true);
98
        $this->resetAfterTest(true);
99
 
99
 
100
        // Generate all the things.
100
        // Generate all the things.
Línea 114... Línea 114...
114
        $this->assertEquals('\mod_glossary\event\entry_viewed', $events[0]->eventname);
114
        $this->assertEquals('\mod_glossary\event\entry_viewed', $events[0]->eventname);
115
        $this->assertEquals($e1->id, $events[0]->objectid);
115
        $this->assertEquals($e1->id, $events[0]->objectid);
116
        $sink->close();
116
        $sink->close();
117
    }
117
    }
Línea 118... Línea 118...
118
 
118
 
119
    public function test_glossary_core_calendar_provide_event_action() {
119
    public function test_glossary_core_calendar_provide_event_action(): void {
120
        $this->resetAfterTest();
120
        $this->resetAfterTest();
Línea 121... Línea 121...
121
        $this->setAdminUser();
121
        $this->setAdminUser();
122
 
122
 
Línea 140... Línea 140...
140
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
140
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
141
        $this->assertEquals(1, $actionevent->get_item_count());
141
        $this->assertEquals(1, $actionevent->get_item_count());
142
        $this->assertTrue($actionevent->is_actionable());
142
        $this->assertTrue($actionevent->is_actionable());
143
    }
143
    }
Línea 144... Línea 144...
144
 
144
 
145
    public function test_glossary_core_calendar_provide_event_action_as_non_user() {
145
    public function test_glossary_core_calendar_provide_event_action_as_non_user(): void {
Línea 146... Línea 146...
146
        global $CFG;
146
        global $CFG;
147
 
147
 
Línea 168... Línea 168...
168
 
168
 
169
        // Confirm the event is not shown at all.
169
        // Confirm the event is not shown at all.
170
        $this->assertNull($actionevent);
170
        $this->assertNull($actionevent);
Línea 171... Línea 171...
171
    }
171
    }
172
 
172
 
Línea 173... Línea 173...
173
    public function test_glossary_core_calendar_provide_event_action_for_user() {
173
    public function test_glossary_core_calendar_provide_event_action_for_user(): void {
174
        global $CFG;
174
        global $CFG;
Línea 205... Línea 205...
205
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
205
        $this->assertInstanceOf('moodle_url', $actionevent->get_url());
206
        $this->assertEquals(1, $actionevent->get_item_count());
206
        $this->assertEquals(1, $actionevent->get_item_count());
207
        $this->assertTrue($actionevent->is_actionable());
207
        $this->assertTrue($actionevent->is_actionable());
208
    }
208
    }
Línea 209... Línea 209...
209
 
209
 
210
    public function test_glossary_core_calendar_provide_event_action_in_hidden_section() {
210
    public function test_glossary_core_calendar_provide_event_action_in_hidden_section(): void {
211
        $this->resetAfterTest();
211
        $this->resetAfterTest();
Línea 212... Línea 212...
212
        $this->setAdminUser();
212
        $this->setAdminUser();
213
 
213
 
Línea 235... Línea 235...
235
 
235
 
236
        // Confirm the event is not shown at all.
236
        // Confirm the event is not shown at all.
237
        $this->assertNull($actionevent);
237
        $this->assertNull($actionevent);
Línea 238... Línea 238...
238
    }
238
    }
239
 
239
 
Línea 240... Línea 240...
240
    public function test_glossary_core_calendar_provide_event_action_already_completed() {
240
    public function test_glossary_core_calendar_provide_event_action_already_completed(): void {
241
        global $CFG;
241
        global $CFG;
Línea 269... Línea 269...
269
 
269
 
270
        // Ensure result was null.
270
        // Ensure result was null.
271
        $this->assertNull($actionevent);
271
        $this->assertNull($actionevent);
Línea 272... Línea 272...
272
    }
272
    }
273
 
273
 
Línea 274... Línea 274...
274
    public function test_glossary_core_calendar_provide_event_action_already_completed_for_user() {
274
    public function test_glossary_core_calendar_provide_event_action_already_completed_for_user(): void {
275
        global $CFG;
275
        global $CFG;
Línea 334... Línea 334...
334
    /**
334
    /**
335
     * Test the callback responsible for returning the completion rule descriptions.
335
     * Test the callback responsible for returning the completion rule descriptions.
336
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
336
     * This function should work given either an instance of the module (cm_info), such as when checking the active rules,
337
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
337
     * or if passed a stdClass of similar structure, such as when checking the the default completion settings for a mod type.
338
     */
338
     */
339
    public function test_mod_glossary_completion_get_active_rule_descriptions() {
339
    public function test_mod_glossary_completion_get_active_rule_descriptions(): void {
340
        $this->resetAfterTest();
340
        $this->resetAfterTest();
341
        $this->setAdminUser();
341
        $this->setAdminUser();
Línea 342... Línea 342...
342
 
342
 
343
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
343
        // Two activities, both with automatic completion. One has the 'completionsubmit' rule, one doesn't.
Línea 367... Línea 367...
367
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($cm2), []);
367
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($cm2), []);
368
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
368
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions($moddefaults), $activeruledescriptions);
369
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions(new \stdClass()), []);
369
        $this->assertEquals(mod_glossary_get_completion_active_rule_descriptions(new \stdClass()), []);
370
    }
370
    }
Línea 371... Línea 371...
371
 
371
 
372
    public function test_mod_glossary_get_tagged_entries() {
372
    public function test_mod_glossary_get_tagged_entries(): void {
Línea 373... Línea 373...
373
        global $DB;
373
        global $DB;
374
 
374
 
Línea 466... Línea 466...
466
        // User cannot see unapproved entries unless he is an author.
466
        // User cannot see unapproved entries unless he is an author.
467
        $this->assertDoesNotMatchRegularExpression('/'.$entry16->concept.'/', $res->content);
467
        $this->assertDoesNotMatchRegularExpression('/'.$entry16->concept.'/', $res->content);
468
        $this->assertMatchesRegularExpression('/'.$entry17->concept.'/', $res->content);
468
        $this->assertMatchesRegularExpression('/'.$entry17->concept.'/', $res->content);
469
    }
469
    }
Línea 470... Línea 470...
470
 
470
 
471
    public function test_glossary_get_entries_search() {
471
    public function test_glossary_get_entries_search(): void {
472
        $this->resetAfterTest();
472
        $this->resetAfterTest();
473
        $this->setAdminUser();
473
        $this->setAdminUser();
474
        // Turn on glossary autolinking (usedynalink).
474
        // Turn on glossary autolinking (usedynalink).
475
        set_config('glossary_linkentries', 1);
475
        set_config('glossary_linkentries', 1);
Línea 503... Línea 503...
503
        $concept = strtolower($entry->concept);
503
        $concept = strtolower($entry->concept);
504
        $search = glossary_get_entries_search($concept, $course->id);
504
        $search = glossary_get_entries_search($concept, $course->id);
505
        $this->assertCount(0, $search);
505
        $this->assertCount(0, $search);
506
    }
506
    }
Línea 507... Línea 507...
507
 
507
 
508
    public function test_mod_glossary_can_delete_entry_users() {
508
    public function test_mod_glossary_can_delete_entry_users(): void {
Línea 509... Línea 509...
509
        $this->resetAfterTest();
509
        $this->resetAfterTest();
510
 
510
 
511
        // Create required data.
511
        // Create required data.
Línea 538... Línea 538...
538
        // Test exception.
538
        // Test exception.
539
        $this->expectExceptionMessage(get_string('nopermissiontodelentry', 'error'));
539
        $this->expectExceptionMessage(get_string('nopermissiontodelentry', 'error'));
540
        mod_glossary_can_delete_entry($entry, $glossary, $context, false);
540
        mod_glossary_can_delete_entry($entry, $glossary, $context, false);
541
    }
541
    }
Línea 542... Línea 542...
542
 
542
 
543
    public function test_mod_glossary_can_delete_entry_edit_period() {
543
    public function test_mod_glossary_can_delete_entry_edit_period(): void {
544
        global $CFG;
544
        global $CFG;
Línea 545... Línea 545...
545
        $this->resetAfterTest();
545
        $this->resetAfterTest();
546
 
546
 
Línea 570... Línea 570...
570
        $entry->timecreated = time() - 2 * $CFG->maxeditingtime;
570
        $entry->timecreated = time() - 2 * $CFG->maxeditingtime;
571
        $this->expectExceptionMessage(get_string('errdeltimeexpired', 'glossary'));
571
        $this->expectExceptionMessage(get_string('errdeltimeexpired', 'glossary'));
572
        mod_glossary_can_delete_entry($entry, $glossary, $context, false);
572
        mod_glossary_can_delete_entry($entry, $glossary, $context, false);
573
    }
573
    }
Línea 574... Línea 574...
574
 
574
 
575
    public function test_mod_glossary_delete_entry() {
575
    public function test_mod_glossary_delete_entry(): void {
576
        global $DB, $CFG;
576
        global $DB, $CFG;
577
        $this->resetAfterTest();
577
        $this->resetAfterTest();
Línea 578... Línea 578...
578
        require_once($CFG->dirroot . '/rating/lib.php');
578
        require_once($CFG->dirroot . '/rating/lib.php');
Línea 629... Línea 629...
629
        $this->assertEquals(0, $DB->count_records('glossary_alias', ['entryid' => $entry->id]));
629
        $this->assertEquals(0, $DB->count_records('glossary_alias', ['entryid' => $entry->id]));
630
        $this->assertEquals(0, $DB->count_records('rating', ['component' => 'mod_glossary', 'itemid' => $entry->id]));
630
        $this->assertEquals(0, $DB->count_records('rating', ['component' => 'mod_glossary', 'itemid' => $entry->id]));
631
        $this->assertEmpty(\core_tag_tag::get_by_name(0, 'Cats'));
631
        $this->assertEmpty(\core_tag_tag::get_by_name(0, 'Cats'));
632
    }
632
    }
Línea 633... Línea 633...
633
 
633
 
634
    public function test_mod_glossary_delete_entry_imported() {
634
    public function test_mod_glossary_delete_entry_imported(): void {
635
        global $DB;
635
        global $DB;
Línea 636... Línea 636...
636
        $this->resetAfterTest();
636
        $this->resetAfterTest();
637
 
637
 
Línea 670... Línea 670...
670
 
670
 
671
        // Tags.
671
        // Tags.
672
        $this->assertEmpty(\core_tag_tag::get_by_name(0, 'Cats'));
672
        $this->assertEmpty(\core_tag_tag::get_by_name(0, 'Cats'));
Línea 673... Línea 673...
673
    }
673
    }
674
 
674
 
Línea 675... Línea 675...
675
    public function test_mod_glossary_can_update_entry_users() {
675
    public function test_mod_glossary_can_update_entry_users(): void {
676
        $this->resetAfterTest();
676
        $this->resetAfterTest();
677
 
677
 
Línea 706... Línea 706...
706
        // Test exception.
706
        // Test exception.
707
        $this->expectExceptionMessage(get_string('errcannoteditothers', 'glossary'));
707
        $this->expectExceptionMessage(get_string('errcannoteditothers', 'glossary'));
708
        mod_glossary_can_update_entry($entry, $glossary, $context, $cm, false);
708
        mod_glossary_can_update_entry($entry, $glossary, $context, $cm, false);
709
    }
709
    }
Línea 710... Línea 710...
710
 
710
 
711
    public function test_mod_glossary_can_update_entry_edit_period() {
711
    public function test_mod_glossary_can_update_entry_edit_period(): void {
712
        global $CFG;
712
        global $CFG;
Línea 713... Línea 713...
713
        $this->resetAfterTest();
713
        $this->resetAfterTest();
714
 
714
 
Línea 739... Línea 739...
739
        $entry->timecreated = time() - 2 * $CFG->maxeditingtime;
739
        $entry->timecreated = time() - 2 * $CFG->maxeditingtime;
740
        $this->expectExceptionMessage(get_string('erredittimeexpired', 'glossary'));
740
        $this->expectExceptionMessage(get_string('erredittimeexpired', 'glossary'));
741
        mod_glossary_can_update_entry($entry, $glossary, $context, $cm, false);
741
        mod_glossary_can_update_entry($entry, $glossary, $context, $cm, false);
742
    }
742
    }
Línea 743... Línea 743...
743
 
743
 
744
    public function test_prepare_entry_for_edition() {
744
    public function test_prepare_entry_for_edition(): void {
745
        global $USER;
745
        global $USER;
Línea 746... Línea 746...
746
        $this->resetAfterTest(true);
746
        $this->resetAfterTest(true);
747
 
747