This commit is contained in:
Dan Poltawski
2016-04-06 08:42:27 +01:00
25 changed files with 88 additions and 67 deletions
+1 -1
View File
@@ -74,7 +74,7 @@ class behat_admin extends behat_base {
$exception = new ElementNotFoundException($this->getSession(), '"' . $label . '" administration setting ');
// The argument should be converted to an xpath literal.
$label = $this->getSession()->getSelectorsHandler()->xpathLiteral($label);
$label = behat_context_helper::escape($label);
// Single element settings.
try {
+3 -3
View File
@@ -167,7 +167,7 @@ class behat_backup extends behat_base {
$this->getSession());
// The argument should be converted to an xpath literal.
$fromcourse = $this->getSession()->getSelectorsHandler()->xpathLiteral($fromcourse);
$fromcourse = behat_context_helper::escape($fromcourse);
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' ics-results ')]" .
"/descendant::tr[contains(., $fromcourse)]" .
"/descendant::input[@type='radio']";
@@ -212,7 +212,7 @@ class behat_backup extends behat_base {
$this->select_backup($backupfilename);
// The argument should be converted to an xpath literal.
$existingcourse = $this->getSession()->getSelectorsHandler()->xpathLiteral($existingcourse);
$existingcourse = behat_context_helper::escape($existingcourse);
// Selecting the specified course (we can not call behat_forms::select_radio here as is in another behat subcontext).
$radionode = $this->find('xpath', "//div[contains(concat(' ', normalize-space(@class), ' '), ' bcs-existing-course ')]" .
@@ -333,7 +333,7 @@ class behat_backup extends behat_base {
$this->getSession());
// The argument should be converted to an xpath literal.
$backupfilename = $this->getSession()->getSelectorsHandler()->xpathLiteral($backupfilename);
$backupfilename = behat_context_helper::escape($backupfilename);
$xpath = "//tr[contains(., $backupfilename)]/descendant::a[contains(., '" . get_string('restore') . "')]";
$restorelink = $this->find('xpath', $xpath, $exception);
@@ -92,7 +92,7 @@ class behat_block_comments extends behat_base {
$exception = new ElementNotFoundException($this->getSession(), '"' . $comment . '" comment ');
// Using xpath liternal to avoid possible problems with comments containing quotes.
$commentliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($comment);
$commentliteral = behat_context_helper::escape($comment);
$commentxpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' block_comments ')]" .
"/descendant::div[@class='comment-message'][contains(., $commentliteral)]";
+2 -2
View File
@@ -49,7 +49,7 @@ class behat_completion extends behat_base {
public function user_has_completed_activity($userfullname, $activityname) {
// Will throw an exception if the element can not be hovered.
$titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Completed");
$titleliteral = behat_context_helper::escape($userfullname . ", " . $activityname . ": Completed");
$xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, $titleliteral)]";
@@ -69,7 +69,7 @@ class behat_completion extends behat_base {
public function user_has_not_completed_activity($userfullname, $activityname) {
// Will throw an exception if the element can not be hovered.
$titleliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname . ", " . $activityname . ": Not completed");
$titleliteral = behat_context_helper::escape($userfullname . ", " . $activityname . ": Not completed");
$xpath = "//table[@id='completion-progress']" .
"/descendant::img[contains(@title, $titleliteral)]";
+6 -6
View File
@@ -188,7 +188,7 @@ class behat_course extends behat_base {
$sectionxpath = "//li[@id='section-" . $section . "']";
}
$activityliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral(ucfirst($activity));
$activityliteral = behat_context_helper::escape(ucfirst($activity));
if ($this->running_javascript()) {
@@ -892,7 +892,7 @@ class behat_course extends behat_base {
public function i_duplicate_activity_editing_the_new_copy_with($activityname, TableNode $data) {
$activity = $this->escape($activityname);
$activityliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($activityname);
$activityliteral = behat_context_helper::escape($activityname);
$this->execute("behat_course::i_duplicate_activity", $activity);
@@ -1023,7 +1023,7 @@ class behat_course extends behat_base {
$courseformat = $this->get_course_format();
// Checking the show button alt text and show icon.
$showtext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('showfromothers', $courseformat));
$showtext = behat_context_helper::escape(get_string('showfromothers', $courseformat));
$linkxpath = $xpath . "/descendant::a[@title=$showtext]";
$imgxpath = $linkxpath . "/descendant::img[contains(@src, 'show')]";
@@ -1050,7 +1050,7 @@ class behat_course extends behat_base {
$courseformat = $this->get_course_format();
// Checking the hide button alt text and hide icon.
$hidetext = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('hidefromothers', $courseformat));
$hidetext = behat_context_helper::escape(get_string('hidefromothers', $courseformat));
$linkxpath = $xpath . "/descendant::a[@title=$hidetext]";
$imgxpath = $linkxpath . "/descendant::img[contains(@src, 'hide')]";
@@ -1117,7 +1117,7 @@ class behat_course extends behat_base {
*/
protected function get_activity_node($activityname) {
$activityname = $this->getSession()->getSelectorsHandler()->xpathLiteral($activityname);
$activityname = behat_context_helper::escape($activityname);
$xpath = "//li[contains(concat(' ', normalize-space(@class), ' '), ' activity ')][contains(., $activityname)]";
return $this->find('xpath', $xpath);
@@ -1677,7 +1677,7 @@ class behat_course extends behat_base {
}
$exception = new ExpectationException('"' . $categoryname . '" category can not be found', $this->getSession());
$categoryliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($categoryname);
$categoryliteral = behat_context_helper::escape($categoryname);
$xpath = "//div[@class='info']/descendant::*[" . implode(' or ', $headingtags) . "][@class='categoryname'][./descendant::a[.=$categoryliteral]]";
$node = $this->find('xpath', $xpath, $exception);
$node->click();
+1 -1
View File
@@ -91,7 +91,7 @@ class behat_enrol extends behat_base {
if ($this->running_javascript()) {
// We have a div here, not a tr.
$userliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname);
$userliteral = behat_context_helper::escape($userfullname);
$userrowxpath = "//div[contains(concat(' ',normalize-space(@class),' '),' user ')][contains(., $userliteral)]";
$this->execute('behat_general::i_click_on_in_the',
@@ -227,8 +227,8 @@ class behat_gradingform_rubric extends behat_base {
*/
public function i_replace_rubric_level_with($currentvalue, $value, $criterionname) {
$currentvalueliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($currentvalue);
$criterionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($criterionname);
$currentvalueliteral = behat_context_helper::escape($currentvalue);
$criterionliteral = behat_context_helper::escape($criterionname);
$criterionxpath = "//div[@id='rubric-rubric']" .
"/descendant::td[contains(concat(' ', normalize-space(@class), ' '), ' description ')]";
@@ -488,7 +488,7 @@ class behat_gradingform_rubric extends behat_base {
* @return string
*/
protected function get_criterion_xpath($criterionname) {
$literal = $this->getSession()->getSelectorsHandler()->xpathLiteral($criterionname);
$literal = behat_context_helper::escape($criterionname);
return "//tr[contains(concat(' ', normalize-space(@class), ' '), ' criterion ')]" .
"[./descendant::td[@class='description'][text()=$literal]]";
}
+6 -6
View File
@@ -61,8 +61,8 @@ class behat_grading extends behat_base {
public function i_go_to_advanced_grading_definition_page($activityname) {
// Transforming to literals, probably not necessary, just in case.
$newactionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string("manageactionnew", "grading"));
$editactionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string("manageactionedit", "grading"));
$newactionliteral = behat_context_helper::escape(get_string("manageactionnew", "grading"));
$editactionliteral = behat_context_helper::escape(get_string("manageactionedit", "grading"));
// Working both when adding and editing.
$definitionxpath = "//a[@class='action']" .
@@ -85,7 +85,7 @@ class behat_grading extends behat_base {
$usergradetext = get_string('gradeuser', 'assign', $userfullname);
// Shortcut in case we already are in the grading page.
$usergradetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($usergradetext);
$usergradetextliteral = behat_context_helper::escape($usergradetext);
if ($this->getSession()->getPage()->find('named_partial', array('link', $usergradetextliteral))) {
$this->execute('behat_general::click_link', $this->escape($usergradetext));
@@ -123,14 +123,14 @@ class behat_grading extends behat_base {
*/
public function i_set_activity_to_use_grading_form($activityname, $templatename) {
$templateliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($templatename);
$templateliteral = behat_context_helper::escape($templatename);
$templatexpath = "//h2[@class='template-name'][contains(., $templateliteral)]/" .
"following-sibling::div[contains(concat(' ', normalize-space(@class), ' '), ' template-actions ')]";
// Should work with both templates and own forms.
$literaltemplate = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('templatepick', 'grading'));
$literalownform = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('templatepickownform', 'grading'));
$literaltemplate = behat_context_helper::escape(get_string('templatepick', 'grading'));
$literalownform = behat_context_helper::escape(get_string('templatepickownform', 'grading'));
$usetemplatexpath = "/a[./descendant::div[text()=$literaltemplate]]|" .
"/a[./descendant::div[text()=$literalownform]]";
@@ -106,7 +106,7 @@ class behat_gradereport_grader extends behat_base {
}
} else {
// If there isn't a form field, just search for contents.
$valueliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($value);
$valueliteral = behat_context_helper::escape($value);
$xpath = $this->get_student_and_grade_cell_selector($student, $itemname);
$xpath .= "[contains(normalize-space(.)," . $valueliteral . ")]";
+8 -8
View File
@@ -73,7 +73,7 @@ class behat_grade extends behat_base {
*/
public function i_set_the_following_settings_for_grade_item($gradeitem, TableNode $data) {
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
@@ -83,7 +83,7 @@ class behat_grade extends behat_base {
}
$savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('edit') . ' ');
$edit = behat_context_helper::escape(get_string('edit') . ' ');
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
@@ -102,7 +102,7 @@ class behat_grade extends behat_base {
*/
public function i_set_calculation_for_grade_item_with_idnumbers($calculation, $gradeitem, TableNode $data) {
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradeitem)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
@@ -113,7 +113,7 @@ class behat_grade extends behat_base {
// Going to edit calculation.
$savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
@@ -147,8 +147,8 @@ class behat_grade extends behat_base {
*/
public function i_set_calculation_for_grade_category_with_idnumbers($calculation, $gradeitem, TableNode $data) {
$gradecategorytotal = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem . ' total');
$gradeitem = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$gradecategorytotal = behat_context_helper::escape($gradeitem . ' total');
$gradeitem = behat_context_helper::escape($gradeitem);
if ($this->running_javascript()) {
$xpath = "//tr[contains(.,$gradecategorytotal)]//*[contains(@class,'moodle-actionmenu')]" .
@@ -160,7 +160,7 @@ class behat_grade extends behat_base {
// Going to edit calculation.
$savechanges = get_string('savechanges', 'grades');
$edit = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('editcalculation', 'grades'));
$edit = behat_context_helper::escape(get_string('editcalculation', 'grades'));
$linkxpath = "//a[./img[starts-with(@title,$edit) and contains(@title,$gradeitem)]]";
$this->execute("behat_general::i_click_on", array($this->escape($linkxpath), "xpath_element"));
@@ -197,7 +197,7 @@ class behat_grade extends behat_base {
$steps = array();
if ($this->running_javascript()) {
$gradeitemliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($gradeitem);
$gradeitemliteral = behat_context_helper::escape($gradeitem);
$xpath = "//tr[contains(.,$gradeitemliteral)]//*[contains(@class,'moodle-actionmenu')]//a[contains(@class,'toggle-display')]";
if ($this->getSession()->getPage()->findAll('xpath', $xpath)) {
$this->execute("behat_general::i_click_on", array($this->escape($xpath), "xpath_element"));
+2 -2
View File
@@ -49,10 +49,10 @@ class behat_groups extends behat_base {
*/
public function i_add_user_to_group_members($userfullname, $groupname) {
$userfullname = $this->getSession()->getSelectorsHandler()->xpathLiteral($userfullname);
$userfullname = behat_context_helper::escape($userfullname);
// Using a xpath liternal to avoid problems with quotes and double quotes.
$groupname = $this->getSession()->getSelectorsHandler()->xpathLiteral($groupname);
$groupname = behat_context_helper::escape($groupname);
// We don't know the option text as it contains the number of users in the group.
$select = $this->find_field('groups');
+1 -1
View File
@@ -253,7 +253,7 @@ class behat_base extends Behat\MinkExtension\Context\RawMinkContext {
return $this->find('named_partial',
array(
$cleanname,
$this->getSession()->getSelectorsHandler()->xpathLiteral($arguments[0])
behat_context_helper::escape($arguments[0])
)
);
}
+3 -3
View File
@@ -72,7 +72,7 @@ class behat_files extends behat_base {
);
} else {
// Gets the ffilemanager node specified by the locator which contains the filepicker container.
$filepickerelement = $this->getSession()->getSelectorsHandler()->xpathLiteral($filepickerelement);
$filepickerelement = behat_context_helper::escape($filepickerelement);
$filepickercontainer = $this->find(
'xpath',
"//input[./@id = //label[normalize-space(.)=$filepickerelement]/@for]" .
@@ -133,7 +133,7 @@ class behat_files extends behat_base {
$exception = new ExpectationException($exceptionmsg, $this->getSession());
// Avoid quote-related problems.
$name = $this->getSession()->getSelectorsHandler()->xpathLiteral($name);
$name = behat_context_helper::escape($name);
// Get a filepicker/filemanager element (folder or file).
try {
@@ -205,7 +205,7 @@ class behat_files extends behat_base {
$repoexception = new ExpectationException('The "' . $repositoryname . '" repository has not been found', $this->getSession());
// Avoid problems with both double and single quotes in the same string.
$repositoryname = $this->getSession()->getSelectorsHandler()->xpathLiteral($repositoryname);
$repositoryname = behat_context_helper::escape($repositoryname);
// Here we don't need to look inside the selected element because there can only be one modal window.
$repositorylink = $this->find(
@@ -44,6 +44,12 @@ class behat_context_helper {
*/
protected static $environment = null;
/**
* @var Escaper::escapeLiteral
*/
protected static $escaper;
/**
* Sets the browser session.
*
@@ -73,4 +79,17 @@ class behat_context_helper {
return $subcontext;
}
/**
* Translates string to XPath literal.
*
* @param string $label label to escape
* @return string escaped string.
*/
public static function escape($label) {
if (empty(self::$escaper)) {
self::$escaper = new \Behat\Mink\Selector\Xpath\Escaper();
}
return self::$escaper->escapeLiteral($label);
}
}
+1 -1
View File
@@ -157,7 +157,7 @@ XPATH
$locator = $element;
} else {
// Named selectors uses arrays as locators including the type of named selector.
$locator = array($selectortype, $session->getSelectorsHandler()->xpathLiteral($element));
$locator = array($selectortype, behat_context_helper::escape($element));
$selector = 'named_partial';
}
@@ -74,7 +74,7 @@ class behat_form_availability extends behat_form_textarea {
// Set a grouping condition.
$driver->click('//div[@class="availability-button"]/button');
$driver->click('//button[@id="availability_addrestriction_grouping"]');
$escparam = $this->session->getSelectorsHandler()->xpathLiteral($param);
$escparam = behat_context_helper::escape($param);
$nodes = $driver->find(
'//span[contains(concat(" " , @class, " "), " availability_grouping ")]//' .
'option[normalize-space(.) = ' . $escparam . ']');
+1 -1
View File
@@ -221,7 +221,7 @@ class behat_form_select extends behat_form_field {
* @return string xpath
*/
protected function get_option_xpath($option, $selectxpath) {
$valueliteral = $this->session->getSelectorsHandler()->xpathLiteral(trim($option));
$valueliteral = behat_context_helper::escape(trim($option));
return $selectxpath . "/descendant::option[(./@value=$valueliteral or normalize-space(.)=$valueliteral)]";
}
}
+7 -7
View File
@@ -540,7 +540,7 @@ class behat_general extends behat_base {
// Looking for all the matching nodes without any other descendant matching the
// same xpath (we are using contains(., ....).
$xpathliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$xpathliteral = behat_context_helper::escape($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
@@ -590,7 +590,7 @@ class behat_general extends behat_base {
// Looking for all the matching nodes without any other descendant matching the
// same xpath (we are using contains(., ....).
$xpathliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$xpathliteral = behat_context_helper::escape($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
@@ -648,7 +648,7 @@ class behat_general extends behat_base {
// Looking for all the matching nodes without any other descendant matching the
// same xpath (we are using contains(., ....).
$xpathliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$xpathliteral = behat_context_helper::escape($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
@@ -702,7 +702,7 @@ class behat_general extends behat_base {
// Looking for all the matching nodes without any other descendant matching the
// same xpath (we are using contains(., ....).
$xpathliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$xpathliteral = behat_context_helper::escape($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
@@ -1128,9 +1128,9 @@ class behat_general extends behat_base {
$tablenode = $this->get_selected_node('table', $table);
$tablexpath = $tablenode->getXpath();
$rowliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($row);
$valueliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($value);
$columnliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($column);
$rowliteral = behat_context_helper::escape($row);
$valueliteral = behat_context_helper::escape($value);
$columnliteral = behat_context_helper::escape($column);
if (preg_match('/^-?(\d+)-?$/', $column, $columnasnumber)) {
// Column indicated as a number, just use it as position of the column.
+5 -5
View File
@@ -60,7 +60,7 @@ class behat_navigation extends behat_base {
$exception = new ExpectationException($exception, $this->getSession());
}
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($text);
$nodetextliteral = behat_context_helper::escape($text);
$hasblocktree = "[contains(concat(' ', normalize-space(@class), ' '), ' block_tree ')]";
$hasbranch = "[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]";
$hascollapsed = "li[@aria-expanded='false']";
@@ -274,7 +274,7 @@ class behat_navigation extends behat_base {
// If node is a link then some driver click in the middle of the node, which click on link and
// page gets redirected. To ensure expansion works in all cases, check if the node to expand is a
// link and if yes then click on link and wait for it to navigate to next page with node expanded.
$nodetoexpandliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($parentnodes[$i]);
$nodetoexpandliteral = behat_context_helper::escape($parentnodes[$i]);
$nodetoexpandxpathlink = $xpath . "/a[normalize-space(.)=" . $nodetoexpandliteral . "]";
if ($nodetoexpandlink = $node->find('xpath', $nodetoexpandxpathlink)) {
@@ -297,7 +297,7 @@ class behat_navigation extends behat_base {
}
// Finally, click on requested node under navigation.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$nodetextliteral = behat_context_helper::escape($nodetext);
$xpath = "/ul/li/p[contains(concat(' ', normalize-space(@class), ' '), ' tree_item ')]" .
"/a[normalize-space(.)=" . $nodetextliteral . "]";
$nodetoclick = $node->find('xpath', $xpath);
@@ -321,7 +321,7 @@ class behat_navigation extends behat_base {
protected function get_top_navigation_node($nodetext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$nodetextliteral = behat_context_helper::escape($nodetext);
$exception = new ExpectationException('Top navigation node "' . $nodetext . ' not found in "', $this->getSession());
// First find in navigation block.
@@ -365,7 +365,7 @@ class behat_navigation extends behat_base {
protected function get_navigation_node($nodetext, $parentnode = null) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($nodetext);
$nodetextliteral = behat_context_helper::escape($nodetext);
$xpath = "/ul/li[contains(concat(' ', normalize-space(@class), ' '), ' contains_branch ')]" .
"[child::p[contains(concat(' ', normalize-space(@class), ' '), ' branch ')]" .
+2
View File
@@ -106,6 +106,8 @@ information provided here is intended especially for developers.
* Changes in file_rewrite_pluginfile_urls: Passing a new option reverse = true in the $options var will make the function to convert
actual URLs in $text to encoded URLs in the @@PLUGINFILE@@ form.
* behat_util::is_server_running() is removed, please use behat_util::check_server_status() instead.
* Behat\Mink\Selector\SelectorsHandler::xpathLiteral() method is deprecated use behat_context_helper::escape instead
when building Xpath, or pass the unescaped value when using the named selector.',
=== 3.0 ===
+2 -2
View File
@@ -557,8 +557,8 @@ class behat_mod_quiz extends behat_question_base {
public function i_should_see_question_in_section_in_the_quiz_navigation($questionnumber, $sectionheading) {
// Using xpath literal to avoid quotes problems.
$questionnumberliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral('Question ' . $questionnumber);
$headingliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($sectionheading);
$questionnumberliteral = behat_context_helper::escape('Question ' . $questionnumber);
$headingliteral = behat_context_helper::escape($sectionheading);
// Split in two checkings to give more feedback in case of exception.
$exception = new ExpectationException('Question "' . $questionnumber . '" is not in section "' .
@@ -50,7 +50,7 @@ class behat_workshopallocation_manual extends behat_base {
* @param string $participantname
*/
public function i_add_a_reviewer_for_workshop_participant($reviewername, $participantname) {
$participantnameliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participantname);
$participantnameliteral = behat_context_helper::escape($participantname);
$xpathtd = "//table[contains(concat(' ', normalize-space(@class), ' '), ' allocations ')]/".
"tbody/tr[./td[contains(concat(' ', normalize-space(@class), ' '), ' peer ')]".
"[contains(.,$participantnameliteral)]]/".
@@ -68,14 +68,14 @@ class behat_workshopallocation_manual extends behat_base {
if (!$this->running_javascript()) {
// Without Javascript we need to press the "Go" button.
$go = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('go'));
$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(self::EXTENDED_TIMEOUT, self::PAGE_READY_JS);
}
// Check the success string to appear.
$allocatedtext = $this->getSession()->getSelectorsHandler()->xpathLiteral(
$allocatedtext = behat_context_helper::escape(
get_string('allocationadded', 'workshopallocation_manual'));
$this->find('xpath', "//*[contains(.,$allocatedtext)]");
}
@@ -47,8 +47,8 @@ class behat_mod_workshop extends behat_base {
*/
public function i_change_phase_in_workshop_to($workshopname, $phase) {
$workshopname = $this->escape($workshopname);
$phaseliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($phase);
$switchphase = $this->getSession()->getSelectorsHandler()->xpathLiteral(get_string('switchphase', 'workshop'));
$phaseliteral = behat_context_helper::escape($phase);
$switchphase = behat_context_helper::escape(get_string('switchphase', 'workshop'));
$xpath = "//*[@class='userplan']/descendant::div[./span[contains(.,$phaseliteral)]]/".
"descendant-or-self::a[./img[@alt=$switchphase]]";
@@ -113,7 +113,7 @@ class behat_mod_workshop extends behat_base {
*/
public function i_assess_submission_in_workshop_as($submission, $workshopname, TableNode $table) {
$workshopname = $this->escape($workshopname);
$submissionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($submission);
$submissionliteral = behat_context_helper::escape($submission);
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), ' assessment-summary ') ".
"and contains(.,$submissionliteral)]";
$assess = $this->escape(get_string('assess', 'workshop'));
@@ -139,9 +139,9 @@ class behat_mod_workshop extends behat_base {
* @param string $reviewer
*/
public function i_should_see_grade_for_workshop_participant_set_by_peer($grade, $participant, $reviewer) {
$participantliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($participant);
$reviewerliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($reviewer);
$gradeliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($grade);
$participantliteral = behat_context_helper::escape($participant);
$reviewerliteral = behat_context_helper::escape($reviewer);
$gradeliteral = behat_context_helper::escape($grade);
$participantselector = "contains(concat(' ', normalize-space(@class), ' '), ' participant ') ".
"and contains(.,$participantliteral)";
$trxpath = "//table/tbody/tr[td[$participantselector]]";
+2 -2
View File
@@ -72,8 +72,8 @@ class behat_question extends behat_question_base {
public function the_state_of_question_is_shown_as($questiondescription, $state) {
// Using xpath literal to avoid quotes problems.
$questiondescriptionliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($questiondescription);
$stateliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($state);
$questiondescriptionliteral = behat_context_helper::escape($questiondescription);
$stateliteral = behat_context_helper::escape($state);
// Split in two checkings to give more feedback in case of exception.
$exception = new ElementNotFoundException($this->getSession(), 'Question "' . $questiondescription . '" ');
+1 -1
View File
@@ -87,7 +87,7 @@ class behat_filepicker extends behat_files {
$this->getSession()
);
$folderliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($foldername);
$folderliteral = behat_context_helper::escape($foldername);
// We look both in the pathbar and in the contents.
try {