You are here

public function LanguageSelectionPageConditionTest::testNegotiationMethodOrder in Language Selection Page 8.2

Tests that the selection page uses the correct negotiation order.

File

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

Class

LanguageSelectionPageConditionTest
Tests that the condition plugins work.

Namespace

Drupal\Tests\language_selection_page\Functional

Code

public function testNegotiationMethodOrder() {

  // Check that the test negotiation plugin comes after the selection page
  // plugin.
  $definitions = \Drupal::service('plugin.manager.language_negotiation_method')
    ->getDefinitions();
  self::assertEquals([
    'language-interface',
    'language-session',
    'language-browser',
    'language-url',
    'language-content-entity',
    'language-url-fallback',
    'language-selected',
    'language-selection-page',
    'language-selection-page-test-negotiator',
    'language-user',
    'language-user-admin',
  ], array_keys($definitions));

  // Configure the test negotiator to come before the language selection
  // page and disable the URL negotiator.
  $this
    ->drupalPostForm('admin/config/regional/language/detection', [
    'language_interface[enabled][language-selection-page-test-negotiator]' => 1,
    'language_interface[weight][language-selection-page-test-negotiator]' => -10,
    'language_interface[enabled][language-selection-page]' => 1,
    'language_interface[weight][language-selection-page]' => 0,
    'language_interface[enabled][language-url]' => 0,
  ], 'Save settings');
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('node/' . $node
    ->id());
  $this
    ->assertLanguageSelectionPageLoaded();

  // The test negotiation plugin should kick in and not show the selection
  // page.
  $node = $this
    ->drupalCreateNode();
  $this
    ->drupalGet('node/' . $node
    ->id() . '-fake');
  $this
    ->assertLanguageSelectionPageNotLoaded();
}