MDL-58386 calendar: Fixed CI issues

Part of MDL-55611 epic.
This commit is contained in:
Jun Pataleta
2017-04-04 11:01:47 +01:00
committed by Dan Poltawski
parent 966cbed632
commit 20592f5ff2
34 changed files with 222 additions and 175 deletions
+1
View File
@@ -36,6 +36,7 @@ use core_calendar\local\event\value_objects\action;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_factory implements action_factory_interface {
public function create_instance($name, \moodle_url $url, $itemcount, $actionable) {
return new action ($name, $url, $itemcount, $actionable);
}
+2 -1
View File
@@ -43,7 +43,8 @@ class event_action_exporter extends exporter {
/**
* Constructor.
*
* @param action_interface $action
* @param action_interface $action The action object.
* @param array $related Related data.
*/
public function __construct(action_interface $action, $related = []) {
$data = new \stdClass();
+1
View File
@@ -50,6 +50,7 @@ class event_exporter extends exporter {
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$this->event = $event;
+1
View File
@@ -42,6 +42,7 @@ class event_icon_exporter extends exporter {
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$coursemodule = $event->get_course_module();
@@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying a list of calendar events grouped
* by course id.
* Contains event class for displaying a list of calendar events grouped by course id.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <[email protected]>
@@ -52,7 +51,7 @@ class events_grouped_by_course_exporter extends exporter {
/**
* Constructor.
*
* @param array $events An array of event_interface objects
* @param array $eventsbycourse An array of event_interface objects
* @param array $related An array of related objects
*/
public function __construct(array $eventsbycourse, $related = []) {
+9 -9
View File
@@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for providing the related objects when exporting
* a list of calendar events.
* Contains event class for providing the related objects when exporting a list of calendar events.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <[email protected]>
@@ -27,11 +26,12 @@ namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use context;
use \core_calendar\local\interfaces\event_interface;
use stdClass;
/**
* Class to providing the related objects when exporting
* a list of calendar events.
* Class to providing the related objects when exporting a list of calendar events.
*
* This class is only meant for use with exporters. It attempts to bulk load
* the related objects for a list of events and cache them to avoid having
@@ -66,7 +66,7 @@ class events_related_objects_cache {
/**
* Constructor.
*
* @param array $event Array of event_interface events
* @param array $events Array of event_interface events
* @param array $courses Array of courses to populate the cache with
*/
public function __construct(array $events, array $courses = null) {
@@ -84,7 +84,7 @@ class events_related_objects_cache {
/**
* Get the related course object for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_course(event_interface $event) {
@@ -103,7 +103,7 @@ class events_related_objects_cache {
/**
* Get the related context for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return context|null
*/
public function get_context(event_interface $event) {
@@ -132,7 +132,7 @@ class events_related_objects_cache {
/**
* Get the related group object for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_group(event_interface $event) {
@@ -151,7 +151,7 @@ class events_related_objects_cache {
/**
* Get the related course module for a given event.
*
* @param event_interface $event.
* @param event_interface $event The event object.
* @return stdClass|null
*/
public function get_course_module(event_interface $event) {
+1 -2
View File
@@ -15,8 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying a list of calendar events for
* a single course.
* Contains event class for displaying a list of calendar events for a single course.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <[email protected]>
+16 -16
View File
@@ -39,22 +39,20 @@ class api {
/**
* Get all events restricted by various parameters, taking in to account user and group overrides.
*
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param int|null $timestartaftereventid Restrict the events in the timestart range to ones
after this ID.
* @param int $timesortaftereventid Restrict the events in the timesort range to ones
after this ID.
* @param int $limitnum Return at most this number of events.
* @param int $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param int|null $timestartaftereventid Restrict the events in the timestart range to ones after this ID.
* @param int|null $timesortaftereventid Restrict the events in the timesort range to ones after this ID.
* @param int $limitnum Return at most this number of events.
* @param int|null $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @return \core_calendar\local\interfaces\event_interface[] Array of event_interfaces.
*/
public static function get_events(
@@ -113,6 +111,7 @@ class api {
* @param int|null $aftereventid Only return events after this one
* @param int $limitnum Limit results to this amount (between 1 and 50)
* @return array A list of action_event_interface objects
* @throws \moodle_exception
*/
public static function get_action_events_by_timesort(
$timesortfrom = null,
@@ -150,6 +149,7 @@ class api {
* @param int|null $aftereventid Only return events after this one
* @param int $limitnum Limit results to this amount (between 1 and 50)
* @return array A list of action_event_interface objects
* @throws limit_invalid_parameter_exception
*/
public static function get_action_events_by_course(
$course,
@@ -82,12 +82,12 @@ class core_container {
protected static $callbacks = array();
/**
* @var stdClass[] An array of cached courses to use with the event factory.
* @var \stdClass[] An array of cached courses to use with the event factory.
*/
protected static $coursecache = array();
/**
* @var stdClass[] An array of cached modules to use with the event factory.
* @var \stdClass[] An array of cached modules to use with the event factory.
*/
protected static $modulecache = array();
@@ -24,8 +24,9 @@
namespace core_calendar\local\event\data_access;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\event\exceptions\limit_invalid_parameter_exception;
use core_calendar\local\event\exceptions\timesort_invalid_parameter_exception;
use core_calendar\local\interfaces\action_event_interface;
use core_calendar\local\interfaces\event_factory_interface;
use core_calendar\local\interfaces\event_interface;
@@ -33,6 +34,8 @@ use core_calendar\local\interfaces\event_vault_interface;
use core_calendar\local\interfaces\raw_event_retrieval_strategy_interface;
/**
* Event vault class.
*
* This class will handle interacting with the database layer to retrieve
* the records. This is required to house the complex logic required for
* pagination because it's not a one-to-one mapping between database records
@@ -60,6 +63,7 @@ class event_vault implements event_vault_interface {
* Create an event vault.
*
* @param event_factory_interface $factory An event factory
* @param raw_event_retrieval_strategy_interface $retrievalstrategy
*/
public function __construct(
event_factory_interface $factory,
@@ -245,6 +249,16 @@ class event_vault implements event_vault_interface {
);
}
/**
* Generates SQL subquery and parameters for 'from' pagination.
*
* @param string $field
* @param int $timefrom
* @param int|null $lastseentime
* @param int|null $lastseenid
* @param bool $withduration
* @return array
*/
protected function timefield_pagination_from(
$field,
$timefrom,
@@ -279,6 +293,15 @@ class event_vault implements event_vault_interface {
return ['where' => [$where], 'params' => $params];
}
/**
* Generates SQL subquery and parameters for 'to' pagination.
*
* @param string $field
* @param int $timeto
* @param int|null $lastseentime
* @param int|null $lastseenid
* @return array|bool
*/
protected function timefield_pagination_to(
$field,
$timeto,
@@ -313,17 +336,28 @@ class event_vault implements event_vault_interface {
* Create an event from a database record.
*
* @param \stdClass $record The database record
* @return event_interface|false
* @return event_interface|null
*/
protected function transform_from_database_record(\stdClass $record) {
if ($record->courseid == 0 && $record->instance && $record->modulename) {
list($course, $cm) = get_course_and_cm_from_instance($record->instance, $record->modulename);
$record->courseid = $course->id;
}
if ($record->courseid == 0 && $record->instance && $record->modulename) {
list($course, $cm) = get_course_and_cm_from_instance($record->instance, $record->modulename);
$record->courseid = $course->id;
}
return $this->factory->create_instance($record);
}
/**
* Fetches records from DB.
*
* @param int $userid
* @param string $whereconditions
* @param array $whereparams
* @param string $ordersql
* @param int $offset
* @param int $limitnum
* @return array
*/
protected function get_from_db(
$userid,
$whereconditions,
@@ -39,7 +39,7 @@ use core_calendar\local\event\exceptions\no_repeat_parent_exception;
*/
class repeat_event_collection implements event_collection_interface {
/**
* @var DB_QUERY_LIMIT How many records to pull from the DB at once.
* @var int DB_QUERY_LIMIT How many records to pull from the DB at once.
*/
const DB_QUERY_LIMIT = 100;
@@ -38,10 +38,8 @@ use core_calendar\local\interfaces\event_interface;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_event_factory implements action_event_factory_interface {
public function create_instance(
event_interface $event,
action_interface $action
) {
public function create_instance(event_interface $event, action_interface $action) {
return new action_event($event, $action);
}
}
@@ -92,6 +92,7 @@ abstract class event_abstract_factory implements event_factory_interface {
* @param callable $visibilitycallbackapplier Function to apply component visibility callbacks.
* @param callable $bailoutcheck Function to test if we can return null early.
* @param array $coursecachereference Cache to use with get_course_cached.
* @param array $modulecachereference Cache to use with get_module_cached.
*/
public function __construct(
callable $actioncallbackapplier,
@@ -37,6 +37,7 @@ use core_calendar\local\interfaces\event_interface;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_factory extends event_abstract_factory {
protected function apply_component_action(event_interface $event) {
$callbackapplier = $this->actioncallbackapplier;
$callbackresult = $callbackapplier($event);
@@ -27,7 +27,6 @@ namespace core_calendar\local\event\proxies;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\interfaces\proxy_interface;
use core_calendar\local\event\exceptions\member_does_not_exist_exception;
/**
* Course module stdClass proxy.
@@ -42,6 +41,15 @@ use core_calendar\local\event\exceptions\member_does_not_exist_exception;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class module_std_proxy extends std_proxy implements proxy_interface {
/**
* module_std_proxy constructor.
*
* @param int $modulename The module name.
* @param callable $instance The module instance.
* @param callable $callback Callback to load the class.
* @param \stdClass $base Class containing base values.
*/
public function __construct($modulename, $instance, callable $callback, \stdClass $base = null) {
$this->modulename = $modulename;
$this->instance = $instance;
@@ -37,6 +37,7 @@ use core_calendar\local\interfaces\raw_event_retrieval_strategy_interface;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_interface {
public function get_raw_events(
array $usersfilter = null,
array $groupsfilter = null,
@@ -49,7 +50,7 @@ class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_inter
$ignorehidden = true
) {
return $this->get_raw_events_legacy_implementation(
!is_null($usersfilter) ? $usersfilter : true, //true means no filter in old implementation
!is_null($usersfilter) ? $usersfilter : true, // True means no filter in old implementation.
!is_null($groupsfilter) ? $groupsfilter : true,
!is_null($coursesfilter) ? $coursesfilter : true,
$whereconditions,
@@ -67,10 +68,14 @@ class raw_event_retrieval_strategy implements raw_event_retrieval_strategy_inter
* @param array|int|boolean $users array of users, user id or boolean for all/no user events
* @param array|int|boolean $groups array of groups, group id or boolean for all/no group events
* @param array|int|boolean $courses array of courses, course id or boolean for all/no course events
* @param boolean $withduration whether only events starting within time range selected
* or events in progress/already started selected as well
* @param string $whereconditions The conditions in the WHERE clause.
* @param array $whereparams The parameters for the WHERE clause.
* @param string $ordersql The ORDER BY clause.
* @param int $offset Offset.
* @param int $limitnum Limit.
* @param boolean $ignorehidden whether to select only visible events or all events
* @return array $events of selected events or an empty array if there aren't any (or there was an error) */
* @return array $events of selected events or an empty array if there aren't any (or there was an error)
*/
protected function get_raw_events_legacy_implementation(
$users,
$groups,
@@ -48,7 +48,7 @@ class event_description implements description_interface {
/**
* Constructor.
*
* @param stirng $value The description's value.
* @param string $value The description's value.
* @param int $format The description's format.
*/
public function __construct($value, $format) {
@@ -26,8 +26,6 @@ namespace core_calendar\local\interfaces;
defined('MOODLE_INTERNAL') || die();
use core_calendar\local\interfaces\event_interface;
/**
* Interface for an action event class.
*
@@ -38,7 +36,7 @@ interface action_event_interface extends event_interface {
/**
* Get the action event's action.
*
* @return \core_calendar\local\event\value_objects\action_interface
* @return action_interface
*/
public function get_action();
}
@@ -50,35 +50,35 @@ interface event_interface {
/**
* Get the event's description.
*
* @return \core_calendar\local\event\value_objects\description_interface
* @return description_interface
*/
public function get_description();
/**
* Get the course object associated with the event.
*
* @return \core_calendar\local\event\proxies\proxy_interface
* @return proxy_interface
*/
public function get_course();
/**
* Get the course module object that created the event.
*
* @return \core_calendar\local\event\proxies\proxy_interface
* @return proxy_interface
*/
public function get_course_module();
/**
* Get the group object associated with the event.
*
* @return \core_calendar\local\event\value_objects\proxy_interface
* @return proxy_interface
*/
public function get_group();
/**
* Get the user object associated with the event.
*
* @return \core_calendar\local\event\proxies\proxy_interface
* @return proxy_interface
*/
public function get_user();
@@ -92,21 +92,21 @@ interface event_interface {
/**
* Get the times associated with the event.
*
* @return \core_calendar\local\event\value_objects\times_interface
* @return times_interface
*/
public function get_times();
/**
* Get repeats of this event.
*
* @return \core_calendar\local\event\entities\event_collection_interface
* @return event_collection_interface
*/
public function get_repeats();
/**
* Get the event's subscritpion.
* Get the event's subscription.
*
* @return \core_calendar\local\event\proxies\proxy_interface
* @return proxy_interface
*/
public function get_subscription();
@@ -27,7 +27,6 @@ namespace core_calendar\local\interfaces;
defined('MOODLE_INTERNAL') || die();
use core_calendar\event;
use core_calendar\local\interfaces\event_interface;
/**
* Interface for an event mapper class
@@ -24,6 +24,8 @@
namespace core_calendar\local\interfaces;
defined('MOODLE_INTERNAL') || die();
/**
* Interface for an event vault class
*
@@ -42,26 +44,23 @@ interface event_vault_interface {
/**
* Get all events restricted by various parameters, taking in to account user and group overrides.
*
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param event_interface|null $timestartafterevent Restrict the events in the timestart range to ones
after this one.
* @param event_interface|null $timesortafterevent Restrict the events in the timesort range to ones
after this one.
* @param int $limitnum Return at most this number of events.
* @param int $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @param callable $filter Additional logic to filter out unwanted events.
* Must return true to keep the event, false to discard
* it.
* @return \core_calendar\local\interfaces\event_interface[] Array of event_interfaces.
* @param int|null $timestartfrom Events with timestart from this value (inclusive).
* @param int|null $timestartto Events with timestart until this value (inclusive).
* @param int|null $timesortfrom Events with timesort from this value (inclusive).
* @param int|null $timesortto Events with timesort until this value (inclusive).
* @param event_interface|null $timestartafterevent Restrict the events in the timestart range to ones after this one.
* @param event_interface|null $timesortafterevent Restrict the events in the timesort range to ones after this one.
* @param int $limitnum Return at most this number of events.
* @param int|null $type Return only events of this type.
* @param array|null $usersfilter Return only events for these users.
* @param array|null $groupsfilter Return only events for these groups.
* @param array|null $coursesfilter Return only events for these courses.
* @param bool $withduration If true return only events starting within specified
* timestart otherwise return in progress events as well.
* @param bool $ignorehidden If true don't return hidden events.
* @param callable|null $filter Additional logic to filter out unwanted events.
* Must return true to keep the event, false to discard it.
* @return event_interface[] Array of event_interfaces.
*/
public function get_events(
$timestartfrom = null,
@@ -108,12 +107,12 @@ interface event_vault_interface {
* ($afterevent) and it will be used to appropriately offset the result set so that you don't
* receive the same events again.
*
* @param \stdClass $user The user for whom the events belong
* @param \stdClass $course The course to filter by
* @param int|null $timesortfrom Events with timesort from this value (inclusive)
* @param int|null $timesortto Events with timesort until this value (inclusive)
* @param event_interface|null $afterevent Only return events after this one
* @param int $limitnum Return at most this number of events
* @param \stdClass $user The user for whom the events belong
* @param \stdClass $course The course to filter by
* @param int $timesortfrom Events with timesort from this value (inclusive)
* @param int $timesortto Events with timesort until this value (inclusive)
* @param event_interface $afterevent Only return events after this one
* @param int $limitnum Return at most this number of events
* @return action_event_interface
*/
public function get_action_events_by_course(
@@ -15,9 +15,9 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* core_calendar
* Raw event strategy retrieval interface.
*
* @package Raw event strategy retrieval interface.
* @package core_calendar
* @copyright 2017 Cameron Ball <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
@@ -36,15 +36,15 @@ interface raw_event_retrieval_strategy_interface {
/**
* Retrieve raw calendar event records from the DB.
*
* @param array|null $usersfilter Array of users to retrieve events for.
* @param array|null $groupsfilter Array of groups to retrieve events for.
* @param array|null $coursesfilter Array of courses to retrieve events for.
* @param array|null $whereconditions Array of where conditions to restrict results.
* @param array|null $whereparams Array of parameters for $whereconditions.
* @param string $ordersql SQL to order results.
* @param int $offset Amount to offset results by.
* @param int $limitnum Return at most this many results.
* @param bool $ignorehidden True to ignore hidden events. False to include them.
* @param array|null $usersfilter Array of users to retrieve events for.
* @param array|null $groupsfilter Array of groups to retrieve events for.
* @param array|null $coursesfilter Array of courses to retrieve events for.
* @param array|null $whereconditions Array of where conditions to restrict results.
* @param array|null $whereparams Array of parameters for $whereconditions.
* @param string|null $ordersql SQL to order results.
* @param int|null $offset Amount to offset results by.
* @param int $limitnum Return at most this many results.
* @param bool $ignorehidden True to ignore hidden events. False to include them.
* @return \stdClass[] Array of event records.
*/
public function get_raw_events(
+21 -38
View File
@@ -1,43 +1,26 @@
<?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/>.
/////////////////////////////////////////////////////////////////////////////
// //
// NOTICE OF COPYRIGHT //
// //
// Moodle - Calendar extension //
// //
// Copyright (C) 2003-2004 Greek School Network www.sch.gr //
// //
// Designed by: //
// Avgoustos Tsinakos ([email protected]) //
// Jon Papaioannou ([email protected]) //
// //
// Programming and development: //
// Jon Papaioannou ([email protected]) //
// //
// For bugs, suggestions, etc contact: //
// Jon Papaioannou ([email protected]) //
// //
// The current module was developed at the University of Macedonia //
// (www.uom.gr) under the funding of the Greek School Network (www.sch.gr) //
// The aim of this project is to provide additional and improved //
// functionality to the Asynchronous Distance Education service that the //
// Greek School Network deploys. //
// //
// This program 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 2 of the License, or //
// (at your option) any later version. //
// //
// This program 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: //
// //
// http://www.gnu.org/copyleft/gpl.html //
// //
/////////////////////////////////////////////////////////////////////////////
/**
* Sets the events filter for the calendar view.
*
* @package core_calendar
* @copyright 2003 Jon Papaioannou ([email protected])
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once('../config.php');
require_once($CFG->dirroot.'/calendar/lib.php');
@@ -62,6 +62,7 @@ class core_calendar_action_event_factory_testcase extends advanced_testcase {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class action_event_factory_test_event implements event_interface {
public function get_id() {
return 1729;
}
+7
View File
@@ -95,6 +95,7 @@ class core_calendar_action_event_testcase extends advanced_testcase {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_calendar_action_event_test_event implements event_interface {
public function get_id() {
return 1729;
}
@@ -156,8 +157,14 @@ class core_calendar_action_event_test_event implements event_interface {
* @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 {
/**
* @var array
*/
protected $events;
/**
* core_calendar_action_event_test_event_collection constructor.
*/
public function __construct() {
$this->events = [
'not really an event hahaha',
+4 -4
View File
@@ -130,7 +130,7 @@ class core_calendar_container_testcase extends advanced_testcase {
* @dataProvider get_event_factory_testcases()
* @param \stdClass $dbrow Row from the "database".
*/
function test_event_factory_when_module_visibility_is_toggled_as_admin($dbrow) {
public function test_event_factory_when_module_visibility_is_toggled_as_admin($dbrow) {
$legacyevent = $this->create_event($dbrow);
$factory = \core_calendar\local\event\core_container::get_event_factory();
$course = $this->getDataGenerator()->create_course();
@@ -156,7 +156,7 @@ class core_calendar_container_testcase extends advanced_testcase {
* @dataProvider get_event_factory_testcases()
* @param \stdClass $dbrow Row from the "database".
*/
function test_event_factory_when_module_visibility_is_toggled_as_guest($dbrow) {
public function test_event_factory_when_module_visibility_is_toggled_as_guest($dbrow) {
$legacyevent = $this->create_event($dbrow);
$factory = \core_calendar\local\event\core_container::get_event_factory();
$course = $this->getDataGenerator()->create_course();
@@ -182,7 +182,7 @@ class core_calendar_container_testcase extends advanced_testcase {
/**
* Test that the event factory deals with completion related events properly.
*/
function test_event_factory_with_completion_related_event() {
public function test_event_factory_with_completion_related_event() {
global $CFG;
$CFG->enablecompletion = true;
@@ -296,7 +296,7 @@ class core_calendar_container_testcase extends advanced_testcase {
* Helper function to create calendar events using the old code.
*
* @param array $properties A list of calendar event properties to set
* @return event
* @return \core_calendar\event|bool
*/
protected function create_event($properties = []) {
$record = new \stdClass();
+4 -7
View File
@@ -83,8 +83,6 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
/**
* Test invalid callback exception.
*
* @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_action_callback() {
$this->resetAfterTest(true);
@@ -106,6 +104,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
$modulecache
);
$this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
@@ -132,8 +131,6 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
/**
* Test invalid callback exception.
*
* @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_visibility_callback() {
$this->resetAfterTest(true);
@@ -155,6 +152,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
$modulecache
);
$this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
@@ -181,8 +179,6 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
/**
* Test invalid callback exception.
*
* @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_bail_callback() {
$this->resetAfterTest(true);
@@ -204,6 +200,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
$modulecache
);
$this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
@@ -446,7 +443,7 @@ class core_calendar_event_factory_testcase extends advanced_testcase {
* Helper function to create calendar events using the old code.
*
* @param array $properties A list of calendar event properties to set
* @return event
* @return \core_calendar\event
*/
protected function create_event($properties = []) {
$record = new \stdClass();
+12 -5
View File
@@ -57,7 +57,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
}
/**
* Test event -> legacy event
* Test event -> legacy event.
*/
public function test_from_event_to_legacy_event() {
$this->resetAfterTest(true);
@@ -72,7 +72,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
}
/**
* Test event -> stdClass
* Test event -> stdClass.
*/
public function test_from_event_to_stdclass() {
$this->resetAfterTest(true);
@@ -90,7 +90,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
}
/**
* Test event -> array
* Test event -> array.
*/
public function test_from_event_to_assoc_array() {
$this->resetAfterTest(true);
@@ -107,6 +107,9 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
$this->assertEquals($arr['timestart'], $event->get_times()->get_start_time()->getTimestamp());
}
/**
* Test for action event -> legacy event.
*/
public function test_from_action_event_to_legacy_event() {
$this->resetAfterTest(true);
$this->setAdminUser();
@@ -157,6 +160,7 @@ class core_calendar_event_mapper_testcase extends advanced_testcase {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_mapper_test_event_factory implements event_factory_interface {
public function create_instance(\stdClass $dbrow) {
return new event_mapper_test_event();
}
@@ -174,6 +178,10 @@ class event_mapper_test_action_event implements action_event_interface {
*/
protected $event;
/**
* event_mapper_test_action_event constructor.
* @param event_interface $event
*/
public function __construct(event_interface $event) {
$this->event = $event;
}
@@ -269,7 +277,7 @@ class event_mapper_test_event implements event_interface {
protected $subscriptionproxy;
/**
* Constructor.
* Constructor.
*
* @param \core_calendar\event $legacyevent Legacy event to exctract IDs etc from.
*/
@@ -349,7 +357,6 @@ class event_mapper_test_event implements event_interface {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_mapper_test_proxy implements proxy_interface {
/**
* @var int $id Proxied ID.
*/
+10 -10
View File
@@ -305,7 +305,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$strategy = new raw_event_retrieval_strategy();
$vault = new event_vault($factory, $strategy);
/**
/*
* The events should be ordered by timesort as follows:
*
* 1 event 1
@@ -352,7 +352,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
]);
}
/**
/*
* Expected result set:
*
* 2 event 4
@@ -376,7 +376,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('2 event 8', $events[8]->get_name());
/**
/*
* Expected result set:
*
* 2 event 4
@@ -388,7 +388,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('1 event 5', $events[1]->get_name());
/**
/*
* Expected result set:
*
* 2 event 8
@@ -403,7 +403,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertCount(1, $events);
$this->assertEquals('2 event 8', $events[0]->get_name());
/**
/*
* Expected empty result set.
*/
$aftereventid = $records[18]->id;
@@ -776,7 +776,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->getDataGenerator()->enrol_user($user->id, $course1->id);
$this->getDataGenerator()->enrol_user($user->id, $course2->id);
/**
/*
* The events should be ordered by timesort as follows:
*
* 1 event 1
@@ -835,7 +835,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
]);
}
/**
/*
* Expected result set:
*
* 2 event 4
@@ -859,7 +859,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('2 event 8', $events[8]->get_name());
/**
/*
* Expected result set:
*
* 2 event 4
@@ -871,7 +871,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('1 event 5', $events[1]->get_name());
/**
/*
* Expected result set:
*
* 2 event 8
@@ -886,7 +886,7 @@ class core_calendar_event_vault_testcase extends advanced_testcase {
$this->assertCount(1, $events);
$this->assertEquals('2 event 8', $events[0]->get_name());
/**
/*
* Expected empty result set.
*/
$aftereventid = $records[18]->id;
+8 -3
View File
@@ -28,17 +28,14 @@ global $CFG;
require_once($CFG->dirroot . '/calendar/lib.php');
use core_calendar\local\data_access\event_vault;
use core_calendar\local\event\entities\action_event;
use core_calendar\local\event\entities\event;
use core_calendar\local\event\entities\repeat_event_collection;
use core_calendar\local\event\proxies\std_proxy;
use core_calendar\local\event\value_objects\action;
use core_calendar\local\event\value_objects\event_course_module;
use core_calendar\local\event\value_objects\event_description;
use core_calendar\local\event\value_objects\event_times;
use core_calendar\local\interfaces\event_factory_interface;
use core_calendar\local\interfaces\raw_event_retrieval_strategy_interface;
/**
* Create a calendar event with the given properties.
@@ -68,9 +65,15 @@ function create_event($properties) {
/**
* A test factory that will create action events.
*
* @copyright 2017 Ryan Wyllie <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or late
*/
class action_event_test_factory implements event_factory_interface {
/**
* @var callable $callback.
*/
private $callback;
/**
@@ -79,6 +82,8 @@ class action_event_test_factory implements event_factory_interface {
*
* The callback will be given the event and should return true if the event
* should be returned and false otherwise.
*
* @param callable $callback The callback.
*/
public function __construct($callback = null) {
$this->callback = $callback;
+5 -2
View File
@@ -38,6 +38,9 @@ class core_calendar_module_std_proxy_testcase extends advanced_testcase {
*/
public $objects;
/**
* Sets up the fixture. This method is called before a test is executed.
*/
public function setUp() {
$this->objects = [
'somemodule_someinstance' => (object) [
@@ -105,7 +108,6 @@ class core_calendar_module_std_proxy_testcase extends advanced_testcase {
* Test getting a non existant member.
*
* @dataProvider test_get_set_testcases()
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
* @param string $modulename Object module name.
* @param string $instance Object instance.
*/
@@ -118,6 +120,7 @@ class core_calendar_module_std_proxy_testcase extends advanced_testcase {
}
);
$this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->get('thisdoesnotexist');
}
@@ -125,7 +128,6 @@ class core_calendar_module_std_proxy_testcase extends advanced_testcase {
* Test setting a non existant member.
*
* @dataProvider test_get_set_testcases()
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
* @param string $modulename Object module name.
* @param string $instance Object instance.
*/
@@ -138,6 +140,7 @@ class core_calendar_module_std_proxy_testcase extends advanced_testcase {
}
);
$this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->set('thisdoesnotexist', 'should break');
}
@@ -35,7 +35,6 @@ use core_calendar\local\event\strategies\raw_event_retrieval_strategy;
* @copyright 2017 Cameron Ball <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_calendar_raw_event_retrieval_strategy_testcase extends advanced_testcase {
/**
* Test retrieval strategy when module is disabled.
@@ -41,13 +41,12 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
/**
* Test that creating a repeat collection for a parent that doesn't
* exist throws an exception.
*
* @expectedException \core_calendar\local\event\exceptions\no_repeat_parent_exception
*/
public function test_no_parent_collection() {
$this->resetAfterTest(true);
$parentid = 123122131;
$factory = new core_calendar_repeat_event_collection_event_test_factory();
$this->expectException('\core_calendar\local\event\exceptions\no_repeat_parent_exception');
$collection = new repeat_event_collection($parentid, null, $factory);
}
@@ -119,7 +118,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
* Helper function to create calendar events using the old code.
*
* @param array $properties A list of calendar event properties to set
* @return event
* @return \core_calendar\event
*/
protected function create_event($properties = []) {
$record = new \stdClass();
@@ -149,6 +148,7 @@ class core_calendar_repeat_event_collection_testcase extends advanced_testcase {
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class core_calendar_repeat_event_collection_event_test_factory implements event_factory_interface {
public function create_instance(\stdClass $dbrow) {
$identity = function($id) {
return $id;
+2 -2
View File
@@ -98,7 +98,6 @@ class core_calendar_std_proxy_testcase extends advanced_testcase {
* Test getting a non existant member.
*
* @dataProvider test_get_set_testcases()
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
* @param int $id ID of the object being proxied.
*/
public function test_get_invalid_member($id) {
@@ -106,6 +105,7 @@ class core_calendar_std_proxy_testcase extends advanced_testcase {
return $this->objects[$id];
});
$this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->get('thisdoesnotexist');
}
@@ -113,7 +113,6 @@ class core_calendar_std_proxy_testcase extends advanced_testcase {
* Test setting a non existant member.
*
* @dataProvider test_get_set_testcases()
* @expectedException \core_calendar\local\event\exceptions\member_does_not_exist_exception
* @param int $id ID of the object being proxied.
*/
public function test_set_invalid_member($id) {
@@ -121,6 +120,7 @@ class core_calendar_std_proxy_testcase extends advanced_testcase {
return $this->objects[$id];
});
$this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->set('thisdoesnotexist', 'should break');
}