You are here

public function AdministrativeAreaFilterTest::testDynamicAdministrativeAreaLabels in Address 8

Tests dynamic administrative area labels.

File

tests/src/Functional/Views/AdministrativeAreaFilterTest.php, line 130

Class

AdministrativeAreaFilterTest
Tests the administrative area Views filter for Address fields.

Namespace

Drupal\Tests\address\Functional\Views

Code

public function testDynamicAdministrativeAreaLabels() {
  $static_label = 'Administrative area (static label)';
  $dynamic_labels = [
    'AE' => 'Emirate',
    'BR' => 'State',
    'CA' => 'Province',
    'US' => 'State',
  ];
  $view = Views::getView('address_test_filter_administrative_area');
  $filters = $view
    ->getDisplay()
    ->getOption('filters');
  $filters['field_address_test_administrative_area']['country']['country_source'] = 'argument';
  $filters['field_address_test_administrative_area']['country']['country_argument_id'] = 'field_address_test_country_code';
  $filters['field_address_test_administrative_area']['expose']['label_type'] = 'dynamic';
  $filters['field_address_test_administrative_area']['expose']['label'] = $static_label;
  $view
    ->getDisplay()
    ->overrideOption('filters', $filters);
  $view
    ->save();
  foreach ($dynamic_labels as $country => $dynamic_label) {
    $this
      ->drupalGet("address-test/views/filter-administrative-area/{$country}");
    $this
      ->assertSession()
      ->pageTextNotContains($static_label);
    $this
      ->assertSession()
      ->pageTextContains($dynamic_label);
  }
}