MDL-62384 privacy: Modify user contexts query for auth_oauth2
[moodle.git] / calendar / tests / event_test.php
blob8b28046d2b8b6a9f12ab3e265ff2bf07f3d84c9d
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 * 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\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;
34 /**
35 * 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_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 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']
64 foreach ($constructorparams as $name => $value) {
65 if ($name !== 'visible') {
66 $this->assertEquals($event->{'get_' . $name}(), $value);
70 $this->assertEquals($event->is_visible(), $constructorparams['visible']);
73 /**
74 * Test cases for getters test.
76 public function getters_testcases() {
77 $lamecallable = function($id) {
78 return (object)['id' => $id];
81 return [
82 'Dataset 1' => [
83 'constructorparams' => [
84 'id' => 1,
85 'name' => 'Test event 1',
86 'description' => new event_description('asdf', 1),
87 'category' => new coursecat_proxy(0),
88 'course' => new std_proxy(1, $lamecallable),
89 'group' => new std_proxy(1, $lamecallable),
90 'user' => new std_proxy(1, $lamecallable),
91 'repeats' => new core_calendar_event_test_event_collection(),
92 'course_module' => new std_proxy(1, $lamecallable),
93 'type' => 'dunno what this actually is meant to be',
94 'times' => new event_times(
95 (new \DateTimeImmutable())->setTimestamp(-386380800),
96 (new \DateTimeImmutable())->setTimestamp(115776000),
97 (new \DateTimeImmutable())->setTimestamp(115776000),
98 (new \DateTimeImmutable())->setTimestamp(time())
100 'visible' => true,
101 'subscription' => new std_proxy(1, $lamecallable)
109 * Test event class.
111 * @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
112 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
114 class core_calendar_event_test_event_collection implements event_collection_interface {
116 * @var array $events Array of events.
118 protected $events;
121 * Constructor.
123 public function __construct() {
124 $this->events = [
125 'not really an event hahaha',
126 'also not really. gottem.'
130 public function get_id() {
131 return 1729;
134 public function get_num() {
135 return 2;
138 public function getIterator() {
139 foreach ($this->events as $event) {
140 yield $event;