You are here

public function SubtitleFormatterTest::testSubtitleFormatterTextLong 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::testSubtitleFormatterTextLong()

Test the instant article subtitle formatter on a text_long field.

File

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

Class

SubtitleFormatterTest
Tests the SubtitleFormatterTest.

Namespace

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

Code

public function testSubtitleFormatterTextLong() {
  $value = '<p>Inspiring <strong>subtitle</strong> to set <a href="https://en.wikipedia.org/wiki/Tone_(literature)">the tone</a>.</p>';
  $entity = EntityTest::create([]);
  $entity->{$this->textFieldName}[] = [
    'value' => $value,
    'format' => 'full_html',
  ];

  /** @var \Drupal\fb_instant_articles\Plugin\Field\InstantArticleFormatterInterface $formatter */
  $formatter = $this->display
    ->getRenderer($this->textFieldName);
  $article = InstantArticle::create();
  $formatter
    ->viewInstantArticle($entity->{$this->textFieldName}, $article, Regions::REGION_HEADER, $this->normalizerMock);
  $subtitle = $article
    ->getHeader()
    ->getSubtitle();
  $subtitle_dom = $subtitle
    ->toDOMElement();
  $actual_string = $subtitle_dom->ownerDocument
    ->saveHTML($subtitle_dom);
  $this
    ->assertEquals('<h2>Inspiring <b>subtitle</b> to set <a href="https://en.wikipedia.org/wiki/Tone_(literature)">the tone</a>.</h2>', $actual_string);
}