You are here

public function SubtitleFormatterTest::testSubtitleFormatter in Facebook Instant Articles 8.2

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

Test the instant article subtitle formatter.

File

tests/src/Kernel/Plugin/Field/FieldFormatter/SubtitleFormatterTest.php, line 80

Class

SubtitleFormatterTest
Tests the SubtitleFormatterTest.

Namespace

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

Code

public function testSubtitleFormatter() {
  $value_alpha = 'Inspiring subtitle to set the tone';
  $value_beta = 'Another subtitle, which should never be seen.';
  $entity = EntityTest::create([]);
  $entity->{$this->fieldName}[] = [
    'value' => $value_alpha,
  ];
  $entity->{$this->fieldName}[] = [
    'value' => $value_beta,
  ];

  /** @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_HEADER, $this->normalizerMock);
  $this
    ->assertEquals($value_alpha, $article
    ->getHeader()
    ->getSubtitle()
    ->getPlainText());
}