You are here

public function TimestampTest::testWithConfig in Feeds 8.3

Tests importing date values with various configurations and formats.

@dataProvider withConfigProvider

Parameters

array $expected: The expected values.

string $source: The CSV source to use.

array $settings: The target configuration.

File

tests/src/Kernel/Feeds/Target/TimestampTest.php, line 79

Class

TimestampTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\Timestamp @group feeds

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testWithConfig(array $expected, $source, array $settings = []) {
  $this->feedType
    ->addMapping([
    'target' => 'created',
    'map' => [
      'value' => $source,
    ],
    'settings' => $settings,
  ]);
  $this->feedType
    ->save();

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

  // Assert three created nodes.
  $this
    ->assertNodeCount(3);
  foreach ($expected as $nid => $value) {
    $node = Node::load($nid);
    $this
      ->assertEquals($value, $node->created->value);
  }

  // Assert that the fourth entry failed to validate.
  $messages = \Drupal::messenger()
    ->messagesByType('warning');
  $this
    ->assertCount(1, $messages);
  $this
    ->assertStringContainsString('The content <em class="placeholder">Eodem modo typi</em> failed to validate', (string) $messages[0]);
  $this
    ->assertStringContainsString('created.0.value: This value should be of the correct primitive type.', (string) $messages[0]);
}