MDL-51749 calendar: Behat tests for calendar export and additional fixes

This commit is contained in:
Jun Pataleta
2016-04-18 15:02:50 +08:00
parent 6552198130
commit 3de445bb56
2 changed files with 63 additions and 4 deletions
+6 -4
View File
@@ -60,7 +60,8 @@ if (!empty($generateurl)) {
if(!empty($what) && !empty($time)) {
if(in_array($what, $allowed_what) && in_array($time, $allowed_time)) {
$courses = enrol_get_users_courses($user->id, true, 'id, visible, shortname');
// Array of courses that we will pass to calendar_get_events() which is initially set to the list of the user's courses.
$paramcourses = $courses;
if ($what == 'all' || $what == 'groups') {
$groups = array();
foreach ($courses as $course) {
@@ -75,13 +76,14 @@ if(!empty($what) && !empty($time)) {
$users = $user->id;
$courses[SITEID] = new stdClass;
$courses[SITEID]->shortname = get_string('globalevents', 'calendar');
$paramcourses[SITEID] = $courses[SITEID];
} else if ($what == 'groups') {
$users = false;
$courses = array();
$paramcourses = array();
} else if ($what == 'user') {
$users = $user->id;
$groups = false;
$courses = array();
$paramcourses = array();
} else {
$users = false;
$groups = false;
@@ -177,7 +179,7 @@ if(!empty($what) && !empty($time)) {
die();
}
}
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($courses), false);
$events = calendar_get_events($timestart, $timeend, $users, $groups, array_keys($paramcourses), false);
$ical = new iCalendar;
$ical->add_property('method', 'PUBLISH');
+57
View File
@@ -0,0 +1,57 @@
@core @core_calendar @core_calendar_export
Feature: Export calendar events
In order to be able to use my calendar events outside of Moodle
As a user
I need to export calendar events in iCalendar format
Background:
Given the following "users" exist:
| username | firstname | lastname | email |
| student1 | Student | 1 | student1@example.com |
And the following "courses" exist:
| fullname | shortname | format |
| Course 1 | C1 | topics |
And the following "course enrolments" exist:
| user | course | role |
| student1 | C1 | student |
And I log in as "student1"
Scenario: Viewing calendar export options
Given I follow "This month"
When I click on "Export calendar" "button"
Then I should see "All events"
And I should see "Events related to courses"
And I should see "Events related to groups"
And I should see "My personal events"
Scenario: Generating calendar URL for all events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "All events" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=all&"
Scenario: Generating calendar URL for course events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "Events related to courses" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=courses&"
Scenario: Generating calendar URL for group events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "Events related to groups" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=groups&"
Scenario: Generating calendar URL for user events
Given I follow "This month"
And I click on "Export calendar" "button"
And I set the field "My personal events" to "1"
And I set the field "This week" to "1"
When I click on "Get calendar URL" "button"
Then I should see "&preset_what=user&"