ParagraphFormatterTest.php in Facebook Instant Articles 3.x
File
tests/src/Kernel/Plugin/Field/FieldFormatter/ParagraphFormatterTest.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;
use Facebook\InstantArticles\Elements\Paragraph;
class ParagraphFormatterTest extends FormatterTestBase {
protected function setUp() : void {
parent::setUp();
$this->display
->setComponent($this->fieldName, [
'type' => 'fbia_paragraph',
'settings' => [],
]);
$this->display
->save();
}
public function testParagraphFormatter() {
$value = 'I am a random value.';
$entity = EntityTest::create([]);
$entity->{$this->fieldName}->value = $value;
$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);
}
}