Chris@0: drupalCreateUser(['administer languages', 'access administration pages']);
Chris@0: $this->drupalLogin($admin_user);
Chris@0:
Chris@0: // Add custom language.
Chris@0: $edit = [
Chris@0: 'predefined_langcode' => 'custom',
Chris@0: ];
Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0: // Test validation on missing values.
Chris@0: $this->assertText(t('@name field is required.', ['@name' => t('Language code')]));
Chris@0: $this->assertText(t('@name field is required.', ['@name' => t('Language name')]));
Chris@0: $empty_language = new Language();
Chris@0: $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
Chris@18: $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0:
Chris@0: // Test validation of invalid values.
Chris@0: $edit = [
Chris@0: 'predefined_langcode' => 'custom',
Chris@0: 'langcode' => 'white space',
Chris@0: 'label' => 'evil markup',
Chris@0: 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0: ];
Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0:
Chris@0: $this->assertRaw(t('%field must be a valid language tag as defined by the W3C.', [
Chris@0: '%field' => t('Language code'),
Chris@0: ':url' => 'http://www.w3.org/International/articles/language-tags/',
Chris@0: ]));
Chris@0:
Chris@0: $this->assertRaw(t('%field cannot contain any markup.', ['%field' => t('Language name')]));
Chris@18: $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0:
Chris@0: // Test adding a custom language with a numeric region code.
Chris@0: $edit = [
Chris@0: 'predefined_langcode' => 'custom',
Chris@0: 'langcode' => 'es-419',
Chris@0: 'label' => 'Latin American Spanish',
Chris@0: 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0: ];
Chris@0:
Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0: $this->assertRaw(t(
Chris@0: 'The language %language has been created and can now be used.',
Chris@0: ['%language' => $edit['label']]
Chris@0: ));
Chris@18: $this->assertUrl(Url::fromRoute('entity.configurable_language.collection', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0:
Chris@0: // Test validation of existing language values.
Chris@0: $edit = [
Chris@0: 'predefined_langcode' => 'custom',
Chris@0: 'langcode' => 'de',
Chris@0: 'label' => 'German',
Chris@0: 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0: ];
Chris@0:
Chris@0: // Add the language the first time.
Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0: $this->assertRaw(t(
Chris@0: 'The language %language has been created and can now be used.',
Chris@0: ['%language' => $edit['label']]
Chris@0: ));
Chris@18: $this->assertUrl(Url::fromRoute('entity.configurable_language.collection', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0:
Chris@0: // Add the language a second time and confirm that this is not allowed.
Chris@0: $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0: $this->assertRaw(t(
Chris@0: 'The language %language (%langcode) already exists.',
Chris@0: ['%language' => $edit['label'], '%langcode' => $edit['langcode']]
Chris@0: ));
Chris@18: $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0: }
Chris@0:
Chris@0: }