You are here

public function FeedsItemUrlFormatterTest::testFeedsItemUrlFormatter in Feeds 8.3

Test the feeds item url formatter.

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

@dataProvider providerUrls

File

tests/src/Functional/Plugin/Field/FieldFormatter/FeedsItemUrlFormatterTest.php, line 19

Class

FeedsItemUrlFormatterTest
Tests feeds_item_url field formatter.

Namespace

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

Code

public function testFeedsItemUrlFormatter($input, $expected) {

  // Set display mode for feeds_item to feeds_item_url on article content
  // type.
  $this->container
    ->get('entity_display.repository')
    ->getViewDisplay('node', 'article', 'default')
    ->setComponent('feeds_item', [
    'type' => 'feeds_item_url',
    'settings' => [
      'url_plain' => FALSE,
    ],
    'weight' => 1,
  ])
    ->save();
  $feed = $this
    ->createCsvFeed();

  // Setup the article with test url.
  $article = $this
    ->createNodeWithFeedsItem($feed);
  $article->feeds_item->url = $input;

  // Display the article and test we are getting correct output for url.
  $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 {

    // If nothing is expected to be displayed, check if the field is rendered
    // at all.
    $this
      ->assertFeedsItemFieldNotDisplayed($rendered_content, $input);
  }
}