You are here

public function ConfigTranslationOverviewTest::testMapperListPage in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php \Drupal\Tests\config_translation\Functional\ConfigTranslationOverviewTest::testMapperListPage()

Tests the config translation mapper page.

File

core/modules/config_translation/tests/src/Functional/ConfigTranslationOverviewTest.php, line 83

Class

ConfigTranslationOverviewTest
Translate settings and entities to various languages.

Namespace

Drupal\Tests\config_translation\Functional

Code

public function testMapperListPage() {
  $this
    ->drupalGet('admin/config/regional/config-translation');
  $this
    ->assertLinkByHref('admin/config/regional/config-translation/config_test');
  $this
    ->assertLinkByHref('admin/config/people/accounts/translate');

  // Make sure there is only a single operation for each dropbutton, either
  // 'List' or 'Translate'.
  foreach ($this
    ->cssSelect('ul.dropbutton') as $i => $dropbutton) {
    $this
      ->assertCount(1, $dropbutton
      ->findAll('xpath', 'li'));
    $this
      ->assertTrue($dropbutton
      ->getText() === 'Translate' || $dropbutton
      ->getText() === 'List');
  }
  $labels = [
    '&$nxd~i0',
    'some "label" with quotes',
    $this
      ->randomString(),
  ];
  $storage = \Drupal::entityTypeManager()
    ->getStorage('config_test');
  foreach ($labels as $label) {
    $test_entity = $storage
      ->create([
      'id' => $this
        ->randomMachineName(),
      'label' => $label,
    ]);
    $test_entity
      ->save();
    $base_url = 'admin/structure/config_test/manage/' . $test_entity
      ->id();
    $this
      ->drupalGet('admin/config/regional/config-translation/config_test');
    $this
      ->assertLinkByHref($base_url . '/translate');
    $this
      ->assertEscaped($test_entity
      ->label());

    // Make sure there is only a single 'Translate' operation for each
    // dropbutton.
    foreach ($this
      ->cssSelect('ul.dropbutton') as $i => $dropbutton) {
      $this
        ->assertCount(1, $dropbutton
        ->findAll('xpath', 'li'));
      $this
        ->assertIdentical('Translate', $dropbutton
        ->getText());
    }
    $entity_type = \Drupal::entityTypeManager()
      ->getDefinition($test_entity
      ->getEntityTypeId());
    $this
      ->drupalGet($base_url . '/translate');
    $title = $test_entity
      ->label() . ' ' . $entity_type
      ->getSingularLabel();
    $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
    $this
      ->assertRaw($title);
    $this
      ->assertRaw('<th>' . t('Language') . '</th>');
    $this
      ->drupalGet($base_url);
    $this
      ->assertSession()
      ->linkExists(t('Translate @title', [
      '@title' => $entity_type
        ->getSingularLabel(),
    ]));
  }
}