Mercurial > hg > isophonics-drupal-site
comparison 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 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Tests\language\Functional; | |
4 | |
5 use Drupal\Core\Language\Language; | |
6 use Drupal\Core\Language\LanguageInterface; | |
7 use Drupal\Tests\BrowserTestBase; | |
8 | |
9 /** | |
10 * Adds and configures custom languages. | |
11 * | |
12 * @group language | |
13 */ | |
14 class LanguageCustomLanguageConfigurationTest extends BrowserTestBase { | |
15 | |
16 /** | |
17 * Modules to enable. | |
18 * | |
19 * @var array | |
20 */ | |
21 public static $modules = ['language']; | |
22 | |
23 /** | |
24 * Functional tests for adding, editing and deleting languages. | |
25 */ | |
26 public function testLanguageConfiguration() { | |
27 | |
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); | |
31 | |
32 // Add custom language. | |
33 $edit = [ | |
34 'predefined_langcode' => 'custom', | |
35 ]; | |
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.'); | |
43 | |
44 // Test validation of invalid values. | |
45 $edit = [ | |
46 'predefined_langcode' => 'custom', | |
47 'langcode' => 'white space', | |
48 'label' => '<strong>evil markup</strong>', | |
49 'direction' => LanguageInterface::DIRECTION_LTR, | |
50 ]; | |
51 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); | |
52 | |
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/', | |
56 ])); | |
57 | |
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.'); | |
60 | |
61 // Test adding a custom language with a numeric region code. | |
62 $edit = [ | |
63 'predefined_langcode' => 'custom', | |
64 'langcode' => 'es-419', | |
65 'label' => 'Latin American Spanish', | |
66 'direction' => LanguageInterface::DIRECTION_LTR, | |
67 ]; | |
68 | |
69 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); | |
70 $this->assertRaw(t( | |
71 'The language %language has been created and can now be used.', | |
72 ['%language' => $edit['label']] | |
73 )); | |
74 $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.'); | |
75 | |
76 // Test validation of existing language values. | |
77 $edit = [ | |
78 'predefined_langcode' => 'custom', | |
79 'langcode' => 'de', | |
80 'label' => 'German', | |
81 'direction' => LanguageInterface::DIRECTION_LTR, | |
82 ]; | |
83 | |
84 // Add the language the first time. | |
85 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language')); | |
86 $this->assertRaw(t( | |
87 'The language %language has been created and can now be used.', | |
88 ['%language' => $edit['label']] | |
89 )); | |
90 $this->assertUrl(\Drupal::url('entity.configurable_language.collection', [], ['absolute' => TRUE]), [], 'Correct page redirection.'); | |
91 | |
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')); | |
94 $this->assertRaw(t( | |
95 'The language %language (%langcode) already exists.', | |
96 ['%language' => $edit['label'], '%langcode' => $edit['langcode']] | |
97 )); | |
98 $this->assertUrl(\Drupal::url('language.add', [], ['absolute' => TRUE]), [], 'Correct page redirection.'); | |
99 } | |
100 | |
101 } |