public function ContentEntitySourceUnitTest::setUp in Translation Management Tool 8
Overrides ContentEntityTestBase::setUp
File
- sources/
content/ tests/ src/ Kernel/ ContentEntitySourceUnitTest.php, line 39
Class
- ContentEntitySourceUnitTest
- Content entity Source unit tests.
Namespace
Drupal\Tests\tmgmt_content\KernelCode
public function setUp() : void {
parent::setUp();
$filter = FilterFormat::create([
'format' => 'unallowed_format',
]);
$filter
->save();
$this
->config('tmgmt.settings')
->set('allowed_formats', [
'text_plain',
])
->save();
$this
->installSchema('node', [
'node_access',
]);
// Auto-create fields for testing.
FieldStorageConfig::create([
'entity_type' => $this->entityTypeId,
'field_name' => 'field_test_text',
'type' => 'text',
'cardinality' => 1,
])
->save();
FieldConfig::create([
'entity_type' => $this->entityTypeId,
'field_name' => 'field_test_text',
'bundle' => $this->entityTypeId,
'label' => 'Test text-field',
'translatable' => FALSE,
])
->save();
// Make the test field translatable.
$field_storage = FieldStorageConfig::loadByName($this->entityTypeId, 'field_test_text');
$field_storage
->setCardinality(4);
$field_storage
->save();
$field = FieldConfig::loadByName($this->entityTypeId, $this->entityTypeId, 'field_test_text');
$field
->setTranslatable(TRUE);
$field
->save();
// Add an image field and make it translatable.
$this
->installEntitySchema('file');
$this
->installSchema('file', array(
'file_usage',
));
$this
->installConfig(array(
'node',
));
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'image_test',
'entity_type' => $this->entityTypeId,
'type' => 'image',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'translatable' => TRUE,
));
$field_storage
->save();
FieldConfig::create(array(
'entity_type' => $this->entityTypeId,
'field_storage' => $field_storage,
'bundle' => $this->entityTypeId,
'label' => $this->image_label = $this
->randomMachineName(),
))
->save();
\Drupal::service('file_system')
->copy(DRUPAL_ROOT . '/core/misc/druplicon.png', 'public://example.jpg');
$this->image = File::create([
'uri' => 'public://example.jpg',
]);
$this->image
->save();
// Add a translatable text field that should be ignored.
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'ignored_field',
'entity_type' => $this->entityTypeId,
'type' => 'text',
'cardinality' => FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED,
'translatable' => TRUE,
));
$field_storage
->save();
FieldConfig::create(array(
'entity_type' => $this->entityTypeId,
'field_storage' => $field_storage,
'bundle' => $this->entityTypeId,
'label' => $this
->randomMachineName(),
))
->setThirdPartySetting('tmgmt_content', 'excluded', TRUE)
->save();
// Add a translatable text field that should be checked after the translated
// entity has been created.
$field_storage = FieldStorageConfig::create(array(
'field_name' => 'later_addition',
'entity_type' => $this->entityTypeId,
'type' => 'text',
'cardinality' => 1,
'translatable' => TRUE,
));
$field_storage
->save();
FieldConfig::create(array(
'entity_type' => $this->entityTypeId,
'field_storage' => $field_storage,
'bundle' => $this->entityTypeId,
'label' => $this->later_addition_label = $this
->randomMachineName(),
))
->setTranslatable(TRUE)
->save();
}