FormatterTestBase.php in Facebook Instant Articles 8.2
File
tests/src/Kernel/Plugin/Field/FieldFormatter/FormatterTestBase.php
View source
<?php
namespace Drupal\Tests\fb_instant_articles\Kernel\Plugin\Field\FieldFormatter;
use Drupal\Core\Entity\Entity\EntityViewDisplay;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
abstract class FormatterTestBase extends KernelTestBase {
protected static $modules = [
'user',
'field',
'fb_instant_articles',
'entity_test',
'system',
'serialization',
'user',
];
protected $entityType;
protected $bundle;
protected $fieldName;
protected $display;
protected $normalizerMock;
protected function setUp() : void {
parent::setUp();
$this
->installConfig([
'system',
'field',
]);
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$this->normalizerMock = $this
->createMock(NormalizerInterface::class);
$this->entityType = 'entity_test';
$this->bundle = $this->entityType;
$this->fieldName = mb_strtolower($this
->randomMachineName());
$field_storage = FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => $this->entityType,
'type' => $this
->getFieldType(),
]);
$field_storage
->save();
$instance = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => $this->bundle,
'label' => $this
->randomMachineName(),
]);
$instance
->save();
$this->display = EntityViewDisplay::create([
'targetEntityType' => $this->entityType,
'bundle' => $this->bundle,
'mode' => 'default',
'status' => TRUE,
]);
}
protected function getFieldType() {
return 'string';
}
}