public function CreditsFormatterTest::testCreditsFormatter in Facebook Instant Articles 8.2
Same name and namespace in other branches
- 3.x tests/src/Kernel/Plugin/Field/FieldFormatter/CreditsFormatterTest.php \Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter\CreditsFormatterTest::testCreditsFormatter()
Test the instant article credits formatter.
File
- tests/
src/ Kernel/ Plugin/ Field/ FieldFormatter/ CreditsFormatterTest.php, line 33
Class
- CreditsFormatterTest
- Tests the CreditsFormatter.
Namespace
Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatterCode
public function testCreditsFormatter() {
$value_alpha = 'Here are some credits.';
$value_beta = 'Moar credits.';
$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_FOOTER, $this->normalizerMock);
$credits = $article
->getFooter()
->getCredits();
$this
->assertEquals(2, count($credits));
$this
->assertEquals($value_alpha, $credits[0]
->getPlainText());
$this
->assertEquals($value_beta, $credits[1]
->getPlainText());
}