You are here

public function VideoFormatterTest::testVideoFormatterCanonicalUrl in Facebook Instant Articles 8.2

Same name and namespace in other branches
  1. 3.x tests/src/Kernel/Plugin/Field/FieldFormatter/VideoFormatterTest.php \Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter\VideoFormatterTest::testVideoFormatterCanonicalUrl()

Tests the instant article video formatter when a canonical URL is in play.

@covers ::viewInstantArticle

File

tests/src/Kernel/Plugin/Field/FieldFormatter/VideoFormatterTest.php, line 112

Class

VideoFormatterTest
Tests for the VideoFormatter.

Namespace

Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter

Code

public function testVideoFormatterCanonicalUrl() {
  $entity = EntityTest::create([]);

  // Handy method to populate the field with a real value.
  // @see FileItem::generateSampleValue()
  $entity->{$this->fieldName}
    ->generateSampleItems(1);

  // Test with a canonical URL set.
  $config = $this
    ->config('fb_instant_articles.settings');
  $config
    ->set('canonical_url_override', 'http://example.com/override')
    ->save();

  /** @var \Drupal\fb_instant_articles\Plugin\Field\InstantArticleFormatterInterface $formatter */
  $formatter = $this->display
    ->getRenderer($this->fieldName);
  $article = InstantArticle::create();
  $formatter
    ->viewInstantArticle($entity->{$this->fieldName}, $article, Regions::REGION_CONTENT, $this->normalizerMock);
  $children = $article
    ->getChildren();
  $this
    ->assertStringStartsWith('http://example.com/override', $children[0]
    ->getUrl());
}