3 namespace Drupal\Tests\language\Functional;
5 use Drupal\Core\Language\Language;
6 use Drupal\Core\Language\LanguageInterface;
7 use Drupal\Tests\BrowserTestBase;
10 * Adds and configures custom languages.
14 class LanguageCustomLanguageConfigurationTest extends BrowserTestBase {
21 public static $modules = ['language'];
24 * Functional tests for adding, editing and deleting languages.
26 public function testLanguageConfiguration() {
28 // Create user with permissions to add and remove languages.
29 $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
30 $this->drupalLogin($admin_user);
32 // Add custom language.
34 'predefined_langcode' => 'custom',
36 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
37 // Test validation on missing values.
38 $this->assertText(t('@name field is required.', ['@name' => t('Language code')]));
39 $this->assertText(t('@name field is required.', ['@name' => t('Language name')]));
40 $empty_language = new Language();
41 $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
42 $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
44 // Test validation of invalid values.
46 'predefined_langcode' => 'custom',
47 'langcode' => 'white space',
48 'label' => '<strong>evil markup</strong>',
49 'direction' => LanguageInterface::DIRECTION_LTR,
51 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
53 $this->assertRaw(t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', [
54 '%field' => t('Language code'),
55 ':url' => 'http://www.w3.org/International/articles/language-tags/',
58 $this->assertRaw(t('%field cannot contain any markup.', ['%field' => t('Language name')]));
59 $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
61 // Test adding a custom language with a numeric region code.
63 'predefined_langcode' => 'custom',
64 'langcode' => 'es-419',
65 'label' => 'Latin American Spanish',
66 'direction' => LanguageInterface::DIRECTION_LTR,
69 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
71 'The language %language has been created and can now be used.',
72 ['%language' => $edit['label']]
74 $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
76 // Test validation of existing language values.
78 'predefined_langcode' => 'custom',
81 'direction' => LanguageInterface::DIRECTION_LTR,
84 // Add the language the first time.
85 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
87 'The language %language has been created and can now be used.',
88 ['%language' => $edit['label']]
90 $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
92 // Add the language a second time and confirm that this is not allowed.
93 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
95 'The language %language (%langcode) already exists.',
96 ['%language' => $edit['label'], '%langcode' => $edit['langcode']]
98 $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');