From d2a158d3a9995ac31febeb2d7748d14ecee0ce7c Mon Sep 17 00:00:00 2001 From: ferranrecio Date: Tue, 8 Oct 2024 18:03:26 +0200 Subject: [PATCH] MDL-82349 block_site_main_menu: fix behats --- .../behat/behat_block_site_main_menu.php | 119 ----------- .../behat_block_site_main_menu_deprecated.php | 192 ++++++++++++++++++ .../tests/behat/edit_activities.feature | 124 ++++++++++- 3 files changed, 310 insertions(+), 125 deletions(-) create mode 100644 blocks/site_main_menu/tests/behat/behat_block_site_main_menu_deprecated.php diff --git a/blocks/site_main_menu/tests/behat/behat_block_site_main_menu.php b/blocks/site_main_menu/tests/behat/behat_block_site_main_menu.php index 00190399429f8..0580e24e0c57d 100644 --- a/blocks/site_main_menu/tests/behat/behat_block_site_main_menu.php +++ b/blocks/site_main_menu/tests/behat/behat_block_site_main_menu.php @@ -27,10 +27,6 @@ require_once(__DIR__ . '/../../../../lib/behat/behat_base.php'); -use Behat\Mink\Exception\ExpectationException as ExpectationException, - Behat\Mink\Exception\DriverException as DriverException, - Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; - /** * Behat steps definitions for block site main menu * @@ -40,121 +36,6 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ class behat_block_site_main_menu extends behat_base { - - /** - * Returns the DOM node of the activity in the site menu block - * - * @throws ElementNotFoundException Thrown by behat_base::find - * @param string $activityname The activity name - * @return NodeElement - */ - protected function get_site_menu_activity_node($activityname) { - $activityname = behat_context_helper::escape($activityname); - $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., $activityname)]"; - - return $this->find('xpath', $xpath); - } - - /** - * Checks that the specified activity's action menu contains an item. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should have "(?P(?:[^"]|\\")*)" editing icon$/ - * @param string $activityname - * @param string $iconname - */ - public function activity_in_site_main_menu_block_should_have_editing_icon($activityname, $iconname) { - $activitynode = $this->get_site_menu_activity_node($activityname); - - $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' . - $iconname . '" editing icon', $this->getSession()); - $this->find('named_partial', array('link', $iconname), $notfoundexception, $activitynode); - } - - /** - * Checks that the specified activity's action menu contains an item. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should not have "(?P(?:[^"]|\\")*)" editing icon$/ - * @param string $activityname - * @param string $iconname - */ - public function activity_in_site_main_menu_block_should_not_have_editing_icon($activityname, $iconname) { - $activitynode = $this->get_site_menu_activity_node($activityname); - - try { - $this->find('named_partial', array('link', $iconname), false, $activitynode); - throw new ExpectationException('"' . $activityname . '" has a "' . $iconname . - '" editing icon when it should not', $this->getSession()); - } catch (ElementNotFoundException $e) { - // This is good, the menu item should not be there. - } - } - - /** - * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on. - * - * @Given /^I click on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in the "(?P(?:[^"]|\\")*)" activity in site main menu block$/ - * @param string $element - * @param string $selectortype - * @param string $activityname - */ - public function i_click_on_in_the_activity_in_site_main_menu_block($element, $selectortype, $activityname) { - $element = $this->get_site_menu_activity_element($element, $selectortype, $activityname); - $element->click(); - } - - /** - * Clicks on the specified element inside the activity container. - * - * @throws ElementNotFoundException - * @param string $element - * @param string $selectortype - * @param string $activityname - * @return NodeElement - */ - protected function get_site_menu_activity_element($element, $selectortype, $activityname) { - $activitynode = $this->get_site_menu_activity_node($activityname); - - $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '{$activityname}'"); - return $this->find($selectortype, $element, $exception, $activitynode); - } - - /** - * Checks that the specified activity is hidden. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should be hidden$/ - * @param string $activityname - */ - public function activity_in_site_main_menu_block_should_be_hidden($activityname) { - $activitynode = $this->get_site_menu_activity_node($activityname); - $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); - $this->find('named_partial', array('badge', get_string('hiddenfromstudents')), $exception, $activitynode); - } - - /** - * Checks that the specified activity is hidden. - * - * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should be available but hidden from course page$/ - * @param string $activityname - */ - public function activity_in_site_main_menu_block_should_be_available_but_hidden_from_course_page($activityname) { - $activitynode = $this->get_site_menu_activity_node($activityname); - $exception = new ExpectationException('"' . $activityname . '" is not hidden but available', $this->getSession()); - $this->find('named_partial', array('badge', get_string('hiddenoncoursepage')), $exception, $activitynode); - } - - /** - * Opens an activity actions menu if it is not already opened. - * - * @Given /^I open "(?P(?:[^"]|\\")*)" actions menu in site main menu block$/ - * @throws DriverException The step is not available when Javascript is disabled - * @param string $activityname - */ - public function i_open_actions_menu_in_site_main_menu_block($activityname) { - $activityname = behat_context_helper::escape($activityname); - $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., $activityname)]"; - $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']); - } - /** * Return the list of partial named selectors. * diff --git a/blocks/site_main_menu/tests/behat/behat_block_site_main_menu_deprecated.php b/blocks/site_main_menu/tests/behat/behat_block_site_main_menu_deprecated.php new file mode 100644 index 0000000000000..df8c4c56cf86b --- /dev/null +++ b/blocks/site_main_menu/tests/behat/behat_block_site_main_menu_deprecated.php @@ -0,0 +1,192 @@ +. + +// NOTE: no MOODLE_INTERNAL test here, this file may be required by behat before including /config.php. + +require_once(__DIR__ . '/../../../../lib/behat/behat_deprecated_base.php'); + +use Behat\Mink\Element\NodeElement; +use Behat\Mink\Exception\ExpectationException as ExpectationException; +use Behat\Mink\Exception\DriverException as DriverException; +use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException; + +/** + * Behat steps in plugin block_site_main_menu + * + * @package block_site_main_menu + * @category test + * @copyright 2024 Ferran Recio + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class behat_block_site_main_menu_deprecated extends behat_deprecated_base { + + /** + * Returns the DOM node of the activity in the site menu block + * + * @throws ElementNotFoundException Thrown by behat_base::find + * @param string $activityname The activity name + * @return NodeElement + */ + protected function get_site_menu_activity_node($activityname) { + $activityname = behat_context_helper::escape($activityname); + $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., $activityname)]"; + + return $this->find('xpath', $xpath); + } + + /** + * Clicks on the specified element of the activity. You should be in the course page with editing mode turned on. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Given /^I click on "(?P(?:[^"]|\\")*)" "(?P(?:[^"]|\\")*)" in the "(?P(?:[^"]|\\")*)" activity in site main menu block$/ + * @param string $element + * @param string $selectortype + * @param string $activityname + */ + public function i_click_on_in_the_activity_in_site_main_menu_block($element, $selectortype, $activityname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::i_click_on_in_the_activity_in_site_main_menu_block is deprecated', + 'Use: I open ACTIVITYNAME actions menu & I choose OPTIONTEXT in the open action menu', + ]); + $element = $this->get_site_menu_activity_element($element, $selectortype, $activityname); + $element->click(); + } + + /** + * Clicks on the specified element inside the activity container. + * + * @throws ElementNotFoundException + * @param string $element + * @param string $selectortype + * @param string $activityname + * @return NodeElement + */ + protected function get_site_menu_activity_element($element, $selectortype, $activityname) { + $activitynode = $this->get_site_menu_activity_node($activityname); + + $exception = new ElementNotFoundException($this->getSession(), "'{$element}' '{$selectortype}' in '{$activityname}'"); + return $this->find($selectortype, $element, $exception, $activitynode); + } + + /** + * Checks that the specified activity's action menu contains an item. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should have "(?P(?:[^"]|\\")*)" editing icon$/ + * @param string $activityname + * @param string $iconname + */ + public function activity_in_site_main_menu_block_should_have_editing_icon($activityname, $iconname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::activity_in_site_main_menu_block_should_have_editing_icon is deprecated', + 'Use: I should see WHATEVER in the ACTIVITYNAME "activity"', + ]); + + $activitynode = $this->get_site_menu_activity_node($activityname); + + $notfoundexception = new ExpectationException('"' . $activityname . '" doesn\'t have a "' . + $iconname . '" editing icon', $this->getSession()); + $this->find('named_partial', ['link', $iconname], $notfoundexception, $activitynode); + } + + /** + * Checks that the specified activity's action menu contains an item. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should not have "(?P(?:[^"]|\\")*)" editing icon$/ + * @param string $activityname + * @param string $iconname + */ + public function activity_in_site_main_menu_block_should_not_have_editing_icon($activityname, $iconname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::activity_in_site_main_menu_block_should_not_have_editing_icon is deprecated', + 'Use: I should not see WHATEVER in the ACTIVITYNAME "activity"', + ]); + $activitynode = $this->get_site_menu_activity_node($activityname); + + try { + $this->find('named_partial', array('link', $iconname), false, $activitynode); + throw new ExpectationException('"' . $activityname . '" has a "' . $iconname . + '" editing icon when it should not', $this->getSession()); + } catch (ElementNotFoundException $e) { + // This is good, the menu item should not be there. + } + } + + /** + * Checks that the specified activity is hidden. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should be hidden$/ + * @param string $activityname + */ + public function activity_in_site_main_menu_block_should_be_hidden($activityname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::activity_in_site_main_menu_block_should_be_hidden is deprecated', + 'Use: I should see "Hidden from students" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"', + ]); + $activitynode = $this->get_site_menu_activity_node($activityname); + $exception = new ExpectationException('"' . $activityname . '" is not hidden', $this->getSession()); + $this->find('named_partial', ['badge', get_string('hiddenfromstudents')], $exception, $activitynode); + } + + /** + * Checks that the specified activity is hidden. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Then /^"(?P(?:[^"]|\\")*)" activity in site main menu block should be available but hidden from course page$/ + * @param string $activityname + */ + public function activity_in_site_main_menu_block_should_be_available_but_hidden_from_course_page($activityname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::activity_in_site_main_menu_block_should_be_available_but_hidden_from_course_page is deprecated', + 'Use: I should see "Available but not shown on course page" in the "ACTIVITYNAME" "core_courseformat > Activity visibility"', + ]); + $activitynode = $this->get_site_menu_activity_node($activityname); + $exception = new ExpectationException('"' . $activityname . '" is not hidden but available', $this->getSession()); + $this->find('named_partial', ['badge', get_string('hiddenoncoursepage')], $exception, $activitynode); + } + + /** + * Opens an activity actions menu if it is not already opened. + * + * @todo MDL-79721 This will be deleted in Moodle 6.0. + * @deprecated since 5.0 + * + * @Given /^I open "(?P(?:[^"]|\\")*)" actions menu in site main menu block$/ + * @throws DriverException The step is not available when Javascript is disabled + * @param string $activityname + */ + public function i_open_actions_menu_in_site_main_menu_block($activityname) { + $this->deprecated_message([ + 'behat_block_site_main_menu::i_open_actions_menu_in_site_main_menu_block is deprecated', + 'Use: I open "ACTIVITYNAME" actions menu', + ]); + $activityname = behat_context_helper::escape($activityname); + $xpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]//li[contains(., $activityname)]"; + $this->execute('behat_action_menu::i_open_the_action_menu_in', [$xpath, 'xpath_element']); + } +} diff --git a/blocks/site_main_menu/tests/behat/edit_activities.feature b/blocks/site_main_menu/tests/behat/edit_activities.feature index 336c14bc6523c..acd59e690923a 100644 --- a/blocks/site_main_menu/tests/behat/edit_activities.feature +++ b/blocks/site_main_menu/tests/behat/edit_activities.feature @@ -17,7 +17,7 @@ Feature: Edit activities in main menu block And I log in as "admin" And I am on site homepage And I turn editing mode on - When I set the field "Edit title" in the "My forum name" "block_site_main_menu > Activity" to "New forum name" + When I set the field "Edit title" in the "My forum name" "activity" to "New forum name" Then I should not see "My forum name" And I should see "New forum name" And I follow "New forum name" @@ -38,20 +38,132 @@ Feature: Edit activities in main menu block And I log in as "admin" And I am on site homepage And I turn editing mode on - When I open "My forum name" actions menu in site main menu block + When I open "My forum name" actions menu And I choose "Availability > Make available but don't show on course page" in the open action menu Then I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" # Make sure that "Availability" dropdown in the edit menu has three options. - And I open "My forum name" actions menu in site main menu block - And I click on "Edit settings" "link" in the "My forum name" activity in site main menu block + And I open "My forum name" actions menu + And I choose "Edit settings" in the open action menu And I expand all fieldsets And the "Availability" select box should contain "Show on course page" And the "Availability" select box should contain "Hide on course page" And the field "Availability" matches value "Make available but don't show on course page" And I press "Save and return to course" - And "My forum name" activity in site main menu block should be available but hidden from course page + Then I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" And I turn editing mode off - And "My forum name" activity in site main menu block should be available but hidden from course page + Then I should see "Available but not shown on course page" in the "My forum name" "core_courseformat > Activity visibility" And I log out And I should not see "My forum name" in the "Main menu" "block" And I should see "Visible forum" in the "Main menu" "block" + + @javascript + Scenario: The move activity modal allow to move from the main menu block to the main content + Given the following "activity" exists: + | activity | forum | + | course | Acceptance test site | + | name | My forum name | + | idnumber | forum | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | site_main_menu | System | 1 | site-index | side-pre | + And I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should see "My forum name" in the "block_site_main_menu_section" "region" + And I should not see "My forum name" in the "region-main" "region" + When I open "My forum name" actions menu + And I click on "Move" "link" in the "My forum name" activity + And I should see "My forum name" in the "Move activity" "dialogue" + And I should see "Block" in the "Move activity" "dialogue" + And I should see "Site" in the "Move activity" "dialogue" + And I click on "Site" "link" in the "Move activity" "dialogue" + Then I should see "My forum name" in the "region-main" "region" + And I should not see "My forum name" in the "block_site_main_menu_section" "region" + + @javascript + Scenario: The move activity modal allow to move from the main content to the main menu block + Given the following "activity" exists: + | activity | forum | + | course | Acceptance test site | + | name | My forum name | + | idnumber | forum | + | section | 1 | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | site_main_menu | System | 1 | site-index | side-pre | + And I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should not see "My forum name" in the "block_site_main_menu_section" "region" + And I should see "My forum name" in the "region-main" "region" + When I open "My forum name" actions menu + And I click on "Move" "link" in the "My forum name" activity + And I should see "My forum name" in the "Move activity" "dialogue" + And I should see "Block" in the "Move activity" "dialogue" + And I should see "Site" in the "Move activity" "dialogue" + And I click on "Block" "link" in the "Move activity" "dialogue" + Then I should not see "My forum name" in the "region-main" "region" + And I should see "My forum name" in the "block_site_main_menu_section" "region" + + @javascript + Scenario: Teacher can delete an activity in the main menu block + Given the following "activity" exists: + | activity | forum | + | course | Acceptance test site | + | name | My forum name | + | idnumber | forum | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | site_main_menu | System | 1 | site-index | side-pre | + And I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should see "My forum name" in the "block_site_main_menu_section" "region" + When I open "My forum name" actions menu + And I choose "Delete" in the open action menu + And I click on "Delete" "button" in the "Delete activity?" "dialogue" + Then I should not see "My forum name" in the "block_site_main_menu_section" "region" + + @javascript + Scenario: Teacher can duplicate an activity in the main menu block + Given the following "activity" exists: + | activity | forum | + | course | Acceptance test site | + | name | My forum name | + | idnumber | forum | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | site_main_menu | System | 1 | site-index | side-pre | + And I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should see "My forum name" in the "block_site_main_menu_section" "region" + When I open "My forum name" actions menu + And I choose "Duplicate" in the open action menu + Then I should see "My forum name (copy)" in the "block_site_main_menu_section" "region" + + @javascript + Scenario: Teacher can move right and left an activity in the main menu block + Given the following "activity" exists: + | activity | forum | + | course | Acceptance test site | + | name | My forum name | + | idnumber | forum | + And the following "blocks" exist: + | blockname | contextlevel | reference | pagetypepattern | defaultregion | + | site_main_menu | System | 1 | site-index | side-pre | + And I log in as "admin" + And I am on site homepage + And I turn editing mode on + And I should see "My forum name" in the "block_site_main_menu_section" "region" + When I open "My forum name" actions menu + And "Move right" "link" should be visible + And "Move left" "link" should not be visible + And I choose "Move right" in the open action menu + Then I open "My forum name" actions menu + And "Move right" "link" should not be visible + And "Move left" "link" should be visible + And I choose "Move left" in the open action menu + And I open "My forum name" actions menu + And "Move right" "link" should be visible + And "Move left" "link" should not be visible