You are here

public function CopyrightFormatterTest::testCopyrightFormatter in Facebook Instant Articles 3.x

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

Test the instant article copyright formatter.

File

tests/src/Kernel/Plugin/Field/FieldFormatter/CopyrightFormatterTest.php, line 35

Class

CopyrightFormatterTest
Tests the CopyrightFormatter.

Namespace

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

Code

public function testCopyrightFormatter() {
  $value_alpha = 'Copyright very important information ahead.';
  $value_beta = 'So much information, you won\'t read it.';
  $entity = EntityTest::create([]);
  $entity->{$this->fieldName}[] = [
    'value' => $value_alpha,
  ];

  /** @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);
  $this
    ->assertEquals($value_alpha, $article
    ->getFooter()
    ->getCopyright());
  $entity->{$this->fieldName}[] = [
    'value' => $value_beta,
  ];
  $article = InstantArticle::create();
  $formatter
    ->viewInstantArticle($entity->{$this->fieldName}, $article, Regions::REGION_FOOTER, $this->normalizerMock);
  $this
    ->assertEquals($value_alpha . ' ' . $value_beta, $article
    ->getFooter()
    ->getCopyright());
  $article = InstantArticle::create();
  $article
    ->withFooter(Footer::create()
    ->withCopyright(Small::create()
    ->appendText($value_alpha)));
  $formatter
    ->viewInstantArticle($entity->{$this->fieldName}, $article, Regions::REGION_FOOTER, $this->normalizerMock);
  $this
    ->assertEquals($value_alpha . ' ' . $value_beta, $article
    ->getFooter()
    ->getCopyright());
}