public function SubtitleFormatterTest::testSubtitleFormatterTextLong in Facebook Instant Articles 3.x
Same name and namespace in other branches
- 8.2 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\FieldFormatterCode
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);
}