From 8291540ae7c6ba24694cb19ebcd213ec81249ca8 Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 28 Jun 2018 10:09:31 +0800 Subject: [PATCH 1/2] MDL-62813 calendar: fix dmlreadexception on event form --- calendar/classes/local/event/forms/create.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/calendar/classes/local/event/forms/create.php b/calendar/classes/local/event/forms/create.php index 1e36407d74ba5..50e6d8158b7a7 100644 --- a/calendar/classes/local/event/forms/create.php +++ b/calendar/classes/local/event/forms/create.php @@ -119,10 +119,9 @@ public function validation($data, $files) { global $DB, $CFG; $errors = parent::validation($data, $files); - $coursekey = isset($data['groupcourseid']) ? 'groupcourseid' : 'courseid'; $eventtypes = calendar_get_all_allowed_types(); $eventtype = isset($data['eventtype']) ? $data['eventtype'] : null; - + $coursekey = ($eventtype == 'group') ? 'groupcourseid' : 'courseid'; if (empty($eventtype) || !isset($eventtypes[$eventtype])) { $errors['eventtype'] = get_string('invalideventtype', 'calendar'); } From 2a643b019eb345eb31efee29ae14fd61f1a57eec Mon Sep 17 00:00:00 2001 From: Simey Lameze Date: Thu, 28 Jun 2018 14:04:46 +0800 Subject: [PATCH 2/2] MDL-62813 calendar: add behat test for form validation --- calendar/tests/behat/calendar.feature | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/calendar/tests/behat/calendar.feature b/calendar/tests/behat/calendar.feature index e0e7850dc1e9b..18e41e8bb7926 100644 --- a/calendar/tests/behat/calendar.feature +++ b/calendar/tests/behat/calendar.feature @@ -154,3 +154,22 @@ Feature: Perform basic calendar functionality When I click on "Go to activity" "link" And I wait to be redirected Then I should see "Test choice" + + @javascript + Scenario: Attempt to create event without fill required fields should display validation errors + Given I log in as "teacher1" + And I am on "Course 1" course homepage + And I follow "This month" + And I click on "New event" "button" + When I click on "Save" "button" + Then I should see "Required" + And I am on site homepage + And I follow "Calendar" + And I click on "New event" "button" + And I set the field "Type of event" to "Course" + When I click on "Save" "button" + Then I should see "Required" + And I should see "Select a course" + And I set the field "Event title" to "Really awesome event!" + When I click on "Save" "button" + Then I should see "Select a course"