LanguageSelectorTranslatableTest.php 2.3 KB
Newer Older
1 2
<?php

3
namespace Drupal\Tests\language\Functional;
4

5
use Drupal\Tests\BrowserTestBase;
6 7 8 9 10 11

/**
 * Tests the content translation settings language selector options.
 *
 * @group language
 */
12
class LanguageSelectorTranslatableTest extends BrowserTestBase {
13 14 15 16 17 18

  /**
   * Modules to enable.
   *
   * @var array
   */
19
  public static $modules = [
20 21 22 23 24 25 26
    'language',
    'content_translation',
    'node',
    'comment',
    'field_ui',
    'entity_test',
    'locale',
27
  ];
28 29 30 31

  /**
   * The user with administrator privileges.
   *
32
   * @var \Drupal\user\Entity\User
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
   */
  public $administrator;

  /**
   * {@inheritdoc}
   */
  protected function setUp() {
    parent::setUp();

    // Create user and set permissions.
    $this->administrator = $this->drupalCreateUser($this->getAdministratorPermissions(), 'administrator');
    $this->drupalLogin($this->administrator);
  }

  /**
   * Returns an array of permissions needed for the translator.
   */
  protected function getAdministratorPermissions() {
    return array_filter(
52
      ['translate interface',
53 54 55 56 57
        'administer content translation',
        'create content translations',
        'update content translations',
        'delete content translations',
        'administer languages',
58
      ]
59 60 61 62 63 64 65 66
    );
  }

  /**
   * Tests content translation language selectors are correctly translated.
   */
  public function testLanguageStringSelector() {
    // Add another language.
67
    $edit = ['predefined_langcode' => 'es'];
68 69 70 71 72 73 74 75 76 77 78 79 80 81
    $this->drupalPostForm('admin/config/regional/language/add', $edit, t('Add language'));

    // Translate the string English in Spanish (Inglés). Override config entity.
    $name_translation = 'Inglés';
    \Drupal::languageManager()
      ->getLanguageConfigOverride('es', 'language.entity.en')
      ->set('label', $name_translation)
      ->save();

    // Check content translation overview selector.
    $path = 'es/admin/config/regional/content-language';
    $this->drupalGet($path);

    // Get en language from selector.
82
    $elements = $this->xpath('//select[@id=:id]//option[@value=:option]', [':id' => 'edit-settings-user-user-settings-language-langcode', ':option' => 'en']);
83 84

    // Check that the language text is translated.
85
    $this->assertEqual($elements[0]->getText(), $name_translation, 'Checking the option string English is translated to Spanish.');
86 87 88
  }

}