You are here

public function AddressDefaultFormatterTest::testTaiwanAddress in Address 8

Tests Taiwan address formatting.

File

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

Class

AddressDefaultFormatterTest
Tests the address_default formatter.

Namespace

Drupal\Tests\address\Kernel\Formatter

Code

public function testTaiwanAddress() {
  $language = \Drupal::languageManager()
    ->getLanguage('zh-hant');
  \Drupal::languageManager()
    ->setConfigOverrideLanguage($language);

  // Reload the country repository for the new language to take effect.
  $this->container
    ->set('address.country_repository', NULL);
  $entity = EntityTest::create([]);
  $entity->{$this->fieldName} = [
    'langcode' => 'zh-hant',
    'country_code' => 'TW',
    'administrative_area' => 'Taipei City',
    'locality' => "Da'an District",
    'address_line1' => 'Sec. 3 Hsin-yi Rd.',
    'postal_code' => '106',
    // Any HTML in the fields is supposed to be escaped.
    'organization' => 'Giant <h2>Bike</h2> Store',
    'recipient' => 'Mr. Liu',
    'given_name' => 'Wu',
    'family_name' => 'Chen',
  ];
  $this
    ->renderEntityFields($entity, $this->display);
  $expected = implode('', [
    'line1' => '<p class="address" translate="no">',
    'line2' => '<span class="country">台灣</span><br>' . "\n",
    'line3' => '<span class="postal-code">106</span><br>' . "\n",
    'line4' => '<span class="administrative-area">台北市</span><span class="locality">大安區</span><br>' . "\n",
    'line5' => '<span class="address-line1">Sec. 3 Hsin-yi Rd.</span><br>' . "\n",
    'line6' => '<span class="organization">Giant &lt;h2&gt;Bike&lt;/h2&gt; Store</span><br>' . "\n",
    'line7' => '<span class="family-name">Chen</span> <span class="given-name">Wu</span>',
    'line8' => '</p>',
  ]);
  $this
    ->assertRaw($expected, 'The TW address has been properly formatted.');
}