You are here

public function AddressDisplayTest::testSingleAddressComponent in Address Display 8

Tests displaying a single component.

File

tests/src/Kernel/Formatter/AddressDisplayTest.php, line 267

Class

AddressDisplayTest
Tests the address_display_formatter formatter.

Namespace

Drupal\Tests\address_display\Kernel\Formatter

Code

public function testSingleAddressComponent() {

  // Display only organization name.
  $settings = [
    'address_display' => [
      'organization' => [
        'display' => TRUE,
        'glue' => 'glue',
        'weight' => 0,
      ],
      'address_line1' => [
        'display' => FALSE,
        'glue' => '',
        'weight' => 0,
      ],
    ],
  ];
  $this->display
    ->setComponent($this->fieldName, [
    'type' => 'address_display_formatter',
    'settings' => $settings,
  ]);
  $this->display
    ->save();
  $content = $this->display
    ->build($this->entity);
  $this
    ->render($content);

  // Ensure that 'display' option works.
  $this
    ->assertRaw('<span class="address-display-element organization-element">');
  $this
    ->assertNoRaw('<span class="address-display-element address-line1-element">');

  // A single component should not contain a leading separator.
  $this
    ->assertRaw('<span class="address-display-element organization-element">Test company</span>');

  // Ensure that empty element is hidden.
  $this->entity->{$this->fieldName}->organization = '';
  $content = $this->display
    ->build($this->entity);
  $this
    ->render($content);
  $this
    ->assertNoRaw('<span class="address-display-element organization-element">');
}