You are here

public function EntityProcessorBaseTest::testMapWithEmptySource in Feeds 8.3

@covers ::map

File

tests/src/Kernel/Feeds/Processor/EntityProcessorBaseTest.php, line 381

Class

EntityProcessorBaseTest
@coversDefaultClass \Drupal\feeds\Feeds\Processor\EntityProcessorBase @group feeds

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Processor

Code

public function testMapWithEmptySource() {

  // Create a new feed type mock.
  $feed_type = $this
    ->createMock(FeedTypeInterface::class);
  $feed_type
    ->expects($this
    ->once())
    ->method('getMappings')
    ->will($this
    ->returnValue([
    [
      'target' => 'title',
      'map' => [
        'value' => '',
      ],
    ],
  ]));

  // And set this on the processor.
  $this
    ->setProtectedProperty($this->processor, 'feedType', $feed_type);

  // Instantiate target plugin.
  $field_definition = $this
    ->createMock(FieldDefinitionInterface::class);
  $definition = FieldTargetDefinition::createFromFieldDefinition($field_definition)
    ->addProperty('value');
  $target = new StringTarget([
    'feed_type' => $feed_type,
    'target_definition' => $definition,
  ], 'string', [
    'id' => 'string',
    'field_types' => [
      'string',
      'string_long',
      'list_string',
    ],
  ]);

  // And let the feed type always return this plugin.
  $feed_type
    ->expects($this
    ->exactly(2))
    ->method('getTargetPlugin')
    ->will($this
    ->returnValue($target));

  // Map.
  $this
    ->callProtectedMethod($this->processor, 'map', [
    $this->feed,
    $this
      ->createMock(EntityInterface::class),
    $this
      ->createMock(ItemInterface::class),
  ]);
}