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