2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 namespace core_calendar
;
19 use core_calendar\local\event\entities\event
;
20 use core_calendar\local\event\proxies\std_proxy
;
21 use core_calendar\local\event\proxies\coursecat_proxy
;
22 use core_calendar\local\event\value_objects\event_description
;
23 use core_calendar\local\event\value_objects\event_times
;
24 use core_calendar\local\event\entities\event_collection_interface
;
26 defined('MOODLE_INTERNAL') ||
die();
29 * Calendar event tests..
31 * @package core_calendar
32 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class event_test
extends \advanced_testcase
{
37 * Test event class getters.
39 * @dataProvider getters_testcases()
40 * @param array $constructorparams Associative array of constructor parameters.
42 public function test_getters($constructorparams): void
{
44 $constructorparams['id'],
45 $constructorparams['name'],
46 $constructorparams['description'],
47 $constructorparams['category'],
48 $constructorparams['course'],
49 $constructorparams['group'],
50 $constructorparams['user'],
51 $constructorparams['repeats'],
52 $constructorparams['course_module'],
53 $constructorparams['type'],
54 $constructorparams['times'],
55 $constructorparams['visible'],
56 $constructorparams['subscription'],
57 $constructorparams['location'],
58 $constructorparams['component']
61 foreach ($constructorparams as $name => $value) {
62 if ($name !== 'visible' && $name !== 'component') {
63 $this->assertEquals($event->{'get_' . $name}(), $value);
67 $this->assertEquals($event->is_visible(), $constructorparams['visible']);
68 $this->assertEquals('mod_' . $event->get_course_module()->get('modname'), $event->get_component());
72 * Test cases for getters test.
74 public function getters_testcases() {
75 $lamecallable = function($id) {
76 return (object)['id' => $id, 'modname' => 'assign'];
81 'constructorparams' => [
83 'name' => 'Test event 1',
84 'description' => new event_description('asdf', 1),
85 'category' => new coursecat_proxy(0),
86 'course' => new std_proxy(1, $lamecallable),
87 'group' => new std_proxy(1, $lamecallable),
88 'user' => new std_proxy(1, $lamecallable),
89 'repeats' => new core_calendar_event_test_event_collection(),
90 'course_module' => new std_proxy(1, $lamecallable),
91 'type' => 'dunno what this actually is meant to be',
92 'times' => new event_times(
93 (new \
DateTimeImmutable())->setTimestamp(-386380800),
94 (new \
DateTimeImmutable())->setTimestamp(115776000),
95 (new \
DateTimeImmutable())->setTimestamp(115776000),
96 (new \
DateTimeImmutable())->setTimestamp(time()),
97 (new \
DateTimeImmutable())->setTimestamp(115776000)
100 'subscription' => new std_proxy(1, $lamecallable),
101 'location' => 'Test',
112 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
113 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
115 class core_calendar_event_test_event_collection
implements event_collection_interface
{
117 * @var array $events Array of events.
124 public function __construct() {
126 'not really an event hahaha',
127 'also not really. gottem.'
131 public function get_id() {
135 public function get_num() {
139 public function getIterator(): \Traversable
{
140 foreach ($this->events
as $event) {