You are here

public function LanguageSwitcherExtendedTest::testHideUntranslatedEntityLanguage in Language Switcher Extended 8

Tests, to hide language switcher item for an untranslated entity.

File

tests/src/Functional/LanguageSwitcherExtendedTest.php, line 137

Class

LanguageSwitcherExtendedTest
Functional tests for the language_switcher_extended feature.

Namespace

Drupal\Tests\language_switcher_extended\Functional

Code

public function testHideUntranslatedEntityLanguage() {

  // Open the module's configuration page.
  $this
    ->drupalGet('admin/config/regional/language/language-switcher-extended');

  // Configure to hide the link for untranslated entities.
  $edit = [
    'mode' => 'process_untranslated',
    'untranslated_handler' => 'hide_link',
  ];
  $this
    ->submitForm($edit, 'Save configuration');

  // Open the node without a translation.
  $this
    ->drupalGet('node/1');

  // Verify, that the untranslated language switcher is hidden.
  $this
    ->assertSession()
    ->elementAttributeContains('css', '#block-test-language-block li[hreflang="en"] a', 'data-drupal-link-system-path', 'node/1');
  $this
    ->assertSession()
    ->elementNotExists('css', '#block-test-language-block li[hreflang="de"]');
  $this
    ->assertSession()
    ->elementsCount('css', '#block-test-language-block li', 1);

  // Configure to hide a single remaining language switcher link.
  $this
    ->drupalGet('admin/config/regional/language/language-switcher-extended');
  $edit = [
    'mode' => 'process_untranslated',
    'untranslated_handler' => 'hide_link',
    'hide_single_link' => 1,
    'show_langcode' => 0,
  ];
  $this
    ->submitForm($edit, 'Save configuration');

  // Open the node without a translation.
  $this
    ->drupalGet('node/1');

  // Verify, that there is no language switcher item anymore.
  $this
    ->assertSession()
    ->elementsCount('css', '#block-test-language-block li', 0);
  $this
    ->drupalGet('admin/config/regional/language/language-switcher-extended');
  $edit = [
    'mode' => 'process_untranslated',
    'untranslated_handler' => 'hide_link',
    'hide_single_link' => 1,
    'hide_single_link_block' => 1,
    'show_langcode' => 0,
  ];
  $this
    ->submitForm($edit, 'Save configuration');

  // Open the node without a translation.
  $this
    ->drupalGet('node/1');

  // Verify, that there is no language switcher block anymore.
  $this
    ->assertSession()
    ->elementsCount('css', '#block-test-language-block', 0);
}