From fd57126fc710789e83bd3e11630c56a8b84e91fd Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Thu, 30 Jul 2015 02:07:24 +0000 Subject: [PATCH 1/2] MDL-50446 block_site_main_menu: Fix the onclick property handling --- blocks/site_main_menu/block_site_main_menu.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/blocks/site_main_menu/block_site_main_menu.php b/blocks/site_main_menu/block_site_main_menu.php index e28c75bedf5..8b9e0d07eec 100644 --- a/blocks/site_main_menu/block_site_main_menu.php +++ b/blocks/site_main_menu/block_site_main_menu.php @@ -73,8 +73,9 @@ class block_site_main_menu extends block_list { $attrs['title'] = $cm->modfullname; $attrs['class'] = $cm->extraclasses . ' activity-action'; if ($cm->onclick) { - $attrs['id'] = html_writer::random_id('onclick'); - $OUTPUT->add_action_handler(new component_action('click', $cm->onclick), $attrs['id']); + // Get on-click attribute value if specified and decode the onclick - it + // has already been encoded for display. + $attrs['onclick'] = htmlspecialchars_decode($cm->onclick); } if (!$cm->visible) { $attrs['class'] .= ' dimmed'; @@ -161,8 +162,9 @@ class block_site_main_menu extends block_list { $attrs['title'] = $mod->modfullname; $attrs['class'] = $mod->extraclasses . ' activity-action'; if ($mod->onclick) { - $attrs['id'] = html_writer::random_id('onclick'); - $OUTPUT->add_action_handler(new component_action('click', $mod->onclick), $attrs['id']); + // Get on-click attribute value if specified and decode the onclick - it + // has already been encoded for display. + $attrs['onclick'] = htmlspecialchars_decode($mod->onclick); } if (!$mod->visible) { $attrs['class'] .= ' dimmed'; From fd4eca115ab1f7864504e8b80a7129ed23572d60 Mon Sep 17 00:00:00 2001 From: Ryan Wyllie Date: Thu, 30 Jul 2015 03:20:35 +0000 Subject: [PATCH 2/2] MDL-50446 block_site_main_menu: Test add URL resource Behat tests to confirm that adding a URL resource to the main menu block doens't break the javascript. --- .../site_main_menu/tests/behat/add_url.feature | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 blocks/site_main_menu/tests/behat/add_url.feature diff --git a/blocks/site_main_menu/tests/behat/add_url.feature b/blocks/site_main_menu/tests/behat/add_url.feature new file mode 100644 index 00000000000..f391d7bc6f1 --- /dev/null +++ b/blocks/site_main_menu/tests/behat/add_url.feature @@ -0,0 +1,18 @@ +@block @block_main_menu +Feature: Add URL to main menu block + In order to add helpful resources for students + As a admin + I need to add URLs to the main menu block and check it works. + + @javascript + Scenario: Add a URL in menu block and ensure it appears + Given I log in as "admin" + And I am on site homepage + And I navigate to "Turn editing on" node in "Front page settings" + When I add a "URL" to section "0" and I fill the form with: + | Name | google | + | Description | gooooooooogle | + | External URL | http://www.google.com | + | id_display | In pop-up | + Then "google" "link" should exist in the "Main menu" "block" + And "Add an activity or resource" "link" should exist in the "Main menu" "block"