From 90b843bbbbb5bcb8e25a5e92d283383544c0d48c Mon Sep 17 00:00:00 2001 From: Kathrin Osswald <kathrin.osswald@uni-ulm.de> Date: Thu, 27 Aug 2020 13:52:35 +0200 Subject: [PATCH] Fixed bug in image area feature if link attribute was left empty. --- CHANGES.md | 1 + locallib.php | 6 +++++- ..._campus_additional_layout_settings.feature | 19 +++++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 4892482..4d2889c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -6,6 +6,7 @@ Changes ### Unreleased +* 2020-08-27 - Fixed bug in image area feature if link attribute was left empty. * 2020-08-27 - Fixed regression for commit Added rule to show description border for all users for restricted activities. ### Release v3.8-r3 diff --git a/locallib.php b/locallib.php index a0a6126..a215e66 100644 --- a/locallib.php +++ b/locallib.php @@ -181,6 +181,10 @@ function theme_boost_campus_get_imageareacontent() { // Get all files from filearea. $files = $fs->get_area_files($systemcontext->id, 'theme_boost_campus', 'imageareaitems', false, 'itemid', false); + // Initialize the array which holds the image links. + $links = []; + // Initialize the array which holds the alt texts. + $alttexts = []; // Only continue processing if there are files in the filearea. if (!empty($files)) { // Get the content from the setting imageareaitemsattributes and explode it to an array by the delimiter "new line". @@ -199,7 +203,7 @@ function theme_boost_campus_get_imageareacontent() { } else { $settings = explode("|", $line); // Check if parameter 2 or 3 is set. - if (!empty($settings[1] || !empty($settings[2]))) { + if (!empty($settings[1]) || !empty($settings[2])) { foreach ($settings as $i => $setting) { $setting = trim($setting); if (!empty($setting)) { diff --git a/tests/behat/theme_boost_campus_additional_layout_settings.feature b/tests/behat/theme_boost_campus_additional_layout_settings.feature index 0dbafc1..e7b1723 100644 --- a/tests/behat/theme_boost_campus_additional_layout_settings.feature +++ b/tests/behat/theme_boost_campus_additional_layout_settings.feature @@ -36,6 +36,25 @@ Feature: Configuring the theme_boost_campus plugin for the "Additional Layout Se Then ".imagearea img" "css_element" should exist And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//a[contains(@href, 'http://moodle.org')]" "xpath_element" should exist And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//img[contains(@alt, 'Moodle Logo')]" "xpath_element" should exist + When I navigate to "Appearance > Boost Campus" in site administration + And I click on "Additional Layout Settings" "link" + And I set the field "id_s_theme_boost_campus_imageareaitemsattributes" to "moodle_logo.jpg||Moodle Logo" + And I press "Save changes" + Then ".imagearea img" "css_element" should exist + And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//img[contains(@alt, 'Moodle Logo')]" "xpath_element" should exist + And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//a" "xpath_element" should not exist + When I navigate to "Appearance > Boost Campus" in site administration + And I click on "Additional Layout Settings" "link" + And I set the field "id_s_theme_boost_campus_imageareaitemsattributes" to "moodle_logo.jpg|http://moodle.org" + And I press "Save changes" + Then ".imagearea img" "css_element" should exist + And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//a[contains(@href, 'http://moodle.org')][not(@alt)]" "xpath_element" should exist + When I navigate to "Appearance > Boost Campus" in site administration + And I click on "Additional Layout Settings" "link" + And I set the field "id_s_theme_boost_campus_imageareaitemsattributes" to "moodle_logo.jpg" + And I press "Save changes" + Then "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//img[not(@alt)]" "xpath_element" should exist + And "//div[contains(concat(' ',normalize-space(@class),' '),' imagearea ')]//a" "xpath_element" should not exist # Dependent on setting "Image area items" # This is not testable with behat. -- GitLab