You are here

public function AddressDefaultFormatterTest::testElSalvadorAddress in Address 8

Tests El Salvador address formatting.

File

tests/src/Kernel/Formatter/AddressDefaultFormatterTest.php, line 54

Class

AddressDefaultFormatterTest
Tests the address_default formatter.

Namespace

Drupal\Tests\address\Kernel\Formatter

Code

public function testElSalvadorAddress() {
  $entity = EntityTest::create([]);
  $entity->{$this->fieldName} = [
    'country_code' => 'SV',
    'administrative_area' => 'Ahuachapán',
    'locality' => 'Ahuachapán',
    'address_line1' => 'Some Street 12',
  ];
  $this
    ->renderEntityFields($entity, $this->display);
  $expected = implode('', [
    'line1' => '<p class="address" translate="no">',
    'line2' => '<span class="address-line1">Some Street 12</span><br>' . "\n",
    'line3' => '<span class="locality">Ahuachapán</span><br>' . "\n",
    'line4' => '<span class="administrative-area">Ahuachapán</span><br>' . "\n",
    'line5' => '<span class="country">El Salvador</span>',
    'line6' => '</p>',
  ]);
  $this
    ->assertRaw($expected, 'The SV address has been properly formatted.');
  $entity->{$this->fieldName}->postal_code = 'CP 2101';
  $this
    ->renderEntityFields($entity, $this->display);
  $expected = implode('', [
    'line1' => '<p class="address" translate="no">',
    'line2' => '<span class="address-line1">Some Street 12</span><br>' . "\n",
    'line3' => '<span class="postal-code">CP 2101</span>-<span class="locality">Ahuachapán</span><br>' . "\n",
    'line4' => '<span class="administrative-area">Ahuachapán</span><br>' . "\n",
    'line5' => '<span class="country">El Salvador</span>',
    'line6' => '</p>',
  ]);
  $this
    ->assertRaw($expected, 'The SV address has been properly formatted.');
}