You are here

public function ParagraphFormatterTest::testParagraphFormatter in Facebook Instant Articles 3.x

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

Test the instant article paragraph formatter.

File

tests/src/Kernel/Plugin/Field/FieldFormatter/ParagraphFormatterTest.php, line 33

Class

ParagraphFormatterTest
Tests the instant article paragraph field formatter.

Namespace

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

Code

public function testParagraphFormatter() {
  $value = 'I am a random value.';
  $entity = EntityTest::create([]);
  $entity->{$this->fieldName}->value = $value;

  /** @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);
  $children = $article
    ->getChildren();
  $this
    ->assertEquals(1, count($children));
  $this
    ->assertTrue($children[0] instanceof Paragraph);
}