Skip to content

Commit

Permalink
MDL-58428 theme: Shift templates ready for Bootstrapbase removal
Browse files Browse the repository at this point in the history
Move behat override steps from boost into their Moodle core locations &
Move the effected core behat steps into bootstrapbase as override steps.
  • Loading branch information
Chocolate-lightning committed Feb 22, 2019
1 parent 07203d3 commit e365293
Show file tree
Hide file tree
Showing 25 changed files with 893 additions and 933 deletions.
32 changes: 16 additions & 16 deletions admin/tests/behat/behat_admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,12 @@ public function i_set_the_following_administration_settings_values(TableNode $ta

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);
Expand All @@ -78,21 +74,24 @@ public function i_set_the_following_administration_settings_values(TableNode $ta

// 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.
Expand All @@ -101,6 +100,7 @@ public function i_set_the_following_administration_settings_values(TableNode $ta

// 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);
Expand Down
38 changes: 28 additions & 10 deletions blocks/tests/behat/behat_blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
}
}

Expand Down Expand Up @@ -108,7 +106,7 @@ public function i_open_the_blocks_action_menu($blockname) {
}

$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")
);
}

Expand Down Expand Up @@ -137,7 +135,17 @@ public function i_configure_the_block($blockname) {
* @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']);
}
}

/**
Expand All @@ -147,6 +155,16 @@ public function the_add_block_selector_should_contain_block($blockname) {
* @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']);
}
}
}
Loading

0 comments on commit e365293

Please sign in to comment.