View source
<?php
namespace Drupal\Tests\replication\Kernel\Normalizer;
use Drupal\field\Entity\FieldConfig;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\multiversion\Entity\Workspace;
abstract class NormalizerTestBase extends KernelTestBase {
public static $modules = [
'serialization',
'multiversion',
'key_value',
'system',
'field',
'entity_test',
'replication',
'text',
'filter',
'user',
'link',
'file',
'language',
'content_translation',
];
protected $serializer;
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('entity_test_mul');
$this
->installEntitySchema('entity_test_mulrev');
$this
->installEntitySchema('entity_test_rev');
$this
->installEntitySchema('user');
$this
->installEntitySchema('workspace');
$this
->installEntitySchema('file');
$this
->installEntitySchema('replication_log');
$this
->installSchema('file', 'file_usage');
$this
->installSchema('system', [
'key_value_expire',
'sequences',
'url_alias',
'router',
]);
$this
->installSchema('key_value', [
'key_value_sorted',
]);
$this
->installConfig([
'multiversion',
'replication',
'language',
'field',
]);
$this->container
->get('multiversion.manager')
->enableEntityTypes();
$this->container
->get('router.builder')
->rebuild();
FieldStorageConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_text',
'type' => 'text',
'cardinality' => 1,
'translatable' => TRUE,
])
->save();
FieldConfig::create([
'entity_type' => 'entity_test_mulrev',
'field_name' => 'field_test_text',
'bundle' => 'entity_test_mulrev',
'label' => 'Test text-field',
'widget' => [
'type' => 'text_textfield',
'weight' => 0,
],
])
->save();
$this->serializer = $this->container
->get('serializer');
Workspace::create([
'machine_name' => 'live',
'label' => 'Live',
'type' => 'basic',
])
->save();
}
protected function formatExpectedTimestampItemValues($timestamp) {
$minor_version = substr(\Drupal::VERSION, 0, 3);
if (version_compare($minor_version, '8.4', '<') || $this
->config('serialization.settings')
->get('bc_timestamp_normalizer_unix')) {
return [
'value' => $timestamp,
];
}
$date = new \DateTime();
$date
->setTimestamp($timestamp);
$date
->setTimezone(new \DateTimeZone('UTC'));
return [
'value' => $date
->format(\DateTime::RFC3339),
'format' => \DateTime::RFC3339,
];
}
}