You are here

public function LanguageSelectionPageConditionTest::testType in Language Selection Page 8.2

Test that the language selection block works as intended.

File

tests/src/Functional/LanguageSelectionPageConditionTest.php, line 315

Class

LanguageSelectionPageConditionTest
Tests that the condition plugins work.

Namespace

Drupal\Tests\language_selection_page\Functional

Code

public function testType() {
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'type' => 'block',
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageNotLoaded();
  $this
    ->assertSession()
    ->pageTextNotContains('Language Selection Page block');
  $this
    ->drupalPostForm('admin/structure/block/add/language-selection-page/stark', [
    'region' => 'content',
  ], 'Save block');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextContains('Language Selection Page block');
  $this
    ->assertLanguageSelectionPageLoaded();

  // Ensure we are on a blacklisted path.
  $blacklisted_paths = implode(\PHP_EOL, [
    '/admin',
    '/admin/*',
    '/admin*',
    '/node/' . $node
      ->id(),
  ]);
  $this
    ->drupalPostForm('admin/config/regional/language/detection/language_selection_page', [
    'blacklisted_paths' => $blacklisted_paths,
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertSession()
    ->pageTextNotContains('Language Selection Page block');
  $this
    ->assertLanguageSelectionPageNotLoaded();
  $this
    ->resetConfiguration();

  // Test template only.
  $this
    ->drupalPostForm('en/admin/config/regional/language/detection/language_selection_page', [
    'type' => 'standalone',
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();
  $this
    ->assertSession()
    ->responseNotContains('<h2>Search</h2>');

  // Test template in theme.
  $this
    ->drupalPostForm('en/admin/config/regional/language/detection/language_selection_page', [
    'type' => 'embedded',
  ], 'Save configuration');
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();
  $this
    ->assertSession()
    ->responseContains('<h2>Search</h2>');
  $this
    ->resetConfiguration();
}