You are here

public function CountryNameTokenTest::testEntityCountryNameTokens in Address 8

Tests [entity:country_name] tokens.

File

tests/src/Kernel/CountryNameTokenTest.php, line 190

Class

CountryNameTokenTest
Tests the country name token.

Namespace

Drupal\Tests\address\Kernel

Code

public function testEntityCountryNameTokens() {

  // Create a node with address fields and test its country_name tokens.
  $entity = Node::create([
    'title' => 'Test node title',
    'type' => 'article',
    'test_address' => [
      'country_code' => 'AD',
      'locality' => 'Canillo',
      'postal_code' => 'AD500',
      'address_line1' => 'C. Prat de la Creu, 62-64',
    ],
    'multi_address_test' => [
      [
        'country_code' => 'SV',
        'administrative_area' => 'Ahuachapán',
        'locality' => 'Ahuachapán',
        'address_line1' => 'Some Street 12',
      ],
      [
        'country_code' => 'US',
        'administrative_area' => 'CA',
        'address_line1' => '1098 Alta Ave',
        'postal_code' => '94043',
      ],
    ],
  ]);
  $entity
    ->save();
  $this
    ->assertTokens('node', [
    'node' => $entity,
  ], [
    'test_address:country_name' => 'Andorra',
    'multi_address_test:0:country_name' => 'El Salvador',
    'multi_address_test:1:country_name' => 'United States',
  ]);
}