[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/admin/tool/langimport/tests/ -> events_test.php (source)

   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  defined('MOODLE_INTERNAL') || die();
  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 tool_langimport_events_testcase extends advanced_testcase {
  35  
  36      /**
  37       * Setup testcase.
  38       */
  39      public function setUp() {
  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          $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
  61  
  62          \tool_langimport\event\langpack_updated::event_with_langcode('broken langcode');
  63      }
  64  
  65      public function test_langpack_installed() {
  66          $event = \tool_langimport\event\langpack_imported::event_with_langcode('fr');
  67  
  68          // Trigger and capture the event.
  69          $sink = $this->redirectEvents();
  70          $event->trigger();
  71          $events = $sink->get_events();
  72          $event = reset($events);
  73  
  74          $this->assertInstanceOf('\tool_langimport\event\langpack_imported', $event);
  75          $this->assertEquals(context_system::instance(), $event->get_context());
  76      }
  77  
  78      public function test_langpack_installed_validation() {
  79          $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
  80  
  81          \tool_langimport\event\langpack_imported::event_with_langcode('broken langcode');
  82      }
  83  
  84      public function test_langpack_removed() {
  85          $event = \tool_langimport\event\langpack_removed::event_with_langcode('fr');
  86  
  87          // Trigger and capture the event.
  88          $sink = $this->redirectEvents();
  89          $event->trigger();
  90          $events = $sink->get_events();
  91          $event = reset($events);
  92  
  93          $this->assertInstanceOf('\tool_langimport\event\langpack_removed', $event);
  94          $this->assertEquals(context_system::instance(), $event->get_context());
  95      }
  96  
  97      public function test_langpack_removed_validation() {
  98          $this->setExpectedException('coding_exception', 'The \'langcode\' value must be set to a valid language code');
  99  
 100          \tool_langimport\event\langpack_removed::event_with_langcode('broken langcode');
 101      }
 102  }


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1