Commit e3652936 authored by Mathew May's avatar Mathew May
Browse files

MDL-58428 theme: Shift templates ready for Bootstrapbase removal

Move behat override steps from boost into their Moodle core locations &
Move the effected core behat steps into bootstrapbase as override steps.
parent 07203d34
......@@ -55,16 +55,12 @@ class behat_admin extends behat_base {
foreach ($data as $label => $value) {
// We expect admin block to be visible, otherwise go to homepage.
if (!$this->getSession()->getPage()->find('css', '.block_settings')) {
$this->getSession()->visit($this->locate_path('/'));
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
}
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', [get_string('administrationsite')]);
// Search by label.
$searchbox = $this->find_field(get_string('searchinsettings', 'admin'));
$searchbox = $this->find_field(get_string('query', 'admin'));
$searchbox->setValue($label);
$submitsearch = $this->find('css', 'form.adminsearchform input[type=submit]');
$submitsearch = $this->find('css', 'form input[type=submit][name=search]');
$submitsearch->press();
$this->wait(self::TIMEOUT * 1000, self::PAGE_READY_JS);
......@@ -78,21 +74,24 @@ class behat_admin extends behat_base {
// Single element settings.
try {
$fieldxpath = "//*[self::input | self::textarea | self::select][not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
"[@id=//label[contains(normalize-space(.), $label)]/@for or " .
"@id=//span[contains(normalize-space(.), $label)]/preceding-sibling::label[1]/@for]";
$fieldxpath = "//*[self::input | self::textarea | self::select]" .
"[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]" .
"[@id=//label[contains(normalize-space(.), $label)]/@for or " .
"@id=//span[contains(normalize-space(.), $label)]/preceding-sibling::label[1]/@for]";
$fieldnode = $this->find('xpath', $fieldxpath, $exception);
$formfieldtypenode = $this->find('xpath', $fieldxpath . "/ancestor::div[@class='form-setting']" .
"/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
$formfieldtypenode = $this->find('xpath', $fieldxpath .
"/ancestor::div[contains(concat(' ', @class, ' '), ' form-setting ')]" .
"/child::div[contains(concat(' ', @class, ' '), ' form-')]/child::*/parent::div");
} catch (ElementNotFoundException $e) {
// Multi element settings, interacting only the first one.
$fieldxpath = "//*[label[normalize-space(.)= $label]|span[normalize-space(.)= $label]]/" .
"ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' form-item ')]" .
"/descendant::div[@class='form-group']/descendant::*[self::input | self::textarea | self::select]" .
"[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]";
$fieldxpath = "//*[label[contains(., $label)]|span[contains(., $label)]]" .
"/ancestor::div[contains(concat(' ', normalize-space(@class), ' '), ' form-item ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' form-group ')]" .
"/descendant::*[self::input | self::textarea | self::select]" .
"[not(./@type = 'submit' or ./@type = 'image' or ./@type = 'hidden')]";
$fieldnode = $this->find('xpath', $fieldxpath);
// It is the same one that contains the type.
......@@ -101,6 +100,7 @@ class behat_admin extends behat_base {
// Getting the class which contains the field type.
$classes = explode(' ', $formfieldtypenode->getAttribute('class'));
$type = false;
foreach ($classes as $class) {
if (substr($class, 0, 5) == 'form-') {
$type = substr($class, 5);
......
......@@ -46,15 +46,13 @@ class behat_blocks extends behat_base {
* @param string $blockname
*/
public function i_add_the_block($blockname) {
$this->execute('behat_forms::i_set_the_field_to',
array("bui_addblock", $this->escape($blockname))
);
$addblock = get_string('addblock');
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
// If we are running without javascript we need to submit the form.
if (!$this->running_javascript()) {
$this->execute('behat_general::i_click_on_in_the',
array(get_string('go'), "button", "#add_block", "css_element")
);
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
} else {
$this->execute('behat_general::i_click_on_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
}
}
......@@ -108,7 +106,7 @@ class behat_blocks extends behat_base {
}
$this->execute('behat_general::i_click_on_in_the',
array(get_string('actions'), "link", $this->escape($blockname), "block")
array("a[data-toggle='dropdown']", "css_element", $this->escape($blockname), "block")
);
}
......@@ -137,7 +135,17 @@ class behat_blocks extends behat_base {
* @param string $blockname
*/
public function the_add_block_selector_should_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_contain', [get_string('addblock'), $blockname]);
$addblock = get_string('addblock');
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
$cancelstr = get_string('cancel');
if (!$this->running_javascript()) {
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
} else {
$this->execute('behat_general::should_exist_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'button', $addblock, 'dialogue']);
}
}
/**
......@@ -147,6 +155,16 @@ class behat_blocks extends behat_base {
* @param string $blockname
*/
public function the_add_block_selector_should_not_contain_block($blockname) {
$this->execute('behat_forms::the_select_box_should_not_contain', [get_string('addblock'), $blockname]);
$addblock = get_string('addblock');
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', $addblock);
$cancelstr = get_string('cancel');
if (!$this->running_javascript()) {
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', '#region-main', 'css_element']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'link_exact', '#region-main', 'css_element']);
} else {
$this->execute('behat_general::should_not_exist_in_the', [$blockname, 'link_exact', $addblock, 'dialogue']);
$this->execute('behat_general::i_click_on_in_the', [$cancelstr, 'button', $addblock, 'dialogue']);
}
}
}
......@@ -186,10 +186,11 @@ class behat_course extends behat_base {
// We are on the frontpage.
if ($section) {
// Section 1 represents the contents on the frontpage.
$sectionxpath = "//body[@id='page-site-index']/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
$sectionxpath = "//body[@id='page-site-index']" .
"/descendant::div[contains(concat(' ',normalize-space(@class),' '),' sitetopic ')]";
} else {
// Section 0 represents "Site main menu" block.
$sectionxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]";
$sectionxpath = "//*[contains(concat(' ',normalize-space(@class),' '),' block_site_main_menu ')]";
}
} else {
// We are inside the course.
......@@ -201,15 +202,16 @@ class behat_course extends behat_base {
if ($this->running_javascript()) {
// Clicks add activity or resource section link.
$sectionxpath = $sectionxpath . "/descendant::div[@class='section-modchooser']/span/a";
$sectionxpath = $sectionxpath . "/descendant::div" .
"[contains(concat(' ', normalize-space(@class) , ' '), ' section-modchooser ')]/span/a";
$sectionnode = $this->find('xpath', $sectionxpath);
$sectionnode->click();
// Clicks the selected activity if it exists.
$activityxpath = "//div[@id='chooseform']/descendant::label" .
"/descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' typename ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::label/child::input";
"/descendant::span[contains(concat(' ', normalize-space(@class), ' '), ' typename ')]" .
"[normalize-space(.)=$activityliteral]" .
"/parent::label/child::input";
$activitynode = $this->find('xpath', $activityxpath);
$activitynode->doubleClick();
......@@ -217,8 +219,9 @@ class behat_course extends behat_base {
// Without Javascript.
// Selecting the option from the select box which contains the option.
$selectxpath = $sectionxpath . "/descendant::div[contains(concat(' ', normalize-space(@class), ' '), ' section_add_menus ')]" .
"/descendant::select[option[normalize-space(.)=$activityliteral]]";
$selectxpath = $sectionxpath . "/descendant::div" .
"[contains(concat(' ', normalize-space(@class), ' '), ' section_add_menus ')]" .
"/descendant::select[option[normalize-space(.)=$activityliteral]]";
$selectnode = $this->find('xpath', $selectxpath);
$selectnode->selectOption($activity);
......@@ -230,7 +233,6 @@ class behat_course extends behat_base {
}
/**
* Opens a section edit menu if it is not already opened.
*
......@@ -248,7 +250,7 @@ class behat_course extends behat_base {
// If it is already opened we do nothing.
$xpath = $this->section_exists($sectionnumber);
$xpath .= "/descendant::div[contains(@class, 'section-actions')]/descendant::a[contains(@class, 'textmenu')]";
$xpath .= "/descendant::div[contains(@class, 'section-actions')]/descendant::a[contains(@data-toggle, 'dropdown')]";
$exception = new ExpectationException('Section "' . $sectionnumber . '" was not found', $this->getSession());
$menu = $this->find('xpath', $xpath, $exception);
......@@ -550,8 +552,8 @@ class behat_course extends behat_base {
// Edit menu should be visible.
if ($this->is_course_editor()) {
$xpath = $sectionxpath .
"/descendant::div[contains(@class, 'section-actions')]" .
"/descendant::a[contains(@class, 'textmenu')]";
"/descendant::div[contains(@class, 'section-actions')]" .
"/descendant::a[contains(@data-toggle, 'dropdown')]";
if (!$this->getSession()->getPage()->find('xpath', $xpath)) {
throw new ExpectationException('The section edit menu is not available', $this->getSession());
}
......@@ -843,15 +845,23 @@ class behat_course extends behat_base {
// If it is already opened we do nothing.
$activitynode = $this->get_activity_node($activityname);
$classes = array_flip(explode(' ', $activitynode->getAttribute('class')));
if (!empty($classes['action-menu-shown'])) {
// Find the menu.
$menunode = $activitynode->find('css', 'a[data-toggle=dropdown]');
if (!$menunode) {
throw new ExpectationException(sprintf('Could not find actions menu for the activity "%s"', $activityname),
$this->getSession());
}
$expanded = $menunode->getAttribute('aria-expanded');
if ($expanded == 'true') {
return;
}
$this->execute('behat_course::i_click_on_in_the_activity',
array("a[role='menuitem']", "css_element", $this->escape($activityname))
array("a[data-toggle='dropdown']", "css_element", $this->escape($activityname))
);
$this->actions_menu_should_be_open($activityname);
}
/**
......@@ -869,13 +879,19 @@ class behat_course extends behat_base {
// If it is already closed we do nothing.
$activitynode = $this->get_activity_node($activityname);
$classes = array_flip(explode(' ', $activitynode->getAttribute('class')));
if (empty($classes['action-menu-shown'])) {
// Find the menu.
$menunode = $activitynode->find('css', 'a[data-toggle=dropdown]');
if (!$menunode) {
throw new ExpectationException(sprintf('Could not find actions menu for the activity "%s"', $activityname),
$this->getSession());
}
$expanded = $menunode->getAttribute('aria-expanded');
if ($expanded != 'true') {
return;
}
$this->execute('behat_course::i_click_on_in_the_activity',
array("a[role='menuitem']", "css_element", $this->escape($activityname))
array("a[data-toggle='dropdown']", "css_element", $this->escape($activityname))
);
}
......@@ -892,10 +908,15 @@ class behat_course extends behat_base {
throw new DriverException('Activities actions menu not available when Javascript is disabled');
}
// If it is already closed we do nothing.
$activitynode = $this->get_activity_node($activityname);
$classes = array_flip(explode(' ', $activitynode->getAttribute('class')));
if (empty($classes['action-menu-shown'])) {
// Find the menu.
$menunode = $activitynode->find('css', 'a[data-toggle=dropdown]');
if (!$menunode) {
throw new ExpectationException(sprintf('Could not find actions menu for the activity "%s"', $activityname),
$this->getSession());
}
$expanded = $menunode->getAttribute('aria-expanded');
if ($expanded != 'true') {
throw new ExpectationException(sprintf("The action menu for '%s' is not open", $activityname), $this->getSession());
}
}
......@@ -1039,18 +1060,18 @@ class behat_course extends behat_base {
// Determine the future new activity xpath from the former one.
$duplicatedxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" .
"[contains(., $activityliteral)]/following-sibling::li";
$duplicatedactionsmenuxpath = $duplicatedxpath . "/descendant::a[@role='menuitem']";
"[contains(., $activityliteral)]/following-sibling::li";
$duplicatedactionsmenuxpath = $duplicatedxpath . "/descendant::a[@data-toggle='dropdown']";
if ($this->running_javascript()) {
// We wait until the AJAX request finishes and the section is visible again.
$hiddenlightboxxpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')]" .
"[contains(., $activityliteral)]" .
"/ancestor::li[contains(concat(' ', normalize-space(@class), ' '), ' section ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]";
"[contains(., $activityliteral)]" .
"/ancestor::li[contains(concat(' ', normalize-space(@class), ' '), ' section ')]" .
"/descendant::div[contains(concat(' ', @class, ' '), ' lightbox ')][contains(@style, 'display: none')]";
$this->execute("behat_general::wait_until_exists",
array($this->escape($hiddenlightboxxpath), "xpath_element")
array($this->escape($hiddenlightboxxpath), "xpath_element")
);
// Close the original activity actions menu.
......@@ -1059,13 +1080,13 @@ class behat_course extends behat_base {
// The next sibling of the former activity will be the duplicated one, so we click on it from it's xpath as, at
// this point, it don't even exists in the DOM (the steps are executed when we return them).
$this->execute('behat_general::i_click_on',
array($this->escape($duplicatedactionsmenuxpath), "xpath_element")
array($this->escape($duplicatedactionsmenuxpath), "xpath_element")
);
}
// We force the xpath as otherwise mink tries to interact with the former one.
$this->execute('behat_general::i_click_on_in_the',
array(get_string('editsettings'), "link", $this->escape($duplicatedxpath), "xpath_element")
array(get_string('editsettings'), "link", $this->escape($duplicatedxpath), "xpath_element")
);
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
......@@ -1281,8 +1302,8 @@ class behat_course extends behat_base {
protected function is_course_editor() {
// We don't need to behat_base::spin() here as all is already loaded.
if (!$this->getSession()->getPage()->findButton(get_string('turneditingoff')) &&
!$this->getSession()->getPage()->findButton(get_string('turneditingon'))) {
if (!$this->getSession()->getPage()->findLink(get_string('turneditingoff')) &&
!$this->getSession()->getPage()->findLink(get_string('turneditingon'))) {
return false;
}
......@@ -1842,7 +1863,8 @@ class behat_course extends behat_base {
* @throws Behat\Mink\Exception\ExpectationException
*/
protected function user_clicks_on_management_listing_action($listingtype, $listingnode, $action) {
$actionsnode = $listingnode->find('xpath', "//*[contains(concat(' ', normalize-space(@class), ' '), '{$listingtype}-item-actions')]");
$actionsnode = $listingnode->find('xpath', "//*" .
"[contains(concat(' ', normalize-space(@class), ' '), '{$listingtype}-item-actions')]");
if (!$actionsnode) {
throw new ExpectationException("Could not find the actions for $listingtype", $this->getSession());
}
......@@ -1851,7 +1873,7 @@ class behat_course extends behat_base {
throw new ExpectationException("Expected action was not available or not found ($action)", $this->getSession());
}
if ($this->running_javascript() && !$actionnode->isVisible()) {
$actionsnode->find('css', 'a.toggle-display')->click();
$actionsnode->find('css', 'a[data-toggle=dropdown]')->click();
$actionnode = $actionsnode->find('css', '.action-'.$action);
}
$actionnode->click();
......@@ -1874,10 +1896,7 @@ class behat_course extends behat_base {
* @Given /^I navigate to course participants$/
*/
public function i_navigate_to_course_participants() {
$coursestr = behat_context_helper::escape(get_string('courses'));
$mycoursestr = behat_context_helper::escape(get_string('mycourses'));
$xpath = "//div[contains(@class,'block')]//li[p/*[string(.)=$coursestr or string(.)=$mycoursestr]]";
$this->execute('behat_general::i_click_on_in_the', [get_string('participants'), 'link', $xpath, 'xpath_element']);
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('participants'));
}
/**
......
......@@ -76,15 +76,18 @@ class behat_grade extends behat_base {
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
$this->execute("behat_action_menu::i_open_the_action_menu_in",
array("//tr[contains(.,$gradeitem)]",
"xpath_element"));
}
}
$savechanges = get_string('savechanges', 'grades');
$edit = behat_context_helper::escape(get_string('edit') . ' ');
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
"and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
$this->execute("behat_forms::i_set_the_following_fields_to_these_values", $data);
......@@ -128,16 +131,19 @@ class behat_grade extends behat_base {
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
$this->execute("behat_action_menu::i_open_the_action_menu_in",
array("//tr[contains(.,$gradeitem)]",
"xpath_element"));
}
}
// Going to edit calculation.
$savechanges = get_string('savechanges', 'grades');
$edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
"and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// Mapping names to idnumbers.
......@@ -145,11 +151,12 @@ class behat_grade extends behat_base {
foreach ($datahash as $gradeitem => $idnumber) {
// This xpath looks for course, categories and items with the provided name.
// Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
$inputxpath ="//input[@class='idnumber'][" .
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
" or " .
"parent::li[@class='categoryitem' or @class='courseitem']/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]";
$inputxpath = "//input[@class='idnumber'][" .
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
" or " .
"parent::li[@class='categoryitem' or @class='courseitem']" .
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]";
$this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
}
......@@ -174,17 +181,18 @@ class behat_grade extends behat_base {
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" .
"//a[contains(@class,'toggle-display')]";
$xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
$xpath = "//tr[contains(.,$gradecategorytotal)]";
$this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
}
}
// Going to edit calculation.
$savechanges = get_string('savechanges', 'grades');
$edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$linkxpath = "//a[./*[contains(concat(' ', normalize-space(@class), ' '), ' icon ') " .
"and starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
// Mapping names to idnumbers.
......@@ -193,11 +201,11 @@ class behat_grade extends behat_base {
// This xpath looks for course, categories and items with the provided name.
// Grrr, we can't equal in categoryitem and courseitem because there is a line jump...
$inputxpath = "//input[@class='idnumber'][" .
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
" | " .
"parent::li[@class='categoryitem' | @class='courseitem']" .
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]";
"parent::li[@class='item'][text()='" . $gradeitem . "']" .
" | " .
"parent::li[@class='categoryitem' | @class='courseitem']" .
"/parent::ul/parent::li[starts-with(text(),'" . $gradeitem . "')]" .
"]";
$this->execute('behat_forms::i_set_the_field_with_xpath_to', array($inputxpath, $idnumber));
}
......@@ -221,9 +229,10 @@ class behat_grade extends behat_base {
if ($this->running_javascript()) {
$gradeitemliteral = behat_context_helper::escape($gradeitem);
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
$xpath = "//tr[contains(.,$gradeitemliteral)]";
$this->execute("behat_action_menu::i_open_the_action_menu_in", array($xpath, "xpath_element"));
}
}
......@@ -290,11 +299,10 @@ class behat_grade extends behat_base {
* @param string $gradepath
*/
public function i_navigate_to_in_the_course_gradebook($gradepath) {
// If we are not on one of the gradebook pages already, follow "Grades" link in the navigation block.
// If we are not on one of the gradebook pages already, follow "Grades" link in the navigation drawer.
$xpath = '//div[contains(@class,\'grade-navigation\')]';
if (!$this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on_in_the", array(get_string('grades'), 'link',
get_string('pluginname', 'block_navigation'), 'block'));
$this->execute('behat_navigation::i_select_from_flat_navigation_drawer', get_string('grades'));
}
$this->select_in_gradebook_tabs($gradepath);
......
......@@ -58,6 +58,7 @@ class behat_files extends behat_base {
* @param string $filepickerelement The filepicker form field label
* @return NodeElement The hidden element node.
*/
protected function get_filepicker_node($filepickerelement) {
// More info about the problem (in case there is a problem).
......@@ -66,18 +67,18 @@ class behat_files extends behat_base {
// If no file picker label is mentioned take the first file picker from the page.
if (empty($filepickerelement)) {
$filepickercontainer = $this->find(
'xpath',
"//*[@data-fieldtype=\"filemanager\"]",
$exception
'xpath',
"//*[@data-fieldtype=\"filemanager\"]",
$exception
);
} else {
// Gets the ffilemanager node specified by the locator which contains the filepicker container.
$filepickerelement = behat_context_helper::escape($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
'//ancestor::div[@data-fieldtype="filemanager" or @data-fieldtype="filepicker"]',
$exception
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
"//ancestor::*[@data-fieldtype = 'filemanager' or @data-fieldtype = 'filepicker']",
$exception
);
}
......
......@@ -49,16 +49,11 @@ class behat_action_menu extends behat_base {
* @return void
*/
public function i_open_the_action_menu_in($element, $selectortype) {
if (!$this->running_javascript()) {
// Action menus automatically expand in a visible list of actions when Javascript is disabled.
return;
}
// Gets the node based on the requested selector type and locator.
$node = $this->get_node_in_container("css_element", "[role=menuitem][aria-haspopup=true]", $selectortype, $element);
$node = $this->get_node_in_container("css_element", "[role=button][aria-haspopup=true]", $selectortype, $element);
// Check if it is not already opened.
$menunode = $this->find('css', '[aria-labelledby='.$node->getAttribute('id').']');
if ($menunode->getAttribute('aria-hidden') === 'false') {
if ($node->getAttribute('aria-expanded') === 'true') {
return;
}
......@@ -73,15 +68,13 @@ class behat_action_menu extends behat_base {
* @param string $linkstring
* @return void
*/
public function i_choose_in_the_open_action_menu($linkstring) {
public function i_choose_in_the_open_action_menu($menuitemstring) {
if (!$this->running_javascript()) {
throw new DriverException('Action menu steps are not available with Javascript disabled');
}
// Gets the node based on the requested selector type and locator.
$node = $this->get_node_in_container("link",
$linkstring,
"css_element",
".moodle-actionmenu [role=menu][aria-hidden=false]");
$menuselector = ".moodle-actionmenu .dropdown.show .dropdown-menu";
$node = $this->get_node_in_container("link", $menuitemstring, "css_element", $menuselector);
$this->ensure_node_is_visible($node);
$node->click();
}
......
......@@ -57,8 +57,6 @@ class behat_deprecated extends behat_base {
/**
* Click link in navigation tree that matches the text in parentnode/s (seperated using greater-than character if more than one)
*
* @Given /^I navigate to "(?P<nodetext_string>(?:[^"]|\\")*)" node in "(?P<parentnodes_string>(?:[^"]|\\")*)"$/
*
* @throws ExpectationException
* @param string $nodetext navigation node to click.
* @param string $parentnodes comma seperated list of parent nodes.
......@@ -78,7 +76,35 @@ class behat_deprecated extends behat_base {
$this->deprecated_message($alternative);
$parentnodes = array_map('trim', explode('>', $parentnodes));
$this->execute('behat_navigation::select_node_in_navigation', array($nodetext, $parentnodes));
$nodelist = array_merge($parentnodes, [$nodetext]);
$firstnode = array_shift($nodelist);
if ($firstnode === get_string('administrationsite')) {
$this->execute('behat_theme_boost_behat_navigation::i_select_from_flat_navigation_drawer',
array(get_string('administrationsite')));
$this->execute('behat_theme_boost_behat_navigation::select_on_administration_page', array($nodelist));
return;
}
if ($firstnode === get_string('sitepages')) {
if ($nodetext === get_string('calendar', 'calendar')) {
$this->execute('behat_theme_boost_behat_navigation::i_select_from_flat_navigation_drawer',
array(($nodetext)));
} else {
// TODO MDL-57120 other links under "Site pages" are not accessible without navigation block.
$this->execute('behat_theme_boost_behat_navigation::select_node_in_navigation',
array($nodetext, $parentnodes));
}
return;
}
if ($firstnode === get_string('courseadministration')) {
// Administration menu is available only on the main course page where settings in Administration
// block (original purpose of the step) are available on every course page.
$this->execute('behat_theme_boost_behat_navigation::go_to_main_course_page', array());
}
$this->execute('behat_theme_boost_behat_navigation::select_from_administration_menu', array($nodelist));
}
/**
......
......@@ -29,6 +29,7 @@ require_once(__DIR__ . '/../../behat/behat_base.php');
use Behat\Mink\Exception\ExpectationException as ExpectationException;
use Behat\Mink\Exception\DriverException as DriverException;
use Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
/**