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