View source
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class LanguageBrowserDetectionTest extends BrowserTestBase {
public static $modules = [
'language',
];
protected $defaultTheme = 'stark';
public function testUIBrowserLanguageMappings() {
$admin_user = $this
->drupalCreateUser([
'administer languages',
'access administration pages',
]);
$this
->drupalLogin($admin_user);
$this
->drupalGet('admin/config/regional/language/detection');
$this
->assertLinkByHref('admin/config/regional/language/detection/browser');
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.');
$this
->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.');
$browser_langcode = 'zh-cn';
$this
->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
$message = t('Are you sure you want to delete @browser_langcode?', [
'@browser_langcode' => $browser_langcode,
]);
$this
->assertRaw($message);
$edit = [];
$this
->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm'));
$t_args = [
'%browser' => $browser_langcode,
];
$this
->assertRaw(t('The mapping for the %browser browser language code has been deleted.', $t_args), 'The test browser language code has been deleted.');
$this
->assertUrl(Url::fromRoute('language.negotiation_browser', [], [
'absolute' => TRUE,
])
->toString());
$this
->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.');
$edit = [
'new_mapping[browser_langcode]' => 'xx',
'new_mapping[drupal_langcode]' => 'en',
];
$this
->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
$this
->assertUrl(Url::fromRoute('language.negotiation_browser', [], [
'absolute' => TRUE,
])
->toString());
$this
->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
$this
->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.');
$this
->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
$this
->assertText('Browser language codes must be unique.');
$edit = [
'mappings[xx][browser_langcode]' => 'zh-sg',
'mappings[xx][drupal_langcode]' => 'en',
];
$this
->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
$this
->assertText(t('Browser language codes must be unique.'));
$edit = [
'mappings[xx][browser_langcode]' => 'xx',
'mappings[xx][drupal_langcode]' => 'zh-hans',
];
$this
->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
$this
->assertUrl(Url::fromRoute('language.negotiation_browser', [], [
'absolute' => TRUE,
])
->toString());
$this
->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
$this
->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.');
}
}