View source
<?php
namespace Drupal\Tests\feeds_ex\FunctionalJavascript\Feeds\Parser;
use Drupal\feeds\Entity\Feed;
use Drupal\node\Entity\Node;
class XmlParserTest extends ParserTestBase {
protected $parserId = 'xml';
public function testMapCustomSource() {
$this
->createFieldWithStorage('field_alpha');
$edit = [
'context' => '//item',
];
$this
->addMappings($this->feedType
->id(), [
[
'target' => 'feeds_item',
'map' => [
'guid' => [
'value' => 'guid',
'machine_name' => 'guid_',
],
],
'unique' => [
'guid' => TRUE,
],
],
[
'target' => 'title',
'map' => [
'value' => [
'value' => 'title',
'machine_name' => 'title_',
],
],
],
[
'target' => 'body',
'map' => [
'value' => [
'value' => 'body',
'machine_name' => 'body_',
],
],
],
[
'target' => 'field_alpha',
'map' => [
'value' => [
'value' => 'alpha',
'machine_name' => 'alpha_',
],
],
],
], $edit);
$edit = [
'title[0][value]' => 'Feed 1',
'plugin[fetcher][source]' => $this
->resourcesUrl() . '/content.xml',
];
$this
->drupalGet('/feed/add/' . $this->feedType
->id());
$this
->submitFormWithDropButton($edit, 'Save');
$feed = Feed::load(1);
$feed
->import();
$node1 = Node::load(1);
$this
->assertEquals('1', $node1->feeds_item->guid);
$this
->assertEquals('Lorem ipsum', $node1
->getTitle());
$this
->assertEquals('Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.', $node1->body->value);
$this
->assertEquals('Lorem', $node1->field_alpha->value);
$node2 = Node::load(2);
$this
->assertEquals('2', $node2->feeds_item->guid);
$this
->assertEquals('Ut wisi enim ad minim veniam', $node2
->getTitle());
$this
->assertEquals('Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.', $node2->body->value);
$this
->assertEquals('Ut wisi', $node2->field_alpha->value);
}
}