KickerFormatterTest.php in Facebook Instant Articles 8.2
File
tests/src/Kernel/Plugin/Field/FieldFormatter/KickerFormatterTest.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;
class KickerFormatterTest extends FormatterTestBase {
protected function setUp() : void {
parent::setUp();
$this->display
->setComponent($this->fieldName, [
'type' => 'fbia_kicker',
'settings' => [],
]);
$this->display
->save();
}
public function testKickerFormatter() {
$value_alpha = 'Here is some kicker test. Wonder why they call it a kicker?';
$value_beta = 'Another kicker, which should never be seen.';
$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_HEADER, $this->normalizerMock);
$this
->assertEquals($value_alpha, $article
->getHeader()
->getKicker()
->getPlainText());
}
}