You are here

public function AuthorFormatterTest::testAuthorFormatter in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 tests/src/Kernel/Plugin/Field/FieldFormatter/AuthorFormatterTest.php \Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter\AuthorFormatterTest::testAuthorFormatter()

Test the instant article author formatter.

File

tests/src/Kernel/Plugin/Field/FieldFormatter/AuthorFormatterTest.php, line 34

Class

AuthorFormatterTest
Tests the instant article author field formatter.

Namespace

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

Code

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,
  ];

  /** @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_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());
}