AddressPlainFormatterTest.php in Address 8
File
tests/src/Kernel/Formatter/AddressPlainFormatterTest.php
View source
<?php
namespace Drupal\Tests\address\Kernel\Formatter;
use Drupal\entity_test\Entity\EntityTest;
class AddressPlainFormatterTest extends FormatterTestBase {
protected $entity;
protected function setUp() : void {
parent::setUp();
$this
->createField('address', 'address_plain');
$this->entity = EntityTest::create([]);
$this->entity->{$this->fieldName} = [
'country_code' => 'AD',
'locality' => 'Canillo',
'postal_code' => 'AD500',
'address_line1' => 'C. Prat de la Creu, 62-64',
];
}
public function testRender() {
$this
->renderEntityFields($this->entity, $this->display);
$expected_elements = [
'C. Prat de la Creu, 62-64',
'AD500',
'Canillo',
'Andorra',
];
foreach ($expected_elements as $expected_element) {
$this
->assertRaw($expected_element);
}
$this->entity->{$this->fieldName}->locality = 'FAKE_LOCALITY';
$this
->renderEntityFields($this->entity, $this->display);
$this
->assertRaw('FAKE_LOCALITY');
}
public function testAddressPlainThemeHookSuggestions() {
foreach ([
'full',
'my_custom_view_mode',
] as $view_mode) {
$variables['theme_hook_original'] = 'address_plain';
$variables['view_mode'] = $view_mode;
$variables['address'] = $this->entity->{$this->fieldName};
$suggestions = \Drupal::moduleHandler()
->invokeAll('theme_suggestions_address_plain', [
$variables,
]);
$expected_suggestions = [
'address_plain__entity_test__' . $view_mode,
'address_plain__entity_test__entity_test',
'address_plain__entity_test__entity_test__' . $view_mode,
'address_plain__' . $this->fieldName,
'address_plain__entity_test__' . $this->fieldName,
'address_plain__entity_test__' . $this->fieldName . '__entity_test',
];
$this
->assertEquals($expected_suggestions, $suggestions, 'Unexpected theme suggestions for ' . $view_mode);
}
}
}