annotate core/modules/user/tests/src/Functional/UserTranslationUITest.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents
children c2387f117808
rev   line source
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@14 66 $url = $entity->urlInfo('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@14 78 }