2017-02-06 04:08:47 +08:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action event tests.
|
|
|
|
*
|
|
|
|
* @package core_calendar
|
|
|
|
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
2022-03-29 20:24:23 +02:00
|
|
|
namespace core_calendar;
|
2017-02-06 04:08:47 +08:00
|
|
|
|
|
|
|
use core_calendar\local\event\entities\action_event;
|
|
|
|
use core_calendar\local\event\value_objects\action;
|
|
|
|
use core_calendar\local\event\value_objects\event_description;
|
|
|
|
use core_calendar\local\event\value_objects\event_times;
|
2017-03-30 15:33:13 +08:00
|
|
|
use core_calendar\local\event\entities\event_collection_interface;
|
|
|
|
use core_calendar\local\event\entities\event_interface;
|
2017-02-06 04:08:47 +08:00
|
|
|
|
2022-03-29 20:24:23 +02:00
|
|
|
defined('MOODLE_INTERNAL') || die;
|
|
|
|
|
2017-02-06 04:08:47 +08:00
|
|
|
/**
|
|
|
|
* Action event testcase.
|
|
|
|
*
|
2022-03-29 20:24:23 +02:00
|
|
|
* @package core_calendar
|
|
|
|
* @category test
|
2017-02-06 04:08:47 +08:00
|
|
|
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
2024-10-15 07:45:57 +08:00
|
|
|
final class action_event_test extends \advanced_testcase {
|
2017-02-06 04:08:47 +08:00
|
|
|
/**
|
|
|
|
* Test event class getters.
|
|
|
|
*
|
2024-04-13 14:40:07 +08:00
|
|
|
* @dataProvider getters_testcases
|
2017-02-06 04:08:47 +08:00
|
|
|
* @param array $constructorparams Associative array of constructor parameters.
|
|
|
|
*/
|
2024-05-30 09:37:38 +02:00
|
|
|
public function test_getters($constructorparams): void {
|
2017-02-06 04:08:47 +08:00
|
|
|
$event = new action_event(
|
|
|
|
$constructorparams['event'],
|
|
|
|
$constructorparams['action']
|
|
|
|
);
|
|
|
|
|
|
|
|
foreach ($constructorparams as $name => $value) {
|
|
|
|
if ($name !== 'event') {
|
|
|
|
$this->assertEquals($event->{'get_' . $name}(), $value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test cases for getters test.
|
|
|
|
*/
|
2024-04-13 14:40:07 +08:00
|
|
|
public static function getters_testcases(): array {
|
2017-02-06 04:08:47 +08:00
|
|
|
return [
|
|
|
|
'Dataset 1' => [
|
|
|
|
'constructorparams' => [
|
|
|
|
'event' => new core_calendar_action_event_test_event(),
|
|
|
|
'action' => new action(
|
|
|
|
'action 1',
|
2022-03-29 20:24:23 +02:00
|
|
|
new \moodle_url('http://example.com'),
|
2017-02-17 12:48:28 +08:00
|
|
|
2,
|
|
|
|
true
|
2017-02-06 04:08:47 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
'Dataset 2' => [
|
|
|
|
'constructorparams' => [
|
|
|
|
'event' => new core_calendar_action_event_test_event(),
|
|
|
|
'action' => new action(
|
|
|
|
'action 2',
|
2022-03-29 20:24:23 +02:00
|
|
|
new \moodle_url('http://example.com'),
|
2017-02-17 12:48:28 +08:00
|
|
|
5,
|
|
|
|
false
|
2017-02-06 04:08:47 +08:00
|
|
|
)
|
|
|
|
]
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test event.
|
|
|
|
*
|
|
|
|
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
class core_calendar_action_event_test_event implements event_interface {
|
2017-03-24 16:58:54 +08:00
|
|
|
|
2017-02-06 04:08:47 +08:00
|
|
|
public function get_id() {
|
|
|
|
return 1729;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_name() {
|
|
|
|
return 'Jeff';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_description() {
|
|
|
|
return new event_description('asdf', 1);
|
|
|
|
}
|
|
|
|
|
2018-05-24 09:44:54 +08:00
|
|
|
public function get_location() {
|
|
|
|
return 'Cube office';
|
|
|
|
}
|
|
|
|
|
2017-09-19 11:39:39 +08:00
|
|
|
public function get_category() {
|
|
|
|
return new \stdClass();
|
|
|
|
}
|
|
|
|
|
2017-02-06 04:08:47 +08:00
|
|
|
public function get_course() {
|
|
|
|
return new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_course_module() {
|
|
|
|
return new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_group() {
|
|
|
|
return new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_user() {
|
|
|
|
return new \stdClass();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_type() {
|
|
|
|
return 'asdf';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_times() {
|
|
|
|
return new event_times(
|
2017-04-25 20:21:48 +02:00
|
|
|
(new \DateTimeImmutable())->setTimestamp(-386380800),
|
|
|
|
(new \DateTimeImmutable())->setTimestamp(115776000),
|
|
|
|
(new \DateTimeImmutable())->setTimestamp(115776000),
|
2017-02-06 04:08:47 +08:00
|
|
|
(new \DateTimeImmutable())->setTimestamp(time())
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_repeats() {
|
|
|
|
return new core_calendar_action_event_test_event_collection();
|
|
|
|
}
|
|
|
|
|
2017-02-15 03:15:06 +08:00
|
|
|
public function get_subscription() {
|
|
|
|
return new \stdClass();
|
2017-02-06 04:08:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function is_visible() {
|
|
|
|
return true;
|
|
|
|
}
|
2020-04-29 22:22:10 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function get_component() {
|
|
|
|
return null;
|
|
|
|
}
|
2017-02-06 04:08:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test event collection.
|
|
|
|
*
|
|
|
|
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
class core_calendar_action_event_test_event_collection implements event_collection_interface {
|
2017-03-24 16:58:54 +08:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-02-06 04:08:47 +08:00
|
|
|
protected $events;
|
|
|
|
|
2017-03-24 16:58:54 +08:00
|
|
|
/**
|
|
|
|
* core_calendar_action_event_test_event_collection constructor.
|
|
|
|
*/
|
2017-02-06 04:08:47 +08:00
|
|
|
public function __construct() {
|
|
|
|
$this->events = [
|
|
|
|
'not really an event hahaha',
|
|
|
|
'also not really. gottem.'
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_id() {
|
|
|
|
return 1729;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get_num() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
2021-12-21 10:39:00 +01:00
|
|
|
public function getIterator(): \Traversable {
|
2017-02-06 04:08:47 +08:00
|
|
|
foreach ($this->events as $event) {
|
|
|
|
yield $event;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|