annotate core/modules/language/tests/src/Functional/LanguageCustomLanguageConfigurationTest.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents af1871eacc83
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Tests\language\Functional;
Chris@0 4
Chris@18 5 use Drupal\Core\Url;
Chris@0 6 use Drupal\Core\Language\Language;
Chris@0 7 use Drupal\Core\Language\LanguageInterface;
Chris@0 8 use Drupal\Tests\BrowserTestBase;
Chris@0 9
Chris@0 10 /**
Chris@0 11 * Adds and configures custom languages.
Chris@0 12 *
Chris@0 13 * @group language
Chris@0 14 */
Chris@0 15 class LanguageCustomLanguageConfigurationTest extends BrowserTestBase {
Chris@0 16
Chris@0 17 /**
Chris@0 18 * Modules to enable.
Chris@0 19 *
Chris@0 20 * @var array
Chris@0 21 */
Chris@0 22 public static $modules = ['language'];
Chris@0 23
Chris@0 24 /**
Chris@0 25 * Functional tests for adding, editing and deleting languages.
Chris@0 26 */
Chris@0 27 public function testLanguageConfiguration() {
Chris@0 28
Chris@0 29 // Create user with permissions to add and remove languages.
Chris@0 30 $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
Chris@0 31 $this->drupalLogin($admin_user);
Chris@0 32
Chris@0 33 // Add custom language.
Chris@0 34 $edit = [
Chris@0 35 'predefined_langcode' => 'custom',
Chris@0 36 ];
Chris@0 37 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0 38 // Test validation on missing values.
Chris@0 39 $this->assertText(t('@name field is required.', ['@name' => t('Language code')]));
Chris@0 40 $this->assertText(t('@name field is required.', ['@name' => t('Language name')]));
Chris@0 41 $empty_language = new Language();
Chris@0 42 $this->assertFieldChecked('edit-direction-' . $empty_language->getDirection(), 'Consistent usage of language direction.');
Chris@18 43 $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0 44
Chris@0 45 // Test validation of invalid values.
Chris@0 46 $edit = [
Chris@0 47 'predefined_langcode' => 'custom',
Chris@0 48 'langcode' => 'white space',
Chris@0 49 'label' => '<strong>evil markup</strong>',
Chris@0 50 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0 51 ];
Chris@0 52 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0 53
Chris@0 54 $this->assertRaw(t('%field must be a valid language tag as <a href=":url">defined by the W3C</a>.', [
Chris@0 55 '%field' => t('Language code'),
Chris@0 56 ':url' => 'http://www.w3.org/International/articles/language-tags/',
Chris@0 57 ]));
Chris@0 58
Chris@0 59 $this->assertRaw(t('%field cannot contain any markup.', ['%field' => t('Language name')]));
Chris@18 60 $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0 61
Chris@0 62 // Test adding a custom language with a numeric region code.
Chris@0 63 $edit = [
Chris@0 64 'predefined_langcode' => 'custom',
Chris@0 65 'langcode' => 'es-419',
Chris@0 66 'label' => 'Latin American Spanish',
Chris@0 67 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0 68 ];
Chris@0 69
Chris@0 70 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0 71 $this->assertRaw(t(
Chris@0 72 'The language %language has been created and can now be used.',
Chris@0 73 ['%language' => $edit['label']]
Chris@0 74 ));
Chris@18 75 $this->assertUrl(Url::fromRoute('entity.configurable_language.collection', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0 76
Chris@0 77 // Test validation of existing language values.
Chris@0 78 $edit = [
Chris@0 79 'predefined_langcode' => 'custom',
Chris@0 80 'langcode' => 'de',
Chris@0 81 'label' => 'German',
Chris@0 82 'direction' => LanguageInterface::DIRECTION_LTR,
Chris@0 83 ];
Chris@0 84
Chris@0 85 // Add the language the first time.
Chris@0 86 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0 87 $this->assertRaw(t(
Chris@0 88 'The language %language has been created and can now be used.',
Chris@0 89 ['%language' => $edit['label']]
Chris@0 90 ));
Chris@18 91 $this->assertUrl(Url::fromRoute('entity.configurable_language.collection', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0 92
Chris@0 93 // Add the language a second time and confirm that this is not allowed.
Chris@0 94 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
Chris@0 95 $this->assertRaw(t(
Chris@0 96 'The language %language (%langcode) already exists.',
Chris@0 97 ['%language' => $edit['label'], '%langcode' => $edit['langcode']]
Chris@0 98 ));
Chris@18 99 $this->assertUrl(Url::fromRoute('language.add', [], ['absolute' => TRUE])->toString(), [], 'Correct page redirection.');
Chris@0 100 }
Chris@0 101
Chris@0 102 }