XMLXpathTest.php in GraphQL 8.4
File
tests/src/Kernel/DataProducer/XML/XMLXpathTest.php
View source
<?php
namespace Drupal\Tests\graphql\Kernel\DataProducer\XML;
class XMLXpathTest extends XMLTestBase {
public function testXmlXpath() : void {
$document = $this
->loadDocument();
$result = $this
->executeDataProducer('xml_xpath', [
'dom' => $document,
'query' => '//div/h1',
]);
$this
->assertEquals(1, count($result));
$this
->assertEquals('h1', $result[0]->tagName);
$result = $this
->executeDataProducer('xml_xpath', [
'dom' => $document,
'query' => '//div/div/div',
]);
$this
->assertEquals(3, count($result));
$this
->assertEquals('div', $result[0]->tagName);
$this
->assertEquals('div', $result[1]->tagName);
$this
->assertEquals('div', $result[2]->tagName);
$element = $this
->executeDataProducer('xml_xpath', [
'dom' => $document,
'query' => '//div/div/span',
]);
$result = $this
->executeDataProducer('xml_xpath', [
'dom' => $element[0],
'query' => './p',
]);
$this
->assertEquals(2, count($result));
$this
->assertEquals('p', $result[0]->tagName);
$this
->assertEquals('p', $result[1]->tagName);
$result = $this
->executeDataProducer('xml_xpath', [
'dom' => $document,
'query' => '//div/h2',
]);
$this
->assertSame(0, count($result));
}
}