You are here

public function LinkTest::testImportUrl in Feeds 8.3

Tests importing urls.

File

tests/src/Kernel/Feeds/Target/LinkTest.php, line 62

Class

LinkTest
@coversDefaultClass \Drupal\feeds\Feeds\Target\Link @group feeds

Namespace

Drupal\Tests\feeds\Kernel\Feeds\Target

Code

public function testImportUrl() {

  // Import.
  $feed = $this
    ->createFeed($this->feedType
    ->id(), [
    'source' => $this
      ->resourcesPath() . '/csv/content_url.csv',
  ]);
  $feed
    ->import();
  $expected = [
    1 => 'http://example.com',
    2 => 'https://example.com',
    3 => 'internal:/node',
    4 => 'internal:/',
    5 => 'internal:/node',
    6 => 'route:<nolink>',
  ];
  foreach ($expected as $nid => $value) {
    $node = Node::load($nid);
    $this
      ->assertEquals($value, $node->field_link->uri);
  }

  // Assert that some entries failed to validate.
  $messages = \Drupal::messenger()
    ->messagesByType('warning');
  $this
    ->assertCount(2, $messages);
  $this
    ->assertStringContainsString('The content <em class="placeholder">Invalid url</em> failed to validate', (string) $messages[0]);
  $this
    ->assertStringContainsString("field_link.0: The path 'string' is invalid.", (string) $messages[0]);
  $this
    ->assertStringContainsString('The content <em class="placeholder">Another invalid url</em> failed to validate', (string) $messages[1]);
  $this
    ->assertStringContainsString('field_link.0.uri: This value should be of the correct primitive type.', (string) $messages[1]);
}