AuthorFormatterTest.php in Facebook Instant Articles 8.2
File
tests/src/Kernel/Plugin/Field/FieldFormatter/AuthorFormatterTest.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\Author;
use Facebook\InstantArticles\Elements\InstantArticle;
class AuthorFormatterTest extends FormatterTestBase {
protected function setUp() : void {
parent::setUp();
$this->display
->setComponent($this->fieldName, [
'type' => 'fbia_author',
'settings' => [],
]);
$this->display
->save();
}
public function testAuthorFormatter() {
$value_alpha = 'Joe Mayo';
$value_beta = 'J. Peterman';
$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_CONTENT, $this->normalizerMock);
$authors = $article
->getHeader()
->getAuthors();
$this
->assertEquals(2, count($authors));
$this
->assertTrue($authors[0] instanceof Author);
$this
->assertEquals($value_alpha, $authors[0]
->getName());
$this
->assertEquals($value_beta, $authors[1]
->getName());
}
}