View source
<?php
namespace Drupal\Tests\hal\Kernel;
use Drupal\field\Entity\FieldConfig;
use Drupal\language\Entity\ConfigurableLanguage;
use Drupal\KernelTests\KernelTestBase;
use Drupal\field\Entity\FieldStorageConfig;
abstract class NormalizerTestBase extends KernelTestBase {
protected static $modules = [
'entity_test',
'field',
'hal',
'language',
'serialization',
'system',
'text',
'user',
'filter',
];
protected $serializer;
protected $format = 'hal_json';
protected $entityClass = 'Drupal\\entity_test\\Entity\\EntityTest';
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
$class = static::class;
while ($class) {
if (property_exists($class, 'modules')) {
$rp = new \ReflectionProperty($class, 'modules');
if ($rp->class == $class) {
foreach (array_intersect([
'node',
'comment',
], $class::$modules) as $module) {
$this
->installEntitySchema($module);
}
}
}
$class = get_parent_class($class);
}
$this
->installConfig([
'field',
'language',
]);
ConfigurableLanguage::create([
'id' => 'de',
'label' => 'Deutsch',
'weight' => -1,
])
->save();
FieldStorageConfig::create([
'field_name' => 'field_test_text',
'entity_type' => 'entity_test',
'type' => 'text',
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_text',
'bundle' => 'entity_test',
'translatable' => FALSE,
])
->save();
FieldStorageConfig::create([
'field_name' => 'field_test_translatable_text',
'entity_type' => 'entity_test',
'type' => 'text',
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_translatable_text',
'bundle' => 'entity_test',
'translatable' => TRUE,
])
->save();
FieldStorageConfig::create([
'field_name' => 'field_test_entity_reference',
'entity_type' => 'entity_test',
'type' => 'entity_reference',
'settings' => [
'target_type' => 'entity_test',
],
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test',
'field_name' => 'field_test_entity_reference',
'bundle' => 'entity_test',
'translatable' => TRUE,
])
->save();
$this->serializer = $this->container
->get('serializer');
}
}