public function XmlTest::testBasicXmlParsing in Views XML Backend 8
File
- tests/
src/ Unit/ Plugin/ views/ query/ XmlTest.php, line 83 - Contains \Drupal\Tests\views_xml_backend\Unit\Plugin\views\query\XmlTest.
Class
- XmlTest
- @coversDefaultClass \Drupal\views_xml_backend\Plugin\views\query\Xml @group views_xml_backend
Namespace
Drupal\Tests\views_xml_backend\Unit\Plugin\views\queryCode
public function testBasicXmlParsing() {
$xml = <<<XML
<foo>
<bar><value>1</value></bar>
<bar><value>2</value></bar>
<bar><value>3</value></bar>
<bar><value>4</value></bar>
</foo>
XML;
$mock = new MockHandler([
new Response(200, [], $xml),
]);
$handler = HandlerStack::create($mock);
$this->client = new Client([
'handler' => $handler,
]);
$query = $this
->getNewQueryObject([
'xml_file' => 'http://example.com',
'row_xpath' => '/foo/bar',
]);
$view = $this
->getMockedView();
// Fake the fields.
$view->field['field_1'] = (object) [
'options' => [
'xpath_selector' => 'value',
],
];
$query
->build($view);
$query
->execute($view);
// Check for no errors.
$this
->assertSame(0, count($this->messenger
->getMessages()));
$this
->assertSame(4, count($view->result));
foreach ($view->result as $index => $row) {
$this
->assertSame($index, $row->index);
$value = (string) ($index + 1);
$this
->assertSame([
0 => $value,
], $row->field_1);
}
}