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 310 and 401] [Versions 311 and 401] [Versions 39 and 401] [Versions 400 and 401]

   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   * Action event tests.
  19   *
  20   * @package    core_calendar
  21   * @copyright  2017 Cameron Ball <cameron@cameron1729.xyz>
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace core_calendar;
  26  
  27  use core_calendar\local\event\entities\action_event;
  28  use core_calendar\local\event\value_objects\action;
  29  use core_calendar\local\event\value_objects\event_description;
  30  use core_calendar\local\event\value_objects\event_times;
  31  use core_calendar\local\event\entities\event_collection_interface;
  32  use core_calendar\local\event\entities\event_interface;
  33  
  34  defined('MOODLE_INTERNAL') || die;
  35  
  36  /**
  37   * Action event testcase.
  38   *
  39   * @package core_calendar
  40   * @category test
  41   * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
  42   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  43   */
  44  class action_event_test extends \advanced_testcase {
  45      /**
  46       * Test event class getters.
  47       *
  48       * @dataProvider getters_testcases()
  49       * @param array $constructorparams Associative array of constructor parameters.
  50       */
  51      public function test_getters($constructorparams) {
  52          $event = new action_event(
  53              $constructorparams['event'],
  54              $constructorparams['action']
  55          );
  56  
  57          foreach ($constructorparams as $name => $value) {
  58              if ($name !== 'event') {
  59                  $this->assertEquals($event->{'get_' . $name}(), $value);
  60              }
  61          }
  62      }
  63  
  64      /**
  65       * Test cases for getters test.
  66       */
  67      public function getters_testcases() {
  68          return [
  69              'Dataset 1' => [
  70                  'constructorparams' => [
  71                      'event' => new core_calendar_action_event_test_event(),
  72                      'action' => new action(
  73                          'action 1',
  74                          new \moodle_url('http://example.com'),
  75                          2,
  76                          true
  77                      )
  78                  ]
  79              ],
  80              'Dataset 2' => [
  81                  'constructorparams' => [
  82                      'event' => new core_calendar_action_event_test_event(),
  83                      'action' => new action(
  84                          'action 2',
  85                          new \moodle_url('http://example.com'),
  86                          5,
  87                          false
  88                      )
  89                  ]
  90              ],
  91          ];
  92      }
  93  }
  94  
  95  /**
  96   * Test event.
  97   *
  98   * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
  99   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 100   */
 101  class core_calendar_action_event_test_event implements event_interface {
 102  
 103      public function get_id() {
 104          return 1729;
 105      }
 106  
 107      public function get_name() {
 108          return 'Jeff';
 109      }
 110  
 111      public function get_description() {
 112          return new event_description('asdf', 1);
 113      }
 114  
 115      public function get_location() {
 116          return 'Cube office';
 117      }
 118  
 119      public function get_category() {
 120          return new \stdClass();
 121      }
 122  
 123      public function get_course() {
 124          return new \stdClass();
 125      }
 126  
 127      public function get_course_module() {
 128          return new \stdClass();
 129      }
 130  
 131      public function get_group() {
 132          return new \stdClass();
 133      }
 134  
 135      public function get_user() {
 136          return new \stdClass();
 137      }
 138  
 139      public function get_type() {
 140          return 'asdf';
 141      }
 142  
 143      public function get_times() {
 144          return new event_times(
 145              (new \DateTimeImmutable())->setTimestamp(-386380800),
 146              (new \DateTimeImmutable())->setTimestamp(115776000),
 147              (new \DateTimeImmutable())->setTimestamp(115776000),
 148              (new \DateTimeImmutable())->setTimestamp(time())
 149          );
 150      }
 151  
 152      public function get_repeats() {
 153          return new core_calendar_action_event_test_event_collection();
 154      }
 155  
 156      public function get_subscription() {
 157          return new \stdClass();
 158      }
 159  
 160      public function is_visible() {
 161          return true;
 162      }
 163  
 164      /**
 165       * Component
 166       * @return string|null
 167       */
 168      public function get_component() {
 169          return null;
 170      }
 171  }
 172  
 173  /**
 174   * Test event collection.
 175   *
 176   * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
 177   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 178   */
 179  class core_calendar_action_event_test_event_collection implements event_collection_interface {
 180      /**
 181       * @var array
 182       */
 183      protected $events;
 184  
 185      /**
 186       * core_calendar_action_event_test_event_collection constructor.
 187       */
 188      public function __construct() {
 189          $this->events = [
 190              'not really an event hahaha',
 191              'also not really. gottem.'
 192          ];
 193      }
 194  
 195      public function get_id() {
 196          return 1729;
 197      }
 198  
 199      public function get_num() {
 200          return 2;
 201      }
 202  
 203      public function getIterator(): \Traversable {
 204          foreach ($this->events as $event) {
 205              yield $event;
 206          }
 207      }
 208  }