View source
<?php
namespace Drupal\Tests\feeds_ex\FunctionalJavascript\Feeds\Parser;
use Drupal\feeds\Entity\Feed;
use Drupal\node\Entity\Node;
class HtmlParserTest extends ParserTestBase {
protected $parserId = 'html';
public function testMapCustomSource() {
$edit = [
'context' => '//div[@class="post"]',
];
$this
->addMappings($this->feedType
->id(), [
[
'target' => 'title',
'map' => [
'value' => [
'value' => 'h3',
'machine_name' => 'title_',
],
],
],
[
'target' => 'body',
'map' => [
'value' => [
'value' => 'p',
'machine_name' => 'body_',
],
],
],
], $edit);
$edit = [
'title[0][value]' => 'Feed 1',
'plugin[fetcher][source]' => $this
->resourcesUrl() . '/test.html',
];
$this
->drupalGet('/feed/add/' . $this->feedType
->id());
$this
->submitFormWithDropButton($edit, 'Save');
$feed = Feed::load(1);
$feed
->import();
$node1 = Node::load(1);
$this
->assertEquals('I am a title<thing>Stuff</thing>', $node1
->getTitle());
$this
->assertEquals('I am a description0', $node1->body->value);
$node2 = Node::load(2);
$this
->assertEquals('I am a title1', $node2
->getTitle());
$this
->assertEquals('I am a description1', $node2->body->value);
$node3 = Node::load(3);
$this
->assertEquals('I am a title2', $node3
->getTitle());
$this
->assertEquals('I am a description2', $node3->body->value);
}
}