You are here

public function MappingFormTest::testMappingToEntityIdWarning in Feeds 8.3

Tests mapping to entity ID target without setting it as unique.

When adding a target to entity ID and set it is not as unique, a warning should get displayed, recommending to set the target as unique.

File

tests/src/Functional/Form/MappingFormTest.php, line 101

Class

MappingFormTest
@coversDefaultClass \Drupal\feeds\Form\MappingForm @group feeds

Namespace

Drupal\Tests\feeds\Functional\Form

Code

public function testMappingToEntityIdWarning() {
  $feed_type = $this
    ->createFeedType();

  // Add mapping to node ID.
  $edit = [
    'add_target' => 'nid',
  ];
  $this
    ->drupalPostForm('/admin/structure/feeds/manage/' . $feed_type
    ->id() . '/mapping', $edit, 'Save');

  // Now untick "unique".
  $edit = [
    'mappings[2][unique][value]' => 0,
  ];
  $this
    ->drupalPostForm(NULL, $edit, 'Save');

  // Assert that a message is being displayed.
  $this
    ->assertSession()
    ->pageTextContains('When mapping to the entity ID (ID), it is recommended to set it as unique.');

  // But ensure "unique" can get unticked for entity ID targets anyway.
  // Because this could perhaps be useful in advanced use cases.
  $feed_type = $this
    ->reloadEntity($feed_type);
  $mapping = $feed_type
    ->getMappings()[2];
  $this
    ->assertTrue(empty($mapping['unique']['value']));
}