function BrowserTest::testXPathEscaping

Tests XPath escaping.

File

drupal/core/modules/simpletest/lib/Drupal/simpletest/Tests/BrowserTest.php, line 54
Definition of Drupal\simpletest\Tests\BrowserTest.

Class

BrowserTest
Test internal testing framework browser.

Namespace

Drupal\simpletest\Tests

Code

function testXPathEscaping() {
  $testpage = <<<EOF
<html>
<body>
<a href="link1">A "weird" link, just to bother the dumb "XPath 1.0"</a>
<a href="link2">A second "even more weird" link, in memory of George O'Malley</a>
</body>
</html>
EOF;
  $this
    ->drupalSetContent($testpage);

  // Matches the first link.
  $urls = $this
    ->xpath('//a[text()=:text]', array(
    ':text' => 'A "weird" link, just to bother the dumb "XPath 1.0"',
  ));
  $this
    ->assertEqual($urls[0]['href'], 'link1', 'Match with quotes.');
  $urls = $this
    ->xpath('//a[text()=:text]', array(
    ':text' => 'A second "even more weird" link, in memory of George O\'Malley',
  ));
  $this
    ->assertEqual($urls[0]['href'], 'link2', 'Match with mixed single and double quotes.');
}