comparison core/modules/user/tests/src/Functional/UserLanguageTest.php @ 0:4c8ae668cc8c

Initial import (non-working)
author Chris Cannam
date Wed, 29 Nov 2017 16:09:58 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:4c8ae668cc8c
1 <?php
2
3 namespace Drupal\Tests\user\Functional;
4
5 use Drupal\Core\Language\LanguageInterface;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9 * Functional tests for a user's ability to change their default language.
10 *
11 * @group user
12 */
13 class UserLanguageTest extends BrowserTestBase {
14
15 /**
16 * Modules to enable.
17 *
18 * @var array
19 */
20 public static $modules = ['user', 'language'];
21
22 /**
23 * Test if user can change their default language.
24 */
25 public function testUserLanguageConfiguration() {
26 // User to add and remove language.
27 $admin_user = $this->drupalCreateUser(['administer languages', 'access administration pages']);
28 // User to change their default language.
29 $web_user = $this->drupalCreateUser();
30
31 // Add custom language.
32 $this->drupalLogin($admin_user);
33 // Code for the language.
34 $langcode = 'xx';
35 // The English name for the language.
36 $name = $this->randomMachineName(16);
37 $edit = [
38 'predefined_langcode' => 'custom',
39 'langcode' => $langcode,
40 'label' => $name,
41 'direction' => LanguageInterface::DIRECTION_LTR,
42 ];
43 $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add custom language'));
44 $this->drupalLogout();
45
46 // Log in as normal user and edit account settings.
47 $this->drupalLogin($web_user);
48 $path = 'user/' . $web_user->id() . '/edit';
49 $this->drupalGet($path);
50 // Ensure language settings widget is available.
51 $this->assertText(t('Language'), 'Language selector available.');
52 // Ensure custom language is present.
53 $this->assertText($name, 'Language present on form.');
54 // Switch to our custom language.
55 $edit = [
56 'preferred_langcode' => $langcode,
57 ];
58 $this->drupalPostForm($path, $edit, t('Save'));
59 // Ensure form was submitted successfully.
60 $this->assertText(t('The changes have been saved.'), 'Changes were saved.');
61 // Check if language was changed.
62 $this->assertOptionSelected('edit-preferred-langcode', $langcode, 'Default language successfully updated.');
63
64 $this->drupalLogout();
65 }
66
67 }