public function BasicFieldSourceTest::testImportWithTextfieldSource in Feeds 8.3
Tests importing using a text field source.
File
- tests/
src/ Kernel/ Feeds/ Source/ BasicFieldSourceTest.php, line 20
Class
- BasicFieldSourceTest
- @coversDefaultClass \Drupal\feeds\Feeds\Source\BasicFieldSource @group feeds
Namespace
Drupal\Tests\feeds\Kernel\Feeds\SourceCode
public function testImportWithTextfieldSource() {
$feed_type = $this
->createFeedType([
'fetcher' => 'directory',
'fetcher_configuration' => [
'allowed_extensions' => 'csv',
],
'parser' => 'csv',
'custom_sources' => [
'guid' => [
'label' => 'guid',
'value' => 'guid',
'machine_name' => 'guid',
],
],
'mappings' => [
[
'target' => 'feeds_item',
'map' => [
'guid' => 'guid',
],
'unique' => [
'guid' => TRUE,
],
],
[
'target' => 'title',
'map' => [
'value' => 'parent:alpha',
],
],
],
]);
// Add a field to this feed type.
$this
->createFieldWithStorage('alpha', [
'entity_type' => 'feeds_feed',
'bundle' => $feed_type
->id(),
]);
// Import a feed.
$feed = $this
->createFeed($feed_type
->id(), [
'alpha' => [
0 => [
'value' => 'Dolor Sit Amet',
],
],
'source' => $this
->resourcesPath() . '/csv/content.csv',
]);
$feed
->import();
// Assert that two nodes were imported with the title 'Dolor Sit Amet'.
$node1 = Node::load(1);
$this
->assertEquals('Dolor Sit Amet', $node1
->getTitle());
$node2 = Node::load(2);
$this
->assertEquals('Dolor Sit Amet', $node2
->getTitle());
}