You are here

public function ConfigEntityReferenceTest::testImportByLabel in Feeds 8.3

Tests importing config entity references by label.

File

tests/src/Kernel/Feeds/Target/ConfigEntityReferenceTest.php, line 98

Class

ConfigEntityReferenceTest
Tests for the config entity reference target.

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testImportByLabel() {

  // Create a feed type, map to created field.
  $feed_type = $this
    ->createFeedTypeForCsv([
    'guid' => 'guid',
    'title' => 'title',
    'alpha' => 'alpha',
  ], [
    'mappings' => array_merge($this
      ->getDefaultMappings(), [
      [
        'target' => 'field_entity_test_type',
        'map' => [
          'target_id' => 'alpha',
        ],
        'settings' => [
          'reference_by' => 'label',
        ],
      ],
    ]),
  ]);

  // Import.
  $feed = $this
    ->createFeed($feed_type
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content.csv',
  ]);
  $feed
    ->import();

  // Assert two created nodes.
  $this
    ->assertNodeCount(2);

  // Test target id values of these nodes.
  $expected_values = [
    1 => 'test',
    2 => 'test2',
  ];
  foreach ($expected_values as $nid => $expected_value) {
    $node = Node::load($nid);
    $this
      ->assertEquals($expected_value, $node->field_entity_test_type->target_id);
  }
}