protected function AddressDisplayTest::setUp in Address Display 8
Overrides KernelTestBase::setUp
File
- tests/
src/ Kernel/ Formatter/ AddressDisplayTest.php, line 131
Class
- AddressDisplayTest
- Tests the address_display_formatter formatter.
Namespace
Drupal\Tests\address_display\Kernel\FormatterCode
protected function setUp() {
parent::setUp();
$this
->installConfig([
'system',
]);
$this
->installConfig([
'field',
]);
$this
->installConfig([
'text',
]);
$this
->installConfig([
'address',
]);
$this
->installConfig([
'entity_test',
]);
$this
->installEntitySchema('entity_test');
$this->fieldName = mb_strtolower($this
->randomMachineName());
// Create an entity_test field of the 'address' type.
$field_storage = FieldStorageConfig::create([
'field_name' => $this->fieldName,
'entity_type' => 'entity_test',
'type' => 'address',
]);
$field_storage
->save();
$field_config = FieldConfig::create([
'field_storage' => $field_storage,
'bundle' => 'entity_test',
'label' => $this
->randomMachineName(),
]);
$field_config
->save();
// The entity_get_display() procedural function is deprecated in
// drupal:8.8.0 and above.
if (version_compare(\Drupal::VERSION, '8.8', '<')) {
$this->display = \Drupal::service('entity_display.repository')
->getViewDisplay('entity_test', 'entity_test', 'default');
}
else {
$this->display = \Drupal::service('entity_display.repository')
->getViewDisplay('entity_test', 'entity_test', 'default');
}
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName} = [
'organization' => 'Test company',
'country_code' => 'PL',
'locality' => 'Kraków',
'postal_code' => '31-042',
'address_line1' => 'Rynek Główny 1/3',
'given_name' => 'Jan',
'family_name' => 'Nowak',
];
}