From c4b1115e8c32967f5e04148e8411053840477117 Mon Sep 17 00:00:00 2001 From: Huong Nguyen Date: Thu, 28 Jul 2022 15:11:42 +0700 Subject: [PATCH] MDL-74866 bennu: Fix parameter parsing Some parameter values are wrapped by DQUOTE character. We need to go through and get the actual value inside the quoted string. --- calendar/tests/behat/behat_calendar.php | 29 +++++++++++++++++-- calendar/tests/behat/calendar_import.feature | 17 +++++++++++ .../tests/fixtures/import_with_parameters.ics | 27 +++++++++++++++++ lib/bennu/iCalendar_components.php | 12 ++++++++ lib/bennu/readme_moodle.txt | 1 + 5 files changed, 83 insertions(+), 3 deletions(-) create mode 100644 calendar/tests/fixtures/import_with_parameters.ics diff --git a/calendar/tests/behat/behat_calendar.php b/calendar/tests/behat/behat_calendar.php index c336863052d..e7029fa9fde 100644 --- a/calendar/tests/behat/behat_calendar.php +++ b/calendar/tests/behat/behat_calendar.php @@ -137,16 +137,39 @@ class behat_calendar extends behat_base { } /** - * Navigate to a specific date in the calendar. + * Navigate to a specific month in the calendar. * * @Given /^I view the calendar for "(?P\d+)" "(?P\d+)"$/ * @param int $month the month selected as a number * @param int $year the four digit year */ public function i_view_the_calendar_for($month, $year) { - $time = make_timestamp($year, $month, 1); - $this->execute('behat_general::i_visit', ['/calendar/view.php?view=month&course=1&time='.$time]); + $this->view_the_calendar('month', 1, $month, $year); + } + /** + * Navigate to a specific date in the calendar. + * + * @Given /^I view the calendar for "(?P\d+)" "(?P\d+)" "(?P\d+)"$/ + * @param int $day the day selected as a number + * @param int $month the month selected as a number + * @param int $year the four digit year + */ + public function i_view_the_calendar_day_view(int $day, int $month, int $year) { + $this->view_the_calendar('day', $day, $month, $year); + } + + /** + * View the correct calendar view with specific day + * + * @param string $type type of calendar view: month or day + * @param int $day the day selected as a number + * @param int $month the month selected as a number + * @param int $year the four digit year + */ + private function view_the_calendar(string $type, int $day, int $month, int $year) { + $time = make_timestamp($year, $month, $day); + $this->execute('behat_general::i_visit', ['/calendar/view.php?view=' . $type . '&course=1&time=' . $time]); } /** diff --git a/calendar/tests/behat/calendar_import.feature b/calendar/tests/behat/calendar_import.feature index 47f0b1e7676..ec81dd6baee 100644 --- a/calendar/tests/behat/calendar_import.feature +++ b/calendar/tests/behat/calendar_import.feature @@ -85,3 +85,20 @@ Feature: Import and edit calendar events And I upload "calendar/tests/fixtures/import.ics" file to "Calendar file (.ics)" filemanager And I press "Import calendar" And I should see "Site events" + + Scenario: Import iCalendar file with parameter. + Given I log in as "admin" + And I view the calendar for "7" "2022" + And I click on "Import or export calendars" "link" + And I press "Import calendar" + And I set the following fields to these values: + | Calendar name | Test Import | + | Import from | Calendar file (.ics) | + | Type of event | User | + And I upload "calendar/tests/fixtures/import_with_parameters.ics" file to "Calendar file (.ics)" filemanager + And I press "Import calendar" + When I view the calendar for "1" "7" "2022" + Then I should see "First event" + And I should see "Description of the first event" + And I should see "Second event" + And I should see "Description of the second event" diff --git a/calendar/tests/fixtures/import_with_parameters.ics b/calendar/tests/fixtures/import_with_parameters.ics new file mode 100644 index 00000000000..a7db16b0fa0 --- /dev/null +++ b/calendar/tests/fixtures/import_with_parameters.ics @@ -0,0 +1,27 @@ +BEGIN:VCALENDAR +METHOD:PUBLISH +PRODID:-//Huong Nguyen/NONSGML Moodle//EN +VERSION:2.0 +BEGIN:VEVENT +UID:special_import_moodle_1 +SUMMARY:First event +DESCRIPTION:Description of the first event\n +CLASS:PUBLIC +LAST-MODIFIED:20220728T034015Z +LOCATION:Vietnam +DTSTAMP:20220728T034031Z +DTSTART:20220701T070000Z +DTEND:20220701T070000Z +END:VEVENT +BEGIN:VEVENT +UID:special_import_moodle_2 +SUMMARY:Second event +DESCRIPTION;ALTREP="http://moodle.com/":Description of the second event\n +CLASS:PUBLIC +LAST-MODIFIED:20220728T034021Z +LOCATION:Vietnam +DTSTAMP:20220728T034031Z +DTSTART:20220701T080000Z +DTEND:20220701T080000Z +END:VEVENT +END:VCALENDAR diff --git a/lib/bennu/iCalendar_components.php b/lib/bennu/iCalendar_components.php index 9a05677726b..912e818b50d 100644 --- a/lib/bennu/iCalendar_components.php +++ b/lib/bennu/iCalendar_components.php @@ -303,6 +303,18 @@ class iCalendar_component { $component = $this; // use the iCalendar } + $cleanedparams = []; + // Some parameter values are wrapped by DQUOTE character. + // We need to go through and get the actual value inside the quoted string. + foreach ($params as $param => $value) { + if (preg_match('#"(?P[^"]*?)"#', $value, $matches)) { + $cleanedparams[$param] = $matches['actualvalue']; + } else { + $cleanedparams[$param] = $value; + } + } + $params = $cleanedparams; + if ($component->add_property($label, $data, $params) === false) { $this->parser_error("Failed to add property '$label' on line $key"); } diff --git a/lib/bennu/readme_moodle.txt b/lib/bennu/readme_moodle.txt index 19f0628360d..6c8cd0598bf 100644 --- a/lib/bennu/readme_moodle.txt +++ b/lib/bennu/readme_moodle.txt @@ -28,3 +28,4 @@ Changelog 9/ MDL-60391: replace create_function() with lambda function for PHP 7.2 compatibility (13 Oct 2017) 10/ MDL-62914: added handling for TZURL property (13 July 2018) 11/ MDL-67029: replace curly by square brackets for string offsets. PHP 7.4 compatibility (25 Oct 2019) +12/ MDL-74866: fixed parameter parsing if the value is wrapped by DQUOTE character (28 Jul 2022)