2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Tests for langimport events.
20 * @package tool_langimport
21 * @copyright 2014 Dan Poltawski
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
25 defined('MOODLE_INTERNAL') || die();
28 * Test class for langimport events.
30 * @package tool_langimport
31 * @copyright 2014 Dan Poltawski
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later.
34 class tool_langimport_events_testcase extends advanced_testcase {
39 public function setUp() {
40 $this->setAdminUser();
41 $this->resetAfterTest();
44 public function test_langpack_updated() {
47 $event = \tool_langimport\event\langpack_updated::event_with_langcode($CFG->lang);
49 // Trigger and capture the event.
50 $sink = $this->redirectEvents();
52 $events = $sink->get_events();
53 $event = reset($events);
55 $this->assertInstanceOf('\tool_langimport\event\langpack_updated', $event);
56 $this->assertEquals(context_system::instance(), $event->get_context());
59 public function test_langpack_updated_validation() {
60 $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
62 \tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
65 public function test_langpack_installed() {
66 $event = \tool_langimport\event\langpack_imported::event_with_langcode('fr');
68 // Trigger and capture the event.
69 $sink = $this->redirectEvents();
71 $events = $sink->get_events();
72 $event = reset($events);
74 $this->assertInstanceOf('\tool_langimport\event\langpack_imported', $event);
75 $this->assertEquals(context_system::instance(), $event->get_context());
78 public function test_langpack_installed_validation() {
79 $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
81 \tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
84 public function test_langpack_removed() {
85 $event = \tool_langimport\event\langpack_removed::event_with_langcode('fr');
87 // Trigger and capture the event.
88 $sink = $this->redirectEvents();
90 $events = $sink->get_events();
91 $event = reset($events);
93 $this->assertInstanceOf('\tool_langimport\event\langpack_removed', $event);
94 $this->assertEquals(context_system::instance(), $event->get_context());
97 public function test_langpack_removed_validation() {
98 $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
100 \tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');