CreditsFormatterTest.php in Facebook Instant Articles 3.x
File
tests/src/Kernel/Plugin/Field/FieldFormatter/CreditsFormatterTest.php
View source
<?php
namespace Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\fb_instant_articles\Regions;
use Facebook\InstantArticles\Elements\InstantArticle;
class CreditsFormatterTest extends FormatterTestBase {
protected function setUp() : void {
parent::setUp();
$this->display
->setComponent($this->fieldName, [
'type' => 'fbia_credits',
'settings' => [],
]);
$this->display
->save();
}
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,
];
$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());
}
}