annotate core/modules/user/tests/src/Functional/UserTranslationUITest.php @ 5:12f9dff5fda9 tip

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