LanguageUILanguageNegotiationTest.php 24.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php

/**
 * @file
 * Definition of Drupal\language\Tests\LanguageUILanguageNegotiationTest.
 */

namespace Drupal\language\Tests;

10
use Drupal\Core\Url;
11
use Drupal\language\Entity\ConfigurableLanguage;
12 13
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationBrowser;
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSelected;
14
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationSession;
15 16 17
use Drupal\language\Plugin\LanguageNegotiation\LanguageNegotiationUrl;
use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUser;
use Drupal\user\Plugin\LanguageNegotiation\LanguageNegotiationUserAdmin;
18
use Drupal\simpletest\WebTestBase;
19
use Drupal\Core\Language\Language;
20
use Drupal\Core\Language\LanguageInterface;
21
use Symfony\Component\HttpFoundation\Request;
22
use Drupal\language\LanguageNegotiatorInterface;
23
use Drupal\block\Entity\Block;
24 25

/**
26
 * Tests the language UI for language switching.
27
 *
28 29 30 31 32 33 34 35 36 37 38 39 40 41
 * The uses cases that get tested, are:
 * - URL (path) > default: Test that the URL prefix setting gets precedence over
 *   the default language. The browser language preference does not have any
 *   influence.
 * - URL (path) > browser > default: Test that the URL prefix setting gets
 *   precedence over the browser language preference, which in turn gets
 *   precedence over the default language.
 * - URL (domain) > default: Tests that the URL domain setting gets precedence
 *   over the default language.
 *
 * The paths that are used for each of these, are:
 * - admin/config: Tests the UI using the precedence rules.
 * - zh-hans/admin/config: Tests the UI in Chinese.
 * - blah-blah/admin/config: Tests the 404 page.
42 43
 *
 * @group language
44 45
 */
class LanguageUILanguageNegotiationTest extends WebTestBase {
46 47 48 49 50 51 52 53 54 55

  /**
   * Modules to enable.
   *
   * We marginally use interface translation functionality here, so need to use
   * the locale module instead of language only, but the 90% of the test is
   * about the negotiation process which is solely in language module.
   *
   * @var array
   */
56
  public static $modules = array('locale', 'language_test', 'block', 'user', 'content_translation');
57

58
  protected function setUp() {
59
    parent::setUp();
60

61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
    $admin_user = $this->drupalCreateUser(array('administer languages', 'translate interface', 'access administration pages', 'administer blocks'));
    $this->drupalLogin($admin_user);
  }

  /**
   * Tests for language switching by URL path.
   */
  function testUILanguageNegotiation() {
    // A few languages to switch to.
    // This one is unknown, should get the default lang version.
    $langcode_unknown = 'blah-blah';
    // For testing browser lang preference.
    $langcode_browser_fallback = 'vi';
    // For testing path prefix.
    $langcode = 'zh-hans';
    // For setting browser language preference to 'vi'.
    $http_header_browser_fallback = array("Accept-Language: $langcode_browser_fallback;q=1");
    // For setting browser language preference to some unknown.
    $http_header_blah = array("Accept-Language: blah;q=1");

    // Setup the site languages by installing two languages.
82 83 84 85
    // Set the default language in order for the translated string to be registered
    // into database when seen by t(). Without doing this, our target string
    // is for some reason not found when doing translate search. This might
    // be some bug.
86
    $default_language = \Drupal::languageManager()->getDefaultLanguage();
87
    ConfigurableLanguage::createFromLangcode($langcode_browser_fallback)->save();
88
    $this->config('system.site')->set('default_langcode', $langcode_browser_fallback)->save();
89
    ConfigurableLanguage::createFromLangcode($langcode)->save();
90 91 92

    // We will look for this string in the admin/config screen to see if the
    // corresponding translated string is shown.
93
    $default_string = 'Hide descriptions';
94 95 96

    // First visit this page to make sure our target string is searchable.
    $this->drupalGet('admin/config');
97

98
    // Now the t()'ed string is in db so switch the language back to default.
99 100
    // This will rebuild the container so we need to rebuild the container in
    // the test environment.
101
    $this->config('system.site')->set('default_langcode', $default_language->getId())->save();
102
    $this->config('language.negotiation')->set('url.prefixes.en', '')->save();
103
    $this->rebuildContainer();
104 105 106 107 108

    // Translate the string.
    $language_browser_fallback_string = "In $langcode_browser_fallback In $langcode_browser_fallback In $langcode_browser_fallback";
    $language_string = "In $langcode In $langcode In $langcode";
    // Do a translate search of our target string.
109 110 111 112
    $search = array(
      'string' => $default_string,
      'langcode' => $langcode_browser_fallback,
    );
113
    $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
114 115 116 117 118
    $textarea = current($this->xpath('//textarea'));
    $lid = (string) $textarea[0]['name'];
    $edit = array(
      $lid => $language_browser_fallback_string,
    );
119
    $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
120 121 122 123 124

    $search = array(
      'string' => $default_string,
      'langcode' => $langcode,
    );
125
    $this->drupalPostForm('admin/config/regional/translate', $search, t('Filter'));
126 127
    $textarea = current($this->xpath('//textarea'));
    $lid = (string) $textarea[0]['name'];
128
    $edit = array(
129
      $lid => $language_string,
130
    );
131
    $this->drupalPostForm('admin/config/regional/translate', $edit, t('Save translations'));
132

133 134
    // Configure selected language negotiation to use zh-hans.
    $edit = array('selected_langcode' => $langcode);
135
    $this->drupalPostForm('admin/config/regional/language/detection/selected', $edit, t('Save configuration'));
136
    $test = array(
137
      'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
138 139
      'path' => 'admin/config',
      'expect' => $language_string,
140
      'expected_method_id' => LanguageNegotiationSelected::METHOD_ID,
141 142 143 144 145 146
      'http_header' => $http_header_browser_fallback,
      'message' => 'SELECTED: UI language is switched based on selected language.',
    );
    $this->runTest($test);

    // An invalid language is selected.
147
    $this->config('language.negotiation')->set('selected_langcode', NULL)->save();
148
    $test = array(
149
      'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
150 151
      'path' => 'admin/config',
      'expect' => $default_string,
152
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
153 154 155 156 157 158
      'http_header' => $http_header_browser_fallback,
      'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.',
    );
    $this->runTest($test);

    // No selected language is available.
159
    $this->config('language.negotiation')->set('selected_langcode', $langcode_unknown)->save();
160
    $test = array(
161
      'language_negotiation' => array(LanguageNegotiationSelected::METHOD_ID),
162 163
      'path' => 'admin/config',
      'expect' => $default_string,
164
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
165 166 167 168 169
      'http_header' => $http_header_browser_fallback,
      'message' => 'SELECTED > DEFAULT: UI language is switched based on selected language.',
    );
    $this->runTest($test);

170 171 172
    $tests = array(
      // Default, browser preference should have no influence.
      array(
173
        'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
174 175
        'path' => 'admin/config',
        'expect' => $default_string,
176
        'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
177 178 179 180 181
        'http_header' => $http_header_browser_fallback,
        'message' => 'URL (PATH) > DEFAULT: no language prefix, UI language is default and the browser language preference setting is not used.',
      ),
      // Language prefix.
      array(
182
        'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
183 184
        'path' => "$langcode/admin/config",
        'expect' => $language_string,
185
        'expected_method_id' => LanguageNegotiationUrl::METHOD_ID,
186 187 188 189 190
        'http_header' => $http_header_browser_fallback,
        'message' => 'URL (PATH) > DEFAULT: with language prefix, UI language is switched based on path prefix',
      ),
      // Default, go by browser preference.
      array(
191
        'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID),
192 193
        'path' => 'admin/config',
        'expect' => $language_browser_fallback_string,
194
        'expected_method_id' => LanguageNegotiationBrowser::METHOD_ID,
195 196 197 198 199
        'http_header' => $http_header_browser_fallback,
        'message' => 'URL (PATH) > BROWSER: no language prefix, UI language is determined by browser language preference',
      ),
      // Prefix, switch to the language.
      array(
200
        'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID),
201 202
        'path' => "$langcode/admin/config",
        'expect' => $language_string,
203
        'expected_method_id' => LanguageNegotiationUrl::METHOD_ID,
204
        'http_header' => $http_header_browser_fallback,
205
        'message' => 'URL (PATH) > BROWSER: with language prefix, UI language is based on path prefix',
206 207 208
      ),
      // Default, browser language preference is not one of site's lang.
      array(
209
        'language_negotiation' => array(LanguageNegotiationUrl::METHOD_ID, LanguageNegotiationBrowser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
210 211
        'path' => 'admin/config',
        'expect' => $default_string,
212
        'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
213 214 215 216 217 218 219 220 221 222
        'http_header' => $http_header_blah,
        'message' => 'URL (PATH) > BROWSER > DEFAULT: no language prefix and browser language preference set to unknown language should use default language',
      ),
    );

    foreach ($tests as $test) {
      $this->runTest($test);
    }

    // Unknown language prefix should return 404.
223
    $definitions = \Drupal::languageManager()->getNegotiator()->getNegotiationMethods();
224
    $this->config('language.types')
225
      ->set('negotiation.' . LanguageInterface::TYPE_INTERFACE . '.enabled', array_flip(array_keys($definitions)))
226
      ->save();
227 228 229
    $this->drupalGet("$langcode_unknown/admin/config", array(), $http_header_browser_fallback);
    $this->assertResponse(404, "Unknown language path prefix should return 404");

230 231 232 233 234
    // Set preferred langcode for user to NULL.
    $account = $this->loggedInUser;
    $account->preferred_langcode = NULL;
    $account->save();

235
    $test = array(
236
      'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
237 238
      'path' => 'admin/config',
      'expect' => $default_string,
239
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
240 241
      'http_header' => array(),
      'message' => 'USER > DEFAULT: no preferred user language setting, the UI language is default',
242
    );
243
    $this->runTest($test);
244 245 246 247 248 249

    // Set preferred langcode for user to unknown language.
    $account = $this->loggedInUser;
    $account->preferred_langcode = $langcode_unknown;
    $account->save();

250
    $test = array(
251
      'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
252 253
      'path' => 'admin/config',
      'expect' => $default_string,
254
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
255 256
      'http_header' => array(),
      'message' => 'USER > DEFAULT: invalid preferred user language setting, the UI language is default',
257
    );
258
    $this->runTest($test);
259 260 261 262 263

    // Set preferred langcode for user to non default.
    $account->preferred_langcode = $langcode;
    $account->save();

264
    $test = array(
265
      'language_negotiation' => array(LanguageNegotiationUser::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
266 267
      'path' => 'admin/config',
      'expect' => $language_string,
268
      'expected_method_id' => LanguageNegotiationUser::METHOD_ID,
269 270
      'http_header' => array(),
      'message' => 'USER > DEFAULT: defined prefereed user language setting, the UI language is based on user setting',
271
    );
272
    $this->runTest($test);
273 274 275 276 277

    // Set preferred admin langcode for user to NULL.
    $account->preferred_admin_langcode = NULL;
    $account->save();

278
    $test = array(
279
      'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
280 281
      'path' => 'admin/config',
      'expect' => $default_string,
282
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
283 284
      'http_header' => array(),
      'message' => 'USER ADMIN > DEFAULT: no preferred user admin language setting, the UI language is default',
285
    );
286
    $this->runTest($test);
287 288 289 290 291

    // Set preferred admin langcode for user to unknown language.
    $account->preferred_admin_langcode = $langcode_unknown;
    $account->save();

292
    $test = array(
293
      'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
294 295
      'path' => 'admin/config',
      'expect' => $default_string,
296
      'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
297 298
      'http_header' => array(),
      'message' => 'USER ADMIN > DEFAULT: invalid preferred user admin language setting, the UI language is default',
299
    );
300
    $this->runTest($test);
301 302 303 304 305

    // Set preferred admin langcode for user to non default.
    $account->preferred_admin_langcode = $langcode;
    $account->save();

306
    $test = array(
307
      'language_negotiation' => array(LanguageNegotiationUserAdmin::METHOD_ID, LanguageNegotiationSelected::METHOD_ID),
308 309
      'path' => 'admin/config',
      'expect' => $language_string,
310
      'expected_method_id' => LanguageNegotiationUserAdmin::METHOD_ID,
311 312
      'http_header' => array(),
      'message' => 'USER ADMIN > DEFAULT: defined prefereed user admin language setting, the UI language is based on user setting',
313
    );
314
    $this->runTest($test);
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341

    // Go by session preference.
    $language_negotiation_session_param = $this->randomMachineName();
    $edit = array('language_negotiation_session_param' => $language_negotiation_session_param);
    $this->drupalPostForm('admin/config/regional/language/detection/session', $edit, t('Save configuration'));
    $tests = array(
      array(
        'language_negotiation' => array(LanguageNegotiationSession::METHOD_ID),
        'path' => "admin/config",
        'expect' => $default_string,
        'expected_method_id' => LanguageNegotiatorInterface::METHOD_ID,
        'http_header' => $http_header_browser_fallback,
        'message' => 'SESSION > DEFAULT: no language given, the UI language is default',
      ),
      array(
        'language_negotiation' => array(LanguageNegotiationSession::METHOD_ID),
        'path' => 'admin/config',
        'path_options' => ['query' => [$language_negotiation_session_param => $langcode]],
        'expect' => $language_string,
        'expected_method_id' => LanguageNegotiationSession::METHOD_ID,
        'http_header' => $http_header_browser_fallback,
        'message' => 'SESSION > DEFAULT: language given, UI language is determined by session language preference',
      ),
    );
    foreach ($tests as $test) {
      $this->runTest($test);
    }
342 343 344
  }

  protected function runTest($test) {
345
    $test += array('path_options' => []);
346 347
    if (!empty($test['language_negotiation'])) {
      $method_weights = array_flip($test['language_negotiation']);
348
      $this->container->get('language_negotiator')->saveConfiguration(LanguageInterface::TYPE_INTERFACE, $method_weights);
349 350
    }
    if (!empty($test['language_negotiation_url_part'])) {
351
      $this->config('language.negotiation')
352 353
        ->set('url.source', $test['language_negotiation_url_part'])
        ->save();
354 355
    }
    if (!empty($test['language_test_domain'])) {
356
      \Drupal::state()->set('language_test.domain', $test['language_test_domain']);
357
    }
358
    $this->container->get('language_manager')->reset();
359
    $this->drupalGet($test['path'], $test['path_options'], $test['http_header']);
360 361 362 363 364 365 366 367 368 369
    $this->assertText($test['expect'], $test['message']);
    $this->assertText(t('Language negotiation method: @name', array('@name' => $test['expected_method_id'])));
  }

  /**
   * Test URL language detection when the requested URL has no language.
   */
  function testUrlLanguageFallback() {
    // Add the Italian language.
    $langcode_browser_fallback = 'it';
370
    ConfigurableLanguage::createFromLangcode($langcode_browser_fallback)->save();
371
    $languages = $this->container->get('language_manager')->getLanguages();
372 373 374 375

    // Enable the path prefix for the default language: this way any unprefixed
    // URL must have a valid fallback value.
    $edit = array('prefix[en]' => 'en');
376
    $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
377 378 379 380 381 382 383 384

    // Enable browser and URL language detection.
    $edit = array(
      'language_interface[enabled][language-browser]' => TRUE,
      'language_interface[enabled][language-url]' => TRUE,
      'language_interface[weight][language-browser]' => -8,
      'language_interface[weight][language-url]' => -10,
    );
385
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
386 387 388
    $this->drupalGet('admin/config/regional/language/detection');

    // Enable the language switcher block.
389
    $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_INTERFACE, array('id' => 'test_language_block'));
390

391 392 393 394 395
    // Log out, because for anonymous users, the "active" class is set by PHP
    // (which means we can easily test it here), whereas for authenticated users
    // it is set by JavaScript.
    $this->drupalLogout();

396 397 398
    // Access the front page without specifying any valid URL language prefix
    // and having as browser language preference a non-default language.
    $http_header = array("Accept-Language: $langcode_browser_fallback;q=1");
399
    $language = new Language(array('id' => ''));
400 401 402 403
    $this->drupalGet('', array('language' => $language), $http_header);

    // Check that the language switcher active link matches the given browser
    // language.
404
    $args = array(':id' => 'block-test-language-block', ':url' => \Drupal::url('<front>') . $langcode_browser_fallback);
405
    $fields = $this->xpath('//div[@id=:id]//a[@class="language-link is-active" and starts-with(@href, :url)]', $args);
406
    $this->assertTrue($fields[0] == $languages[$langcode_browser_fallback]->getName(), 'The browser language is the URL active language');
407 408

    // Check that URLs are rewritten using the given browser language.
409
    $fields = $this->xpath('//strong[@class="site-name"]/a[@rel="home" and @href=:url]', $args);
410
    $this->assertTrue($fields[0] == 'Drupal', 'URLs are rewritten using the browser language.');
411 412 413
  }

  /**
414
   * Tests URL handling when separate domains are used for multiple languages.
415 416
   */
  function testLanguageDomain() {
417 418 419 420 421
    global $base_url;

    // Get the current host URI we're running on.
    $base_url_host = parse_url($base_url, PHP_URL_HOST);

422
    // Add the Italian language.
423 424
    ConfigurableLanguage::createFromLangcode('it')->save();

425
    $languages = $this->container->get('language_manager')->getLanguages();
426 427 428 429 430 431

    // Enable browser and URL language detection.
    $edit = array(
      'language_interface[enabled][language-url]' => TRUE,
      'language_interface[weight][language-url]' => -10,
    );
432
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
433

434 435 436 437 438 439 440 441 442
    // Do not allow blank domain.
    $edit = array(
      'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
      'domain[en]' => '',
    );
    $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
    $this->assertText('The domain may not be left blank for English', 'The form does not allow blank domains.');
    $this->rebuildContainer();

443 444
    // Change the domain for the Italian language.
    $edit = array(
445
      'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
446
      'domain[en]' => $base_url_host,
447 448
      'domain[it]' => 'it.example.com',
    );
449
    $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
450
    $this->assertText('The configuration options have been saved', 'Domain configuration is saved.');
451
    $this->rebuildContainer();
452

453 454 455 456 457 458 459 460 461
    // Try to use an invalid domain.
    $edit = [
      'language_negotiation_url_part' => LanguageNegotiationUrl::CONFIG_DOMAIN,
      'domain[en]' => $base_url_host,
      'domain[it]' => 'it.example.com/',
    ];
    $this->drupalPostForm('admin/config/regional/language/detection/url', $edit, t('Save configuration'));
    $this->assertRaw(t('The domain for %language may only contain the domain name, not a trailing slash, protocol and/or port.', ['%language' => 'Italian']));

462
    // Build the link we're going to test.
463
    $link = 'it.example.com' . rtrim(base_path(), '/') . '/admin';
464 465 466 467

    // Test URL in another language: http://it.example.com/admin.
    // Base path gives problems on the testbot, so $correct_link is hard-coded.
    // @see UrlAlterFunctionalTest::assertUrlOutboundAlter (path.test).
468
    $italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString();
469
    $url_scheme = \Drupal::request()->isSecure() ? 'https://' : 'http://';
470
    $correct_link = $url_scheme . $link;
471
    $this->assertEqual($italian_url, $correct_link, format_string('The right URL (@url) in accordance with the chosen language', array('@url' => $italian_url)));
472

473
    // Test HTTPS via options.
474
    $italian_url = Url::fromRoute('system.admin', [], ['https' => TRUE, 'language' => $languages['it']])->toString();
475
    $correct_link = 'https://' . $link;
476
    $this->assertTrue($italian_url == $correct_link, format_string('The right HTTPS URL (via options) (@url) in accordance with the chosen language', array('@url' => $italian_url)));
477

478
    // Test HTTPS via current URL scheme.
479
    $request = Request::create('', 'GET', array(), array(), array(), array('HTTPS' => 'on'));
480
    $this->container->get('request_stack')->push($request);
481
    $italian_url = Url::fromRoute('system.admin', [], ['language' => $languages['it']])->toString();
482
    $correct_link = 'https://' . $link;
483
    $this->assertTrue($italian_url == $correct_link, format_string('The right URL (via current URL scheme) (@url) in accordance with the chosen language', array('@url' => $italian_url)));
484
  }
485 486 487 488 489 490 491 492 493 494 495 496 497 498

  /**
   * Tests persistence of negotiation settings for the content language type.
   */
  public function testContentCustomization() {
    // Customize content language settings from their defaults.
    $edit = array(
      'language_content[configurable]' => TRUE,
      'language_content[enabled][language-url]' => FALSE,
      'language_content[enabled][language-session]' => TRUE,
    );
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));

    // Check if configurability persisted.
499
    $config = $this->config('language.types');
500 501 502 503 504 505 506
    $this->assertTrue(in_array('language_interface', $config->get('configurable')), 'Interface language is configurable.');
    $this->assertTrue(in_array('language_content', $config->get('configurable')), 'Content language is configurable.');

    // Ensure configuration was saved.
    $this->assertFalse(array_key_exists('language-url', $config->get('negotiation.language_content.enabled')), 'URL negotiation is not enabled for content.');
    $this->assertTrue(array_key_exists('language-session', $config->get('negotiation.language_content.enabled')), 'Session negotiation is enabled for content.');
  }
507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531

  /**
   * Tests if the language switcher block gets deleted when a language type has been made not configurable.
   */
  public function testDisableLanguageSwitcher() {
    $block_id = 'test_language_block';

    // Enable the language switcher block.
    $this->drupalPlaceBlock('language_block:' . LanguageInterface::TYPE_CONTENT, array('id' => $block_id));

    // Check if the language switcher block has been created.
    $block = Block::load($block_id);
    $this->assertTrue($block, 'Language switcher block was created.');

    // Make sure language_content is not configurable.
    $edit = array(
      'language_content[configurable]' => FALSE,
    );
    $this->drupalPostForm('admin/config/regional/language/detection', $edit, t('Save settings'));
    $this->assertResponse(200);

    // Check if the language switcher block has been removed.
    $block = Block::load($block_id);
    $this->assertFalse($block, 'Language switcher block was removed.');
  }
532
}