MDL-61135 mod_quiz: remove YUI question bank dialogue
[moodle.git] / calendar / tests / action_event_test.php
blobacb864331a2a32cc190f51419334d01ddb0f7a1f
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.
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 /**
18 * Action event tests.
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
25 defined('MOODLE_INTERNAL') || die();
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;
34 /**
35 * Action event testcase.
37 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class core_calendar_action_event_testcase extends advanced_testcase {
41 /**
42 * Test event class getters.
44 * @dataProvider getters_testcases()
45 * @param array $constructorparams Associative array of constructor parameters.
47 public function test_getters($constructorparams) {
48 $event = new action_event(
49 $constructorparams['event'],
50 $constructorparams['action']
53 foreach ($constructorparams as $name => $value) {
54 if ($name !== 'event') {
55 $this->assertEquals($event->{'get_' . $name}(), $value);
60 /**
61 * Test cases for getters test.
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'),
72 true
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'),
83 false
91 /**
92 * Test event.
94 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
95 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
97 class core_calendar_action_event_test_event implements event_interface {
99 public function get_id() {
100 return 1729;
103 public function get_name() {
104 return 'Jeff';
107 public function get_description() {
108 return new event_description('asdf', 1);
111 public function get_category() {
112 return new \stdClass();
115 public function get_course() {
116 return new \stdClass();
119 public function get_course_module() {
120 return new \stdClass();
123 public function get_group() {
124 return new \stdClass();
127 public function get_user() {
128 return new \stdClass();
131 public function get_type() {
132 return 'asdf';
135 public function get_times() {
136 return new event_times(
137 (new \DateTimeImmutable())->setTimestamp(-386380800),
138 (new \DateTimeImmutable())->setTimestamp(115776000),
139 (new \DateTimeImmutable())->setTimestamp(115776000),
140 (new \DateTimeImmutable())->setTimestamp(time())
144 public function get_repeats() {
145 return new core_calendar_action_event_test_event_collection();
148 public function get_subscription() {
149 return new \stdClass();
152 public function is_visible() {
153 return true;
158 * Test event collection.
160 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
161 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
163 class core_calendar_action_event_test_event_collection implements event_collection_interface {
165 * @var array
167 protected $events;
170 * core_calendar_action_event_test_event_collection constructor.
172 public function __construct() {
173 $this->events = [
174 'not really an event hahaha',
175 'also not really. gottem.'
179 public function get_id() {
180 return 1729;
183 public function get_num() {
184 return 2;
187 public function getIterator() {
188 foreach ($this->events as $event) {
189 yield $event;