LanguageBrowserDetectionTest.php in Drupal 10
File
core/modules/language/tests/src/Functional/LanguageBrowserDetectionTest.php
View source
<?php
namespace Drupal\Tests\language\Functional;
use Drupal\Core\Url;
use Drupal\Tests\BrowserTestBase;
class LanguageBrowserDetectionTest extends BrowserTestBase {
protected 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
->assertSession()
->linkByHrefExists('admin/config/regional/language/detection/browser');
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->assertSession()
->fieldValueEquals('edit-mappings-zh-cn-browser-langcode', 'zh-cn');
$this
->assertSession()
->fieldValueEquals('edit-mappings-zh-cn-drupal-langcode', 'zh-hans');
$browser_langcode = 'zh-cn';
$this
->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
$this
->assertSession()
->pageTextContains("Are you sure you want to delete {$browser_langcode}?");
$edit = [];
$this
->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
$this
->submitForm($edit, 'Confirm');
$this
->assertSession()
->statusMessageContains("The mapping for the {$browser_langcode} browser language code has been deleted.", 'status');
$this
->assertSession()
->addressEquals(Url::fromRoute('language.negotiation_browser'));
$this
->assertSession()
->fieldNotExists('edit-mappings-zh-cn-browser-langcode');
$edit = [
'new_mapping[browser_langcode]' => 'xx',
'new_mapping[drupal_langcode]' => 'en',
];
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->addressEquals(Url::fromRoute('language.negotiation_browser'));
$this
->assertSession()
->fieldValueEquals('edit-mappings-xx-browser-langcode', 'xx');
$this
->assertSession()
->fieldValueEquals('edit-mappings-xx-drupal-langcode', 'en');
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->statusMessageContains('Browser language codes must be unique.', 'error');
$edit = [
'mappings[xx][browser_langcode]' => 'zh-sg',
'mappings[xx][drupal_langcode]' => 'en',
];
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->statusMessageContains('Browser language codes must be unique.', 'error');
$edit = [
'mappings[xx][browser_langcode]' => 'xx',
'mappings[xx][drupal_langcode]' => 'zh-hans',
];
$this
->drupalGet('admin/config/regional/language/detection/browser');
$this
->submitForm($edit, 'Save configuration');
$this
->assertSession()
->addressEquals(Url::fromRoute('language.negotiation_browser'));
$this
->assertSession()
->fieldValueEquals('edit-mappings-xx-browser-langcode', 'xx');
$this
->assertSession()
->fieldValueEquals('edit-mappings-xx-drupal-langcode', 'zh-hans');
}
}