MDL-57730 core_calendar: fixed failing unit tests
Part of MDL-55611 epic.
This commit is contained in:
committed by
Damyon Wiese
parent
294dce6764
commit
c91b4c0278
@@ -55,7 +55,7 @@ class core_container {
|
||||
protected static $actioneventfactory;
|
||||
|
||||
/**
|
||||
* @var event_mapper_interface $eventmapper Event mapper.
|
||||
* @var \core_calendar\local\interfaces\event_mapper_interface $eventmapper Event mapper.
|
||||
*/
|
||||
protected static $eventmapper;
|
||||
|
||||
@@ -65,54 +65,36 @@ class core_container {
|
||||
protected static $actionfactory;
|
||||
|
||||
/**
|
||||
* @var event_vault $eventvault Event vault.
|
||||
* @var \core_calendar\local\event\data_access\event_vault $eventvault Event vault.
|
||||
*/
|
||||
private static $eventvault;
|
||||
|
||||
/**
|
||||
* @var array A list of callbacks to use.
|
||||
*/
|
||||
protected static $callbacks = array();
|
||||
|
||||
/**
|
||||
* Initialises the dependency graph if it hasn't yet been.
|
||||
*/
|
||||
private static function init() {
|
||||
if (empty(self::$eventfactory)) {
|
||||
$identity = function(event_interface $event) {
|
||||
return $event;
|
||||
};
|
||||
self::initcallbacks();
|
||||
self::$actionfactory = new action_factory();
|
||||
self::$actioneventfactory = new action_event_factory();
|
||||
self::$eventmapper = new event_mapper(
|
||||
new event_factory($identity, $identity)
|
||||
);
|
||||
self::$eventfactory = new event_factory(
|
||||
function(event_interface $event) {
|
||||
$mapper = self::$eventmapper;
|
||||
$action = component_callback(
|
||||
'mod_' . $event->get_course_module()->get('modname'),
|
||||
'core_calendar_provide_event_action',
|
||||
[
|
||||
$mapper->from_event_to_legacy_event($event),
|
||||
self::$actionfactory
|
||||
]
|
||||
);
|
||||
|
||||
return $action ? self::$actioneventfactory->create_instance($event, $action) : $event;
|
||||
},
|
||||
function(event_interface $event) {
|
||||
$mapper = self::$eventmapper;
|
||||
$eventvisible = component_callback(
|
||||
'mod_' . $event->get_course_module()->get('modname'),
|
||||
'core_calendar_is_event_visible',
|
||||
[
|
||||
$mapper->from_event_to_legacy_event($event)
|
||||
]
|
||||
);
|
||||
|
||||
// Module does not implement the callback, event should be visible.
|
||||
if (is_null($eventvisible)) {
|
||||
new event_factory(
|
||||
function(event_interface $event) {
|
||||
return $event;
|
||||
}, function() {
|
||||
return true;
|
||||
}
|
||||
)
|
||||
);
|
||||
|
||||
return $eventvisible ? true : false;
|
||||
}
|
||||
self::$eventfactory = new event_factory(
|
||||
self::$callbacks[PHPUNIT_TEST ? 'testing' : 'production']['action'],
|
||||
self::$callbacks[PHPUNIT_TEST ? 'testing' : 'production']['visibility']
|
||||
);
|
||||
}
|
||||
|
||||
@@ -135,7 +117,7 @@ class core_container {
|
||||
/**
|
||||
* Gets the event mapper
|
||||
*
|
||||
* @return event_mapper_interface
|
||||
* @return \core_calendar\local\interfaces\event_mapper_interface
|
||||
*/
|
||||
public static function get_event_mapper() {
|
||||
self::init();
|
||||
@@ -145,10 +127,64 @@ class core_container {
|
||||
/**
|
||||
* Return an event vault.
|
||||
*
|
||||
* @return event_vault
|
||||
* @return \core_calendar\local\event\data_access\event_vault
|
||||
*/
|
||||
public static function get_event_vault() {
|
||||
self::init();
|
||||
return self::$eventvault;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialises the callbacks.
|
||||
*/
|
||||
private static function initcallbacks() {
|
||||
self::$callbacks = array(
|
||||
'testing' => array(
|
||||
'action' => function (event_interface $event) {
|
||||
return self::$actioneventfactory->create_instance($event,
|
||||
new \core_calendar\local\event\value_objects\action(
|
||||
'test',
|
||||
new \moodle_url('http://example.com'),
|
||||
420,
|
||||
true
|
||||
));
|
||||
},
|
||||
'visibility' => function (event_interface $event) {
|
||||
return true;
|
||||
}
|
||||
),
|
||||
'production' => array(
|
||||
'action' => function (event_interface $event) {
|
||||
$mapper = self::$eventmapper;
|
||||
$action = component_callback(
|
||||
'mod_' . $event->get_course_module()->get('modname'),
|
||||
'core_calendar_provide_event_action',
|
||||
[
|
||||
$mapper->from_event_to_legacy_event($event),
|
||||
self::$actionfactory
|
||||
]
|
||||
);
|
||||
|
||||
return $action ? self::$actioneventfactory->create_instance($event, $action) : $event;
|
||||
},
|
||||
'visibility' => function (event_interface $event) {
|
||||
$mapper = self::$eventmapper;
|
||||
$eventvisible = component_callback(
|
||||
'mod_' . $event->get_course_module()->get('modname'),
|
||||
'core_calendar_is_event_visible',
|
||||
[
|
||||
$mapper->from_event_to_legacy_event($event)
|
||||
]
|
||||
);
|
||||
|
||||
// Module does not implement the callback, event should be visible.
|
||||
if (is_null($eventvisible)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $eventvisible ? true : false;
|
||||
}
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-44
@@ -400,20 +400,14 @@ class core_calendar_api_testcase extends advanced_testcase {
|
||||
* be returned.
|
||||
*/
|
||||
function test_get_calendar_action_events_by_timesort_after_time() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
$moduleinstance = $generator->create_instance(['course' => $course->id]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
$params = [
|
||||
'type' => CALENDAR_EVENT_TYPE_ACTION,
|
||||
'modulename' => 'assign',
|
||||
'instance' => $moduleinstance->id,
|
||||
'userid' => $user->id,
|
||||
'courseid' => 1,
|
||||
'modulename' => 'xyz',
|
||||
'instance' => 1,
|
||||
'userid' => 1,
|
||||
'eventtype' => 'user',
|
||||
'repeats' => 0,
|
||||
'timestart' => 1,
|
||||
@@ -450,20 +444,14 @@ class core_calendar_api_testcase extends advanced_testcase {
|
||||
* returned.
|
||||
*/
|
||||
function test_get_calendar_action_events_by_timesort_before_time() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
$moduleinstance = $generator->create_instance(['course' => $course->id]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
$params = [
|
||||
'type' => CALENDAR_EVENT_TYPE_ACTION,
|
||||
'modulename' => 'assign',
|
||||
'instance' => $moduleinstance->id,
|
||||
'userid' => $user->id,
|
||||
'courseid' => 1,
|
||||
'modulename' => 'xyz',
|
||||
'instance' => 1,
|
||||
'userid' => 1,
|
||||
'eventtype' => 'user',
|
||||
'repeats' => 0,
|
||||
'timestart' => 1,
|
||||
@@ -499,20 +487,14 @@ class core_calendar_api_testcase extends advanced_testcase {
|
||||
* returned.
|
||||
*/
|
||||
function test_get_calendar_action_events_by_timesort_time_range() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
$moduleinstance = $generator->create_instance(['course' => $course->id]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
$params = [
|
||||
'type' => CALENDAR_EVENT_TYPE_ACTION,
|
||||
'modulename' => 'assign',
|
||||
'instance' => $moduleinstance->id,
|
||||
'userid' => $user->id,
|
||||
'courseid' => 1,
|
||||
'modulename' => 'xyz',
|
||||
'instance' => 1,
|
||||
'userid' => 1,
|
||||
'eventtype' => 'user',
|
||||
'repeats' => 0,
|
||||
'timestart' => 1,
|
||||
@@ -549,20 +531,14 @@ class core_calendar_api_testcase extends advanced_testcase {
|
||||
* returned.
|
||||
*/
|
||||
function test_get_calendar_action_events_by_timesort_time_limit_offset() {
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$generator = $this->getDataGenerator()->get_plugin_generator('mod_assign');
|
||||
$moduleinstance = $generator->create_instance(['course' => $course->id]);
|
||||
|
||||
$this->getDataGenerator()->enrol_user($user->id, $course->id);
|
||||
$this->resetAfterTest(true);
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
$params = [
|
||||
'type' => CALENDAR_EVENT_TYPE_ACTION,
|
||||
'modulename' => 'assign',
|
||||
'instance' => $moduleinstance->id,
|
||||
'userid' => $user->id,
|
||||
'courseid' => 1,
|
||||
'modulename' => 'xyz',
|
||||
'instance' => 1,
|
||||
'userid' => 1,
|
||||
'eventtype' => 'user',
|
||||
'repeats' => 0,
|
||||
'timestart' => 1,
|
||||
|
||||
@@ -24,7 +24,9 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once(__DIR__ . '/../lib.php');
|
||||
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;
|
||||
@@ -137,7 +139,8 @@ class action_event_test_factory implements event_factory_interface {
|
||||
$action = new action(
|
||||
'Test action',
|
||||
new \moodle_url('/'),
|
||||
1
|
||||
1,
|
||||
true
|
||||
);
|
||||
|
||||
$actionevent = new action_event($event, $action);
|
||||
|
||||
Reference in New Issue
Block a user