Chris@0: drupalCreateUser(['administer languages', 'access administration pages']); Chris@0: $this->drupalLogin($admin_user); Chris@0: Chris@0: // Check that the configure link exists. Chris@0: $this->drupalGet('admin/config/regional/language/detection'); Chris@0: $this->assertLinkByHref('admin/config/regional/language/detection/browser'); Chris@0: Chris@0: // Check that defaults are loaded from language.mappings.yml. Chris@0: $this->drupalGet('admin/config/regional/language/detection/browser'); Chris@0: $this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.'); Chris@0: $this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.'); Chris@0: Chris@0: // Delete zh-cn language code. Chris@0: $browser_langcode = 'zh-cn'; Chris@0: $this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode); Chris@0: $message = t('Are you sure you want to delete @browser_langcode?', [ Chris@0: '@browser_langcode' => $browser_langcode, Chris@0: ]); Chris@0: $this->assertRaw($message); Chris@0: Chris@0: // Confirm the delete. Chris@0: $edit = []; Chris@0: $this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm')); Chris@0: Chris@0: // We need raw here because %browser will add HTML. Chris@0: $t_args = [ Chris@0: '%browser' => $browser_langcode, Chris@0: ]; Chris@0: $this->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.'); Chris@0: Chris@0: // Check we went back to the browser negotiation mapping overview. Chris@18: $this->assertUrl(Url::fromRoute('language.negotiation_browser', [], ['absolute' => TRUE])->toString()); Chris@0: // Check that ch-zn no longer exists. Chris@0: $this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.'); Chris@0: Chris@0: // Add a new custom mapping. Chris@0: $edit = [ Chris@0: 'new_mapping[browser_langcode]' => 'xx', Chris@0: 'new_mapping[drupal_langcode]' => 'en', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); Chris@18: $this->assertUrl(Url::fromRoute('language.negotiation_browser', [], ['absolute' => TRUE])->toString()); Chris@0: $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); Chris@0: $this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.'); Chris@0: Chris@0: // Add the same custom mapping again. Chris@0: $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); Chris@0: $this->assertText('Browser language codes must be unique.'); Chris@0: Chris@0: // Change browser language code of our custom mapping to zh-sg. Chris@0: $edit = [ Chris@0: 'mappings[xx][browser_langcode]' => 'zh-sg', Chris@0: 'mappings[xx][drupal_langcode]' => 'en', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); Chris@0: $this->assertText(t('Browser language codes must be unique.')); Chris@0: Chris@0: // Change Drupal language code of our custom mapping to zh-hans. Chris@0: $edit = [ Chris@0: 'mappings[xx][browser_langcode]' => 'xx', Chris@0: 'mappings[xx][drupal_langcode]' => 'zh-hans', Chris@0: ]; Chris@0: $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration')); Chris@18: $this->assertUrl(Url::fromRoute('language.negotiation_browser', [], ['absolute' => TRUE])->toString()); Chris@0: $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.'); Chris@0: $this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.'); Chris@0: } Chris@0: Chris@0: }