diff --git a/calendar/lib.php b/calendar/lib.php index 8577aedd586..208a895b091 100644 --- a/calendar/lib.php +++ b/calendar/lib.php @@ -3495,7 +3495,7 @@ function calendar_output_fragment_event_form($args) { $eventtypes = calendar_get_allowed_event_types($courseid); // If the user is on course context and is allowed to add course events set the event type default to course. - if ($courseid != SITEID && !empty($eventtypes['course'])) { + if (!empty($courseid) && !empty($eventtypes['course'])) { $data['eventtype'] = 'course'; $data['courseid'] = $courseid; $data['groupcourseid'] = $courseid; diff --git a/calendar/tests/behat/behat_calendar.php b/calendar/tests/behat/behat_calendar.php index 0bd835cc666..1c6cb4ccb30 100644 --- a/calendar/tests/behat/behat_calendar.php +++ b/calendar/tests/behat/behat_calendar.php @@ -124,4 +124,16 @@ class behat_calendar extends behat_base { $this->getSession()->visit($this->locate_path('/calendar/view.php?view=month&course=1&time='.$time)); } + + /** + * Navigate to site calendar. + * + * @Given /^I am viewing site calendar$/ + * @throws coding_exception + * @return void + */ + public function i_am_viewing_site_calendar() { + $url = new moodle_url('/calendar/view.php', ['view' => 'month']); + $this->getSession()->visit($this->locate_path($url->out_as_local_url(false))); + } } diff --git a/calendar/tests/behat/calendar.feature b/calendar/tests/behat/calendar.feature index 22aed84b75e..c03180cfcac 100644 --- a/calendar/tests/behat/calendar.feature +++ b/calendar/tests/behat/calendar.feature @@ -180,3 +180,14 @@ Feature: Perform basic calendar functionality And I set the field "Event title" to "Really awesome event!" When I click on "Save" "button" Then I should see "Select a course" + + @javascript + Scenario: Default event type selection in the event form + Given I log in as "teacher1" + When I am viewing site calendar + And I click on "New event" "button" + Then the field "Type of event" matches value "User" + And I am on "Course 1" course homepage + And I follow "This month" + When I click on "New event" "button" + Then the field "Type of event" matches value "Course"