X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=web%2Fcore%2Fmodules%2Flanguage%2Ftests%2Fsrc%2FFunctional%2FLanguageCustomLanguageConfigurationTest.php;fp=web%2Fcore%2Fmodules%2Flanguage%2Ftests%2Fsrc%2FFunctional%2FLanguageCustomLanguageConfigurationTest.php;h=a0510beca72a0bb193f83d931068d323dbcc4364;hb=9917807b03b64faf00f6a1f29dcb6eafc454efa5;hp=0000000000000000000000000000000000000000;hpb=aea91e65e895364e460983b890e295aa5d5540a5;p=yaffs-website
diff --git a/web/core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php b/web/core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php
new file mode 100644
index 000000000..a0510beca
--- /dev/null
+++ b/web/core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php
@@ -0,0 +1,101 @@
+drupalCreateUser(['administer languages', 'access administration pages']);
+ $this->drupalLogin($admin_user);
+
+ // Add custom language.
+ $edit = [
+ 'predefined_langcode' => 'custom',
+ ];
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
+ // Test validation on missing values.
+ $this->assertText(t('@name field is required.', ['@name' => t('Language code')]));
+ $this->assertText(t('@name field is required.', ['@name' => t('Language name')]));
+ $empty_language = new Language();
+ $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
+ $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+
+ // Test validation of invalid values.
+ $edit = [
+ 'predefined_langcode' => 'custom',
+ 'langcode' => 'white space',
+ 'label' => 'evil markup',
+ 'direction' => LanguageInterface::DIRECTION_LTR,
+ ];
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
+
+ $this->assertRaw(t('%field must be a valid language tag as defined by the W3C.', [
+ '%field' => t('Language code'),
+ ':url' => 'http://www.w3.org/International/articles/language-tags/',
+ ]));
+
+ $this->assertRaw(t('%field cannot contain any markup.', ['%field' => t('Language name')]));
+ $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+
+ // Test adding a custom language with a numeric region code.
+ $edit = [
+ 'predefined_langcode' => 'custom',
+ 'langcode' => 'es-419',
+ 'label' => 'Latin American Spanish',
+ 'direction' => LanguageInterface::DIRECTION_LTR,
+ ];
+
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
+ $this->assertRaw(t(
+ 'The language %language has been created and can now be used.',
+ ['%language' => $edit['label']]
+ ));
+ $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+
+ // Test validation of existing language values.
+ $edit = [
+ 'predefined_langcode' => 'custom',
+ 'langcode' => 'de',
+ 'label' => 'German',
+ 'direction' => LanguageInterface::DIRECTION_LTR,
+ ];
+
+ // Add the language the first time.
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
+ $this->assertRaw(t(
+ 'The language %language has been created and can now be used.',
+ ['%language' => $edit['label']]
+ ));
+ $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+
+ // Add the language a second time and confirm that this is not allowed.
+ $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
+ $this->assertRaw(t(
+ 'The language %language (%langcode) already exists.',
+ ['%language' => $edit['label'], '%langcode' => $edit['langcode']]
+ ));
+ $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.');
+ }
+
+}