Skip to content
Snippets Groups Projects
Commit 852f0bdd authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2720869 by jibran: Remove the use of deprecated CssSelector and use...

Issue #2720869 by jibran: Remove the use of deprecated CssSelector and use CssSelectorConverter instead

(cherry picked from commit 2bef9564)
parent 5d126f16
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@
use Drupal\Component\Utility\SafeMarkup;
use Drupal\Component\Utility\Xss;
use Drupal\Core\Render\RenderContext;
use Symfony\Component\CssSelector\CssSelector;
use Symfony\Component\CssSelector\CssSelectorConverter;
/**
* Provides test methods to assert content.
......@@ -247,7 +247,7 @@ protected function xpath($xpath, array $arguments = []) {
* selector to an XPath selector.
*/
protected function cssSelect($selector) {
return $this->xpath(CssSelector::toXPath($selector));
return $this->xpath((new CssSelectorConverter())->toXPath($selector));
}
/**
......
......@@ -7,7 +7,7 @@
use Drupal\node\Entity\Node;
use Drupal\node\Entity\NodeType;
use Drupal\views\Tests\ViewTestBase;
use Symfony\Component\CssSelector\CssSelector;
use Symfony\Component\CssSelector\CssSelectorConverter;
/**
* Tests the rendering of fields (base fields) and their translations.
......@@ -171,8 +171,8 @@ protected function assertRows($expected = []) {
$rows = $this->cssSelect('div.views-row');
foreach ($rows as $row) {
$actual[] = [
'title' => (string) $row->xpath(CssSelector::toXPath('.views-field-title span.field-content a'))[0],
'sticky' => (string) $row->xpath(CssSelector::toXPath('.views-field-sticky span.field-content'))[0],
'title' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-title span.field-content a'))[0],
'sticky' => (string) $row->xpath((new CssSelectorConverter())->toXPath('.views-field-sticky span.field-content'))[0],
];
}
$this->assertEqual($actual, $expected);
......
......@@ -3,7 +3,6 @@
namespace Drupal\FunctionalJavascriptTests;
use Drupal\Tests\BrowserTestBase;
use Symfony\Component\CssSelector\CssSelector;
use Zumba\Mink\Driver\PhantomJSDriver;
/**
......@@ -46,7 +45,7 @@ protected function initMink() {
* \Behat\Mink\Element\NodeElement::isVisible() instead.
*/
protected function assertElementVisible($css_selector, $message = '') {
$this->assertTrue($this->getSession()->getDriver()->isVisible(CssSelector::toXPath($css_selector)), $message);
$this->assertTrue($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message);
}
/**
......@@ -61,7 +60,7 @@ protected function assertElementVisible($css_selector, $message = '') {
* \Behat\Mink\Element\NodeElement::isVisible() instead.
*/
protected function assertElementNotVisible($css_selector, $message = '') {
$this->assertFalse($this->getSession()->getDriver()->isVisible(CssSelector::toXPath($css_selector)), $message);
$this->assertFalse($this->getSession()->getDriver()->isVisible($this->cssSelectToXpath($css_selector)), $message);
}
/**
......
......@@ -23,7 +23,7 @@
use Drupal\user\Entity\Role;
use Drupal\user\Entity\User;
use Drupal\user\UserInterface;
use Symfony\Component\CssSelector\CssSelector;
use Symfony\Component\CssSelector\CssSelectorConverter;
use Symfony\Component\HttpFoundation\Request;
/**
......@@ -1447,7 +1447,7 @@ protected function drupalUserIsLoggedIn(UserInterface $account) {
* Optional message to show alongside the assertion.
*/
protected function assertElementPresent($css_selector, $message = '') {
$this->assertNotEmpty($this->getSession()->getDriver()->find(CssSelector::toXPath($css_selector)), $message);
$this->assertNotEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message);
}
/**
......@@ -1459,7 +1459,7 @@ protected function assertElementPresent($css_selector, $message = '') {
* Optional message to show alongside the assertion.
*/
protected function assertElementNotPresent($css_selector, $message = '') {
$this->assertEmpty($this->getSession()->getDriver()->find(CssSelector::toXPath($css_selector)), $message);
$this->assertEmpty($this->getSession()->getDriver()->find($this->cssSelectToXpath($css_selector)), $message);
}
/**
......@@ -1469,7 +1469,7 @@ protected function assertElementNotPresent($css_selector, $message = '') {
* The CSS selector identifying the element to click.
*/
protected function click($css_selector) {
$this->getSession()->getDriver()->click(CssSelector::toXPath($css_selector));
$this->getSession()->getDriver()->click($this->cssSelectToXpath($css_selector));
}
/**
......@@ -1529,4 +1529,23 @@ protected function getHtmlOutputHeaders() {
return '<hr />Headers: <pre>' . Html::escape(var_export($headers, TRUE)) . '</pre>';
}
/**
* Translates a CSS expression to its XPath equivalent.
*
* The search is relative to the root element (HTML tag normally) of the page.
*
* @param string $selector
* CSS selector to use in the search.
* @param bool $html
* (optional) Enables HTML support. Disable it for XML documents.
* @param string $prefix
* (optional) The prefix for the XPath expression.
*
* @return string
* The equivalent XPath of a CSS expression.
*/
protected function cssSelectToXpath($selector, $html = TRUE, $prefix = 'descendant-or-self::') {
return (new CssSelectorConverter($html))->toXPath($selector, $prefix);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment