Skip to content

Commit

Permalink
Merge branch 'MDL-69160-37' of git://github.com/andrewnicols/moodle i…
Browse files Browse the repository at this point in the history
…nto MOODLE_37_STABLE
  • Loading branch information
stronk7 committed Jul 21, 2020
2 parents 242a321 + 4068dd1 commit d1c2a39
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
31 changes: 17 additions & 14 deletions lib/tests/behat/behat_forms.php
Expand Up @@ -28,10 +28,9 @@
require_once(__DIR__ . '/../../../lib/behat/behat_base.php');
require_once(__DIR__ . '/../../../lib/behat/behat_field_manager.php');

use Behat\Gherkin\Node\TableNode as TableNode,
Behat\Gherkin\Node\PyStringNode as PyStringNode,
Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException;
use Behat\Gherkin\Node\{TableNode, PyStringNode};
use Behat\Mink\Element\NodeElement;
use Behat\Mink\Exception\{ElementNotFoundException, ExpectationException};

/**
* Forms-related steps definitions.
Expand Down Expand Up @@ -286,10 +285,7 @@ public function i_set_the_field_to_multiline($field, PyStringNode $value) {
* @return void
*/
public function i_set_the_field_with_xpath_to($fieldxpath, $value) {
$fieldnode = $this->find('xpath', $fieldxpath);
$this->ensure_node_is_visible($fieldnode);
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession());
$field->set_value($value);
$this->set_field_node_value($this->find('xpath', $fieldxpath), $value);
}

/**
Expand Down Expand Up @@ -627,13 +623,24 @@ public function the_select_box_should_not_contain($select, $option) {
* @return void
*/
protected function set_field_value($fieldlocator, $value) {

// We delegate to behat_form_field class, it will
// guess the type properly as it is a select tag.
$field = behat_field_manager::get_form_field_from_label($fieldlocator, $this);
$field->set_value($value);
}

/**
* Generic field setter to be used by chainable steps.
*
* @param NodeElement $fieldnode
* @param string $value
*/
public function set_field_node_value(NodeElement $fieldnode, string $value): void {
$this->ensure_node_is_visible($fieldnode);
$field = behat_field_manager::get_form_field($fieldnode, $this->getSession());
$field->set_value($value);
}

/**
* Generic field setter.
*
Expand All @@ -646,12 +653,8 @@ protected function set_field_value($fieldlocator, $value) {
* @param string $containerelement Element we look in
*/
protected function set_field_value_in_container($fieldlocator, $value, $containerselectortype, $containerelement) {

$node = $this->get_node_in_container('field', $fieldlocator, $containerselectortype, $containerelement);
// We delegate to behat_form_field class, it will
// guess the type properly as it is a select tag.
$field = behat_field_manager::get_form_field($node, $this->getSession());
$field->set_value($value);
$this->set_field_node_value($node, $value);
}

/**
Expand Down
Expand Up @@ -63,20 +63,19 @@ public function i_add_a_reviewer_for_workshop_participant($reviewername, $partic
$selectnode = $this->find('xpath', $xpathselect);
}

$selectformfield = behat_field_manager::get_form_field($selectnode, $this->getSession());
$selectformfield->set_value($reviewername);
$this->execute('behat_forms::set_field_node_value', [
$selectnode,
$reviewername,
]);

if (!$this->running_javascript()) {
// Without Javascript we need to press the "Go" button.
$go = behat_context_helper::escape(get_string('go'));
$this->find('xpath', $xpathtd."/descendant::input[@value=$go]")->click();
} else {
// With Javascript we just wait for the page to reload.
$this->getSession()->wait(behat_base::get_extended_timeout(), self::PAGE_READY_JS);
}

// Check the success string to appear.
$allocatedtext = behat_context_helper::escape(
get_string('allocationadded', 'workshopallocation_manual'));
$allocatedtext = behat_context_helper::escape(get_string('allocationadded', 'workshopallocation_manual'));
$this->find('xpath', "//*[contains(.,$allocatedtext)]");
}

Expand All @@ -88,8 +87,7 @@ public function i_add_a_reviewer_for_workshop_participant($reviewername, $partic
* @param TableNode $table should have one column with title 'Reviewer' and another with title 'Participant' (or 'Reviewee')
*/
public function i_allocate_submissions_in_workshop_as($workshopname, TableNode $table) {

$this->find_link($workshopname)->click();
$this->execute('behat_general::i_click_on', [$workshopname, 'link']);
$this->execute('behat_navigation::i_navigate_to_in_current_page_administration', get_string('allocate', 'workshop'));
$rows = $table->getRows();
$reviewer = $participant = null;
Expand All @@ -108,8 +106,15 @@ public function i_allocate_submissions_in_workshop_as($workshopname, TableNode $
if ($participant === null) {
throw new ElementTextException('Neither "Participant" nor "Reviewee" column could be located', $this->getSession());
}

for ($i = 1; $i < count($rows); $i++) {
$this->i_add_a_reviewer_for_workshop_participant($rows[$i][$reviewer], $rows[$i][$participant]);
$this->execute(
'behat_workshopallocation_manual::i_add_a_reviewer_for_workshop_participant',
[
$rows[$i][$reviewer],
$rows[$i][$participant],
]
);
}
}
}

0 comments on commit d1c2a39

Please sign in to comment.