Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.
   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   */
  34  class events_test extends \advanced_testcase {
  35  
  36      /**
  37       * Setup testcase.
  38       */
  39      public function setUp(): void {
  40          $this->setAdminUser();
  41          $this->resetAfterTest();
  42      }
  43  
  44      public function test_langpack_updated() {
  45          global $CFG;
  46  
  47          $event = \tool_langimport\event\langpack_updated::event_with_langcode($CFG->lang);
  48  
  49          // Trigger and capture the event.
  50          $sink = $this->redirectEvents();
  51          $event->trigger();
  52          $events = $sink->get_events();
  53          $event = reset($events);
  54  
  55          $this->assertInstanceOf('\tool_langimport\event\langpack_updated', $event);
  56          $this->assertEquals(\context_system::instance(), $event->get_context());
  57      }
  58  
  59      public function test_langpack_updated_validation() {
  60  
  61          $this->expectException('coding_exception');
  62          $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
  63          \tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
  64      }
  65  
  66      public function test_langpack_installed() {
  67          $event = \tool_langimport\event\langpack_imported::event_with_langcode('fr');
  68  
  69          // Trigger and capture the event.
  70          $sink = $this->redirectEvents();
  71          $event->trigger();
  72          $events = $sink->get_events();
  73          $event = reset($events);
  74  
  75          $this->assertInstanceOf('\tool_langimport\event\langpack_imported', $event);
  76          $this->assertEquals(\context_system::instance(), $event->get_context());
  77      }
  78  
  79      public function test_langpack_installed_validation() {
  80  
  81          $this->expectException('coding_exception');
  82          $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
  83          \tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
  84      }
  85  
  86      public function test_langpack_removed() {
  87          $event = \tool_langimport\event\langpack_removed::event_with_langcode('fr');
  88  
  89          // Trigger and capture the event.
  90          $sink = $this->redirectEvents();
  91          $event->trigger();
  92          $events = $sink->get_events();
  93          $event = reset($events);
  94  
  95          $this->assertInstanceOf('\tool_langimport\event\langpack_removed', $event);
  96          $this->assertEquals(\context_system::instance(), $event->get_context());
  97      }
  98  
  99      public function test_langpack_removed_validation() {
 100  
 101          $this->expectException('coding_exception');
 102          $this->expectExceptionMessage("The 'langcode' value must be set to a valid language code");
 103          \tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
 104      }
 105  }