Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 and 402] [Versions 401 and 403]

   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 base course module instance list viewed event.
  19   *
  20   * @package    core
  21   * @category   phpunit
  22   * @copyright  2013 Ankit Agarwal
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  require_once (__DIR__.'/fixtures/event_mod_fixtures.php');
  28  
  29  /**
  30   * Class core_event_course_module_instance_list_viewed_testcase
  31   *
  32   * Tests for event \core\event\course_module_instance_list_viewed_testcase
  33   */
  34  class core_event_course_module_instance_list_viewed_testcase extends advanced_testcase {
  35  
  36      /**
  37       * Test event properties and methods.
  38       */
  39      public function test_event_attributes() {
  40  
  41          $this->resetAfterTest();
  42          $course = $this->getDataGenerator()->create_course();
  43          $context = context_course::instance($course->id);
  44  
  45          // Trigger the page view event.
  46          $sink = $this->redirectEvents();
  47          $event = \mod_unittests\event\course_module_instance_list_viewed::create(array(
  48               'context' => $context,
  49          ));
  50          $event->trigger();
  51          $result = $sink->get_events();
  52          $event = reset($result);
  53          $sink->close();
  54  
  55          // Test event data.
  56          $legacydata = array($course->id, 'unittests', 'view all', 'index.php?id=' . $course->id, '');
  57          $this->assertEventLegacyLogData($legacydata, $event);
  58          $url = new moodle_url('/mod/unittests/index.php', array('id' => $course->id));
  59          $this->assertEquals($url, $event->get_url());
  60          $this->assertEventContextNotUsed($event);
  61  
  62      }
  63  
  64      /**
  65       * Test custom validations of the event.
  66       */
  67      public function test_event_validations() {
  68          try {
  69              \mod_unittests\event\course_module_instance_list_viewed::create(array('context' => context_system::instance()));
  70              $this->fail('Event validation should not allow course_module_instance_list_viewed event to be triggered without outside
  71                      course context');
  72          } catch (Exception $e) {
  73              $this->assertInstanceOf('coding_exception', $e);
  74          }
  75      }
  76  }