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