Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.

Differences Between: [Versions 310 and 311] [Versions 310 and 400] [Versions 310 and 401] [Versions 310 and 402] [Versions 310 and 403] [Versions 39 and 310]

   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   * 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  defined('MOODLE_INTERNAL') || die();
  26  
  27  use core_calendar\local\event\entities\event;
  28  use core_calendar\local\event\proxies\std_proxy;
  29  use core_calendar\local\event\proxies\coursecat_proxy;
  30  use core_calendar\local\event\value_objects\event_description;
  31  use core_calendar\local\event\value_objects\event_times;
  32  use core_calendar\local\event\entities\event_collection_interface;
  33  
  34  /**
  35   * Event testcase.
  36   *
  37   * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
  38   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  39   */
  40  class core_calendar_event_testcase extends advanced_testcase {
  41      /**
  42       * Test event class getters.
  43       *
  44       * @dataProvider getters_testcases()
  45       * @param array $constructorparams Associative array of constructor parameters.
  46       */
  47      public function test_getters($constructorparams) {
  48          $event = new event(
  49              $constructorparams['id'],
  50              $constructorparams['name'],
  51              $constructorparams['description'],
  52              $constructorparams['category'],
  53              $constructorparams['course'],
  54              $constructorparams['group'],
  55              $constructorparams['user'],
  56              $constructorparams['repeats'],
  57              $constructorparams['course_module'],
  58              $constructorparams['type'],
  59              $constructorparams['times'],
  60              $constructorparams['visible'],
  61              $constructorparams['subscription'],
  62              $constructorparams['location'],
  63              $constructorparams['component']
  64          );
  65  
  66          foreach ($constructorparams as $name => $value) {
  67              if ($name !== 'visible' && $name !== 'component') {
  68                  $this->assertEquals($event->{'get_' . $name}(), $value);
  69              }
  70          }
  71  
  72          $this->assertEquals($event->is_visible(), $constructorparams['visible']);
  73          $this->assertEquals('mod_' . $event->get_course_module()->get('modname'), $event->get_component());
  74      }
  75  
  76      /**
  77       * Test cases for getters test.
  78       */
  79      public function getters_testcases() {
  80          $lamecallable = function($id) {
  81              return (object)['id' => $id, 'modname' => 'assign'];
  82          };
  83  
  84          return [
  85              'Dataset 1' => [
  86                  'constructorparams' => [
  87                      'id' => 1,
  88                      'name' => 'Test event 1',
  89                      'description' => new event_description('asdf', 1),
  90                      'category' => new coursecat_proxy(0),
  91                      'course' => new std_proxy(1, $lamecallable),
  92                      'group' => new std_proxy(1, $lamecallable),
  93                      'user' => new std_proxy(1, $lamecallable),
  94                      'repeats' => new core_calendar_event_test_event_collection(),
  95                      'course_module' => new std_proxy(1, $lamecallable),
  96                      'type' => 'dunno what this actually is meant to be',
  97                      'times' => new event_times(
  98                          (new \DateTimeImmutable())->setTimestamp(-386380800),
  99                          (new \DateTimeImmutable())->setTimestamp(115776000),
 100                          (new \DateTimeImmutable())->setTimestamp(115776000),
 101                          (new \DateTimeImmutable())->setTimestamp(time()),
 102                          (new \DateTimeImmutable())->setTimestamp(115776000)
 103                      ),
 104                      'visible' => true,
 105                      'subscription' => new std_proxy(1, $lamecallable),
 106                      'location' => 'Test',
 107                      'component' => null
 108                  ]
 109              ],
 110          ];
 111      }
 112  }
 113  
 114  /**
 115   * Test event class.
 116   *
 117   * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
 118   * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 119   */
 120  class core_calendar_event_test_event_collection implements event_collection_interface {
 121      /**
 122       * @var array $events Array of events.
 123       */
 124      protected $events;
 125  
 126      /**
 127       * Constructor.
 128       */
 129      public function __construct() {
 130          $this->events = [
 131              'not really an event hahaha',
 132              'also not really. gottem.'
 133          ];
 134      }
 135  
 136      public function get_id() {
 137          return 1729;
 138      }
 139  
 140      public function get_num() {
 141          return 2;
 142      }
 143  
 144      public function getIterator() {
 145          foreach ($this->events as $event) {
 146              yield $event;
 147          }
 148      }
 149  }