Part of MDL-55611 epic.
* @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);
}
/**
* 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();
* Constructor.
*
* @param event_interface $event
+ * @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$this->event = $event;
* Constructor.
*
* @param event_interface $event
+ * @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$coursemodule = $event->get_course_module();
// 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 <ryan@moodle.com>
/**
* 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 = []) {
// 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 <ryan@moodle.com>
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
/**
* 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) {
/**
* 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) {
/**
* 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) {
/**
* 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) {
/**
* 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) {
// 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 <ryan@moodle.com>
/**
* 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(
* @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,
* @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,
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();
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;
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
* 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,
);
}
+ /**
+ * 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,
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,
* 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,
*/
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;
* @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);
}
}
* @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,
* @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);
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.
* @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;
* @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,
$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,
* @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,
/**
* 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) {
defined('MOODLE_INTERNAL') || die();
-use core_calendar\local\interfaces\event_interface;
-
/**
* Interface for an action event class.
*
/**
* Get the action event's action.
*
- * @return \core_calendar\local\event\value_objects\action_interface
+ * @return action_interface
*/
public function get_action();
}
/**
* 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();
/**
* 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();
defined('MOODLE_INTERNAL') || die();
use core_calendar\event;
-use core_calendar\local\interfaces\event_interface;
/**
* Interface for an event mapper class
namespace core_calendar\local\interfaces;
+defined('MOODLE_INTERNAL') || die();
+
/**
* Interface for an event vault class
*
/**
* 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,
* ($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(
// 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 <cameron@cameron1729.xyz>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* 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(
<?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 (tsinakos@teikav.edu.gr) //
-// Jon Papaioannou (pj@moodle.org) //
-// //
-// Programming and development: //
-// Jon Papaioannou (pj@moodle.org) //
-// //
-// For bugs, suggestions, etc contact: //
-// Jon Papaioannou (pj@moodle.org) //
-// //
-// 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 (pj@moodle.org)
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
require_once('../config.php');
require_once($CFG->dirroot.'/calendar/lib.php');
* @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;
}
* @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;
}
* @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',
* @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();
* @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();
/**
* 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;
* 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();
/**
* Test invalid callback exception.
- *
- * @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_action_callback() {
$this->resetAfterTest(true);
$modulecache
);
+ $this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
/**
* Test invalid callback exception.
- *
- * @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_visibility_callback() {
$this->resetAfterTest(true);
$modulecache
);
+ $this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
/**
* Test invalid callback exception.
- *
- * @expectedException \core_calendar\local\event\exceptions\invalid_callback_exception
*/
public function test_invalid_bail_callback() {
$this->resetAfterTest(true);
$modulecache
);
+ $this->expectException('\core_calendar\local\event\exceptions\invalid_callback_exception');
$factory->create_instance(
(object)[
'id' => $event->id,
* 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();
}
/**
- * Test event -> legacy event
+ * Test event -> legacy event.
*/
public function test_from_event_to_legacy_event() {
$this->resetAfterTest(true);
}
/**
- * Test event -> stdClass
+ * Test event -> stdClass.
*/
public function test_from_event_to_stdclass() {
$this->resetAfterTest(true);
}
/**
- * Test event -> array
+ * Test event -> array.
*/
public function test_from_event_to_assoc_array() {
$this->resetAfterTest(true);
$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();
* @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();
}
*/
protected $event;
+ /**
+ * event_mapper_test_action_event constructor.
+ * @param event_interface $event
+ */
public function __construct(event_interface $event) {
$this->event = $event;
}
protected $subscriptionproxy;
/**
- * Constructor.
+ * Constructor.
*
* @param \core_calendar\event $legacyevent Legacy event to exctract IDs etc from.
*/
* @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.
*/
$strategy = new raw_event_retrieval_strategy();
$vault = new event_vault($factory, $strategy);
- /**
+ /*
* The events should be ordered by timesort as follows:
*
* 1 event 1
]);
}
- /**
+ /*
* Expected result set:
*
* 2 event 4
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('2 event 8', $events[8]->get_name());
- /**
+ /*
* Expected result set:
*
* 2 event 4
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('1 event 5', $events[1]->get_name());
- /**
+ /*
* Expected result set:
*
* 2 event 8
$this->assertCount(1, $events);
$this->assertEquals('2 event 8', $events[0]->get_name());
- /**
+ /*
* Expected empty result set.
*/
$aftereventid = $records[18]->id;
$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
]);
}
- /**
+ /*
* Expected result set:
*
* 2 event 4
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('2 event 8', $events[8]->get_name());
- /**
+ /*
* Expected result set:
*
* 2 event 4
$this->assertEquals('2 event 4', $events[0]->get_name());
$this->assertEquals('1 event 5', $events[1]->get_name());
- /**
+ /*
* Expected result set:
*
* 2 event 8
$this->assertCount(1, $events);
$this->assertEquals('2 event 8', $events[0]->get_name());
- /**
+ /*
* Expected empty result set.
*/
$aftereventid = $records[18]->id;
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.
/**
* A test factory that will create action events.
+ *
+ * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
+ * @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;
/**
*
* 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;
*/
public $objects;
+ /**
+ * Sets up the fixture. This method is called before a test is executed.
+ */
public function setUp() {
$this->objects = [
'somemodule_someinstance' => (object) [
* 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.
*/
}
);
+ $this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->get('thisdoesnotexist');
}
* 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.
*/
}
);
+ $this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->set('thisdoesnotexist', 'should break');
}
* @copyright 2017 Cameron Ball <cameron@cameron1729.xyz>
* @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.
/**
* 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);
}
* 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();
* @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;
* 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) {
return $this->objects[$id];
});
+ $this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->get('thisdoesnotexist');
}
* 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) {
return $this->objects[$id];
});
+ $this->expectException('\core_calendar\local\event\exceptions\member_does_not_exist_exception');
$proxy->set('thisdoesnotexist', 'should break');
}