annotate core/modules/language/tests/src/Functional/LanguageBrowserDetectionTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children af1871eacc83
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\language\Functional;
Chris@0 4
Chris@0 5 use Drupal\Tests\BrowserTestBase;
Chris@0 6
Chris@0 7 /**
Chris@0 8 * Tests browser language detection.
Chris@0 9 *
Chris@0 10 * @group language
Chris@0 11 */
Chris@0 12 class LanguageBrowserDetectionTest extends BrowserTestBase {
Chris@0 13
Chris@0 14 public static $modules = ['language'];
Chris@0 15
Chris@0 16 /**
Chris@0 17 * Tests for adding, editing and deleting mappings between browser language
Chris@0 18 * codes and Drupal language codes.
Chris@0 19 */
Chris@0 20 public function testUIBrowserLanguageMappings() {
Chris@0 21 // User to manage languages.
Chris@0 22 $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
Chris@0 23 $this->drupalLogin($admin_user);
Chris@0 24
Chris@0 25 // Check that the configure link exists.
Chris@0 26 $this->drupalGet('admin/config/regional/language/detection');
Chris@0 27 $this->assertLinkByHref('admin/config/regional/language/detection/browser');
Chris@0 28
Chris@0 29 // Check that defaults are loaded from language.mappings.yml.
Chris@0 30 $this->drupalGet('admin/config/regional/language/detection/browser');
Chris@0 31 $this->assertField('edit-mappings-zh-cn-browser-langcode', 'zh-cn', 'Chinese browser language code found.');
Chris@0 32 $this->assertField('edit-mappings-zh-cn-drupal-langcode', 'zh-hans-cn', 'Chinese Drupal language code found.');
Chris@0 33
Chris@0 34 // Delete zh-cn language code.
Chris@0 35 $browser_langcode = 'zh-cn';
Chris@0 36 $this->drupalGet('admin/config/regional/language/detection/browser/delete/' . $browser_langcode);
Chris@0 37 $message = t('Are you sure you want to delete @browser_langcode?', [
Chris@0 38 '@browser_langcode' => $browser_langcode,
Chris@0 39 ]);
Chris@0 40 $this->assertRaw($message);
Chris@0 41
Chris@0 42 // Confirm the delete.
Chris@0 43 $edit = [];
Chris@0 44 $this->drupalPostForm('admin/config/regional/language/detection/browser/delete/' . $browser_langcode, $edit, t('Confirm'));
Chris@0 45
Chris@0 46 // We need raw here because %browser will add HTML.
Chris@0 47 $t_args = [
Chris@0 48 '%browser' => $browser_langcode,
Chris@0 49 ];
Chris@0 50 $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 51
Chris@0 52 // Check we went back to the browser negotiation mapping overview.
Chris@0 53 $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
Chris@0 54 // Check that ch-zn no longer exists.
Chris@0 55 $this->assertNoField('edit-mappings-zh-cn-browser-langcode', 'Chinese browser language code no longer exists.');
Chris@0 56
Chris@0 57 // Add a new custom mapping.
Chris@0 58 $edit = [
Chris@0 59 'new_mapping[browser_langcode]' => 'xx',
Chris@0 60 'new_mapping[drupal_langcode]' => 'en',
Chris@0 61 ];
Chris@0 62 $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
Chris@0 63 $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
Chris@0 64 $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
Chris@0 65 $this->assertField('edit-mappings-xx-drupal-langcode', 'en', 'Drupal language code found.');
Chris@0 66
Chris@0 67 // Add the same custom mapping again.
Chris@0 68 $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
Chris@0 69 $this->assertText('Browser language codes must be unique.');
Chris@0 70
Chris@0 71 // Change browser language code of our custom mapping to zh-sg.
Chris@0 72 $edit = [
Chris@0 73 'mappings[xx][browser_langcode]' => 'zh-sg',
Chris@0 74 'mappings[xx][drupal_langcode]' => 'en',
Chris@0 75 ];
Chris@0 76 $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
Chris@0 77 $this->assertText(t('Browser language codes must be unique.'));
Chris@0 78
Chris@0 79 // Change Drupal language code of our custom mapping to zh-hans.
Chris@0 80 $edit = [
Chris@0 81 'mappings[xx][browser_langcode]' => 'xx',
Chris@0 82 'mappings[xx][drupal_langcode]' => 'zh-hans',
Chris@0 83 ];
Chris@0 84 $this->drupalPostForm('admin/config/regional/language/detection/browser', $edit, t('Save configuration'));
Chris@0 85 $this->assertUrl(\Drupal::url('language.negotiation_browser', [], ['absolute' => TRUE]));
Chris@0 86 $this->assertField('edit-mappings-xx-browser-langcode', 'xx', 'Browser language code found.');
Chris@0 87 $this->assertField('edit-mappings-xx-drupal-langcode', 'zh-hans', 'Drupal language code found.');
Chris@0 88 }
Chris@0 89
Chris@0 90 }