You are here

public function FeedsItemTargetIdFormatterTest::testFeedsItemTargetIdFormatter in Feeds 8.3

Tests the feeds target id formatter.

@covers \Drupal\feeds\Plugin\Field\FieldFormatter\FeedsItemTargetIdFormatter::viewElements

@dataProvider providerTargetIds

File

tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemTargetIdFormatterTest.php, line 36

Class

FeedsItemTargetIdFormatterTest
Tests feeds_item_target_id field formatter.

Namespace

Drupal\Tests\feeds\Functional\Plugin\Field\FieldFormatter

Code

public function testFeedsItemTargetIdFormatter($input, $expected) {
  $feed = $this
    ->createCsvFeed();

  // Create an article with and set the 'target_id' property on the feeds item
  // field.
  $article = $this
    ->createNodeWithFeedsItem($feed);
  $article->feeds_item->target_id = $input;

  // Display the article and test we are getting correct output for target id.
  $display = $this->container
    ->get('entity_display.repository')
    ->getViewDisplay($article
    ->getEntityTypeId(), $article
    ->bundle(), 'default');
  $content = $display
    ->build($article);
  $rendered_content = $this->container
    ->get('renderer')
    ->renderRoot($content);
  if ($expected) {
    $this
      ->assertStringContainsString($expected, (string) $rendered_content);
  }
  else {

    // Make sure no field item is rendered with empty input.
    $this
      ->assertFeedsItemFieldNotDisplayed($rendered_content, $input);
  }
}