Chris@14
|
1 <?php
|
Chris@14
|
2
|
Chris@14
|
3 namespace Drupal\Tests\user\Functional;
|
Chris@14
|
4
|
Chris@14
|
5 use Drupal\Tests\content_translation\Functional\ContentTranslationUITestBase;
|
Chris@14
|
6
|
Chris@14
|
7 /**
|
Chris@14
|
8 * Tests the User Translation UI.
|
Chris@14
|
9 *
|
Chris@14
|
10 * @group user
|
Chris@14
|
11 */
|
Chris@14
|
12 class UserTranslationUITest extends ContentTranslationUITestBase {
|
Chris@14
|
13
|
Chris@14
|
14 /**
|
Chris@14
|
15 * The user name of the test user.
|
Chris@14
|
16 *
|
Chris@14
|
17 * @var string
|
Chris@14
|
18 */
|
Chris@14
|
19 protected $name;
|
Chris@14
|
20
|
Chris@14
|
21 /**
|
Chris@14
|
22 * Modules to enable.
|
Chris@14
|
23 *
|
Chris@14
|
24 * @var array
|
Chris@14
|
25 */
|
Chris@14
|
26 public static $modules = ['language', 'content_translation', 'user', 'views'];
|
Chris@14
|
27
|
Chris@14
|
28 protected function setUp() {
|
Chris@14
|
29 $this->entityTypeId = 'user';
|
Chris@14
|
30 $this->testLanguageSelector = FALSE;
|
Chris@14
|
31 $this->name = $this->randomMachineName();
|
Chris@14
|
32 parent::setUp();
|
Chris@14
|
33
|
Chris@14
|
34 \Drupal::entityManager()->getStorage('user')->resetCache();
|
Chris@14
|
35 }
|
Chris@14
|
36
|
Chris@14
|
37 /**
|
Chris@14
|
38 * {@inheritdoc}
|
Chris@14
|
39 */
|
Chris@14
|
40 protected function getTranslatorPermissions() {
|
Chris@14
|
41 return array_merge(parent::getTranslatorPermissions(), ['administer users']);
|
Chris@14
|
42 }
|
Chris@14
|
43
|
Chris@14
|
44 /**
|
Chris@14
|
45 * {@inheritdoc}
|
Chris@14
|
46 */
|
Chris@14
|
47 protected function getNewEntityValues($langcode) {
|
Chris@14
|
48 // User name is not translatable hence we use a fixed value.
|
Chris@14
|
49 return ['name' => $this->name] + parent::getNewEntityValues($langcode);
|
Chris@14
|
50 }
|
Chris@14
|
51
|
Chris@14
|
52 /**
|
Chris@14
|
53 * {@inheritdoc}
|
Chris@14
|
54 */
|
Chris@14
|
55 protected function doTestTranslationEdit() {
|
Chris@14
|
56 $storage = $this->container->get('entity_type.manager')
|
Chris@14
|
57 ->getStorage($this->entityTypeId);
|
Chris@14
|
58 $storage->resetCache([$this->entityId]);
|
Chris@14
|
59 $entity = $storage->load($this->entityId);
|
Chris@14
|
60 $languages = $this->container->get('language_manager')->getLanguages();
|
Chris@14
|
61
|
Chris@14
|
62 foreach ($this->langcodes as $langcode) {
|
Chris@14
|
63 // We only want to test the title for non-english translations.
|
Chris@14
|
64 if ($langcode != 'en') {
|
Chris@14
|
65 $options = ['language' => $languages[$langcode]];
|
Chris@18
|
66 $url = $entity->toUrl('edit-form', $options);
|
Chris@14
|
67 $this->drupalGet($url);
|
Chris@14
|
68
|
Chris@14
|
69 $title = t('@title [%language translation]', [
|
Chris@14
|
70 '@title' => $entity->getTranslation($langcode)->label(),
|
Chris@14
|
71 '%language' => $languages[$langcode]->getName(),
|
Chris@14
|
72 ]);
|
Chris@14
|
73 $this->assertRaw($title);
|
Chris@14
|
74 }
|
Chris@14
|
75 }
|
Chris@14
|
76 }
|
Chris@14
|
77
|
Chris@16
|
78 /**
|
Chris@16
|
79 * Test translated user deletion.
|
Chris@16
|
80 */
|
Chris@16
|
81 public function testTranslatedUserDeletion() {
|
Chris@16
|
82 $this->drupalLogin($this->administrator);
|
Chris@16
|
83 $entity_id = $this->createEntity($this->getNewEntityValues('en'), 'en');
|
Chris@16
|
84
|
Chris@16
|
85 $entity = $this->container->get('entity_type.manager')
|
Chris@16
|
86 ->getStorage($this->entityTypeId)
|
Chris@16
|
87 ->load($entity_id);
|
Chris@16
|
88 $translated_entity = $entity->addTranslation('fr');
|
Chris@16
|
89 $translated_entity->save();
|
Chris@16
|
90
|
Chris@16
|
91 $url = $entity->toUrl(
|
Chris@16
|
92 'edit-form',
|
Chris@16
|
93 ['language' => $this->container->get('language_manager')->getLanguage('en')]
|
Chris@16
|
94 );
|
Chris@16
|
95 $this->drupalPostForm($url, [], t('Cancel account'));
|
Chris@16
|
96 $this->assertSession()->statusCodeEquals(200);
|
Chris@16
|
97 }
|
Chris@16
|
98
|
Chris@14
|
99 }
|