Proyectos de Subversion Moodle

Rev

Rev 11 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Tests for langimport events.
19
 *
20
 * @package    tool_langimport
21
 * @copyright  2014 Dan Poltawski
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
23
 */
24
 
25
namespace tool_langimport\event;
26
 
27
/**
28
 * Test class for langimport events.
29
 *
30
 * @package    tool_langimport
31
 * @copyright  2014 Dan Poltawski
32
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
33
 */
1441 ariadna 34
final class events_test extends \advanced_testcase {
1 efrain 35
 
36
    /**
37
     * Setup testcase.
38
     */
39
    public function setUp(): void {
1441 ariadna 40
        parent::setUp();
1 efrain 41
        $this->setAdminUser();
42
        $this->resetAfterTest();
43
    }
44
 
11 efrain 45
    public function test_langpack_updated(): void {
1 efrain 46
        global $CFG;
47
 
48
        $event = \tool_langimport\event\langpack_updated::event_with_langcode($CFG->lang);
49
 
50
        // Trigger and capture the event.
51
        $sink = $this->redirectEvents();
52
        $event->trigger();
53
        $events = $sink->get_events();
54
        $event = reset($events);
55
 
56
        $this->assertInstanceOf('\tool_langimport\event\langpack_updated', $event);
57
        $this->assertEquals(\context_system::instance(), $event->get_context());
58
    }
59
 
11 efrain 60
    public function test_langpack_updated_validation(): void {
1 efrain 61
 
62
        $this->expectException('coding_exception');
63
        $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
64
        \tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
65
    }
66
 
11 efrain 67
    public function test_langpack_installed(): void {
1 efrain 68
        $event = \tool_langimport\event\langpack_imported::event_with_langcode('fr');
69
 
70
        // Trigger and capture the event.
71
        $sink = $this->redirectEvents();
72
        $event->trigger();
73
        $events = $sink->get_events();
74
        $event = reset($events);
75
 
76
        $this->assertInstanceOf('\tool_langimport\event\langpack_imported', $event);
77
        $this->assertEquals(\context_system::instance(), $event->get_context());
78
    }
79
 
11 efrain 80
    public function test_langpack_installed_validation(): void {
1 efrain 81
 
82
        $this->expectException('coding_exception');
83
        $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
84
        \tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
85
    }
86
 
11 efrain 87
    public function test_langpack_removed(): void {
1 efrain 88
        $event = \tool_langimport\event\langpack_removed::event_with_langcode('fr');
89
 
90
        // Trigger and capture the event.
91
        $sink = $this->redirectEvents();
92
        $event->trigger();
93
        $events = $sink->get_events();
94
        $event = reset($events);
95
 
96
        $this->assertInstanceOf('\tool_langimport\event\langpack_removed', $event);
97
        $this->assertEquals(\context_system::instance(), $event->get_context());
98
    }
99
 
11 efrain 100
    public function test_langpack_removed_validation(): void {
1 efrain 101
 
102
        $this->expectException('coding_exception');
103
        $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
104
        \tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
105
    }
106
}