Commit 6a63383a authored by Son Nguyen's avatar Son Nguyen

Replace the desprecated method SelectorsHandler::xpathLiteral()

Bug 1424817

Change-Id: I83aa04d6a5f63a7b1dbc102eb6d2060afc5cf447
Signed-off-by: default avatarSon Nguyen <son.nguyen@catalyst.net.nz>
parent e0170e35
......@@ -17,7 +17,8 @@
use Behat\Mink\Exception\ExpectationException as ExpectationException,
Behat\Mink\Exception\ElementNotFoundException as ElementNotFoundException,
Behat\Mink\Element\NodeElement as NodeElement;
Behat\Mink\Element\NodeElement as NodeElement,
Behat\Mink\Selector\Xpath\Escaper;
/**
* Base class
......@@ -54,6 +55,18 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
*/
const PAGE_READY_JS = '(SubmittingPieforms && SubmittingPieforms.length === 0) && (document.readyState === "complete")';
/**
* @var Escaper
*/
public $escaper;
/**
* Instantiates the base class
*/
public function __construct() {
$this->escaper = new Escaper();
}
/**
* Locates url, based on provided path.
* Override to provide custom routing mechanism.
......@@ -206,7 +219,7 @@ class BehatBase extends Behat\MinkExtension\Context\RawMinkContext {
return $this->find('named',
array(
$cleanname,
$this->getSession()->getSelectorsHandler()->xpathLiteral($arguments[0])
$this->escaper->escapeLiteral($arguments[0])
)
);
}
......
......@@ -328,7 +328,7 @@ class BehatGeneral extends BehatBase {
public function i_click_on_in_row($link_or_button, $rowtext) {
// The table row container.
$rowtextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($rowtext);
$rowtextliteral = $this->escaper->escapeLiteral($rowtext);
$exception = new ElementNotFoundException($this->getSession(), 'text', null, 'the row containing the text "' . $rowtext . '"');
$xpath = "//div[contains(concat(' ', normalize-space(@class), ' '), concat(' ', 'listrow', ' '))" .
" and contains(normalize-space(.), " . $rowtextliteral . ")]" .
......@@ -483,7 +483,7 @@ class BehatGeneral extends BehatBase {
// 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 = $this->escaper->escapeLiteral($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
......@@ -534,7 +534,7 @@ class BehatGeneral extends BehatBase {
// 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 = $this->escaper->escapeLiteral($text);
$xpath = "/descendant-or-self::*[contains(., $xpathliteral)]" .
"[count(descendant::*[contains(., $xpathliteral)]) = 0]";
......
......@@ -42,7 +42,7 @@ class BehatNavigation extends BehatBase {
protected function get_main_menu_item_node($menuitemtext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($menuitemtext);
$nodetextliteral = $this->escaper->escapeLiteral($menuitemtext);
$exception = new ExpectationException('The menu item "' . $menuitemtext . ' not found or invisible in "', $this->getSession());
$xpath = "//div[@id='main-nav']" .
"/ul[@id='nav']" .
......@@ -63,7 +63,7 @@ class BehatNavigation extends BehatBase {
protected function get_sub_menu_item_node($menuitemtext) {
// Avoid problems with quotes.
$nodetextliteral = $this->getSession()->getSelectorsHandler()->xpathLiteral($menuitemtext);
$nodetextliteral = $this->escaper->escapeLiteral($menuitemtext);
$exception = new ExpectationException('The menu item "' . $menuitemtext . ' not found or invisible in "', $this->getSession());
$xpath = "//div[@id='sub-nav']" .
"/ul" .
......
......@@ -9,6 +9,8 @@
*
*/
use Behat\Mink\Selector\Xpath\Escaper;
/**
* Mahara-specific selectors.
*/
......@@ -99,6 +101,7 @@ XPATH
*/
public static function get_behat_selector($selectortype, $element, Behat\Mink\Session $session) {
$escaper = new Escaper();
// CSS and XPath selectors locator is one single argument.
if ($selectortype == 'css_element' || $selectortype == 'xpath_element') {
$selector = str_replace('_element', '', $selectortype);
......@@ -106,7 +109,7 @@ XPATH
}
else {
// Named selectors uses arrays as locators including the type of named selector.
$locator = array($selectortype, $session->getSelectorsHandler()->xpathLiteral($element));
$locator = array($selectortype, $escaper->escapeLiteral($element));
$selector = 'named';
}
......
......@@ -331,7 +331,7 @@ class BehatFormSelect extends BehatFormField {
* @return string xpath
*/
protected function get_option_xpath($option, $selectxpath) {
$valueliteral = $this->session->getSelectorsHandler()->xpathLiteral(trim($option));
$valueliteral = $this->escaper->escapeLiteral(trim($option));
return $selectxpath . "/descendant::option[(./@value=$valueliteral or normalize-space(.)=$valueliteral)]";
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment