public function CountryNameTokenTest::setUp in Address 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ CountryNameTokenTest.php, line 50
Class
- CountryNameTokenTest
- Tests the country name token.
Namespace
Drupal\Tests\address\KernelCode
public function setUp() : void {
parent::setUp();
if (\Drupal::entityTypeManager()
->hasDefinition('path_alias')) {
$this
->installEntitySchema('path_alias');
}
$this
->installEntitySchema('node');
$this
->installEntitySchema('taxonomy_term');
$this
->installEntitySchema('user');
// Create the article content type with an address field.
$node_type = NodeType::create([
'type' => 'article',
]);
$node_type
->save();
$field_storage = FieldStorageConfig::create([
'field_name' => 'test_address',
'entity_type' => 'node',
'type' => 'address',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_name' => 'test_address',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Test address field',
]);
$field
->save();
// Create a reference field with the same name on user.
$field_storage = FieldStorageConfig::create([
'field_name' => 'test_address',
'entity_type' => 'user',
'type' => 'entity_reference',
]);
$field_storage
->save();
$field = FieldConfig::create([
'field_name' => 'test_address',
'entity_type' => 'user',
'bundle' => 'user',
'label' => 'Test address field',
]);
$field
->save();
$this->testFormat = FilterFormat::create([
'format' => 'test',
'weight' => 1,
'filters' => [
'filter_html_escape' => [
'status' => TRUE,
],
],
]);
$this->testFormat
->save();
// Create a multi-value address field.
$field_storage = FieldStorageConfig::create([
'field_name' => 'multi_address_test',
'entity_type' => 'node',
'type' => 'address',
'cardinality' => 2,
]);
$field_storage
->save();
$this->field = FieldConfig::create([
'field_name' => 'multi_address_test',
'entity_type' => 'node',
'bundle' => 'article',
])
->save();
// Add an untranslatable node reference field.
FieldStorageConfig::create([
'field_name' => 'test_reference',
'type' => 'entity_reference',
'entity_type' => 'node',
'settings' => [
'target_type' => 'node',
],
'translatable' => FALSE,
])
->save();
FieldConfig::create([
'field_name' => 'test_reference',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Test reference',
])
->save();
// Add an untranslatable taxonomy term reference field.
$this->vocabulary = $this
->createVocabulary();
FieldStorageConfig::create([
'field_name' => 'test_term_reference',
'type' => 'entity_reference',
'entity_type' => 'node',
'settings' => [
'target_type' => 'taxonomy_term',
],
'translatable' => FALSE,
])
->save();
FieldConfig::create([
'field_name' => 'test_term_reference',
'entity_type' => 'node',
'bundle' => 'article',
'label' => 'Test term reference',
'settings' => [
'handler' => 'default:taxonomy_term',
'handler_settings' => [
'target_bundles' => [
$this->vocabulary
->id() => $this->vocabulary
->id(),
],
],
],
])
->save();
// Add an address field to terms of the created vocabulary.
$storage = FieldStorageConfig::create([
'field_name' => 'term_address_field',
'entity_type' => 'taxonomy_term',
'type' => 'address',
]);
$storage
->save();
$field = FieldConfig::create([
'field_name' => 'term_address_field',
'entity_type' => 'taxonomy_term',
'bundle' => $this->vocabulary
->id(),
]);
$field
->save();
// Add a second language.
$language = ConfigurableLanguage::create([
'id' => 'de',
'label' => 'German',
]);
$language
->save();
}