ConfigTranslationOverviewTest.php 3.97 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
<?php

/**
 * @file
 * Contains \Drupal\config_translation\Tests\ConfigTranslationOverviewTest.
 */

namespace Drupal\config_translation\Tests;

use Drupal\Component\Utility\String;
11
use Drupal\language\Entity\ConfigurableLanguage;
12 13 14
use Drupal\simpletest\WebTestBase;

/**
15 16 17
 * Translate settings and entities to various languages.
 *
 * @group config_translation
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 */
class ConfigTranslationOverviewTest extends WebTestBase {

  /**
   * Modules to enable.
   *
   * @var array
   */
  public static $modules = array('contact', 'config_translation', 'views', 'views_ui', 'contextual', 'config_test', 'config_translation_test');

  /**
   * Languages to enable.
   *
   * @var array
   */
  protected $langcodes = array('fr', 'ta');

  /**
   * String translation storage object.
   *
   * @var \Drupal\locale\StringStorageInterface
   */
  protected $localeStorage;

42
  protected function setUp() {
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    parent::setUp();
    $permissions = array(
      'translate configuration',
      'administer languages',
      'administer site configuration',
      'administer contact forms',
      'access site-wide contact form',
      'access contextual links',
      'administer views',
    );
    // Create and login user.
    $this->drupalLogin($this->drupalCreateUser($permissions));

    // Add languages.
    foreach ($this->langcodes as $langcode) {
58
      ConfigurableLanguage::createFromLangcode($langcode)->save();
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    }
    $this->localeStorage = $this->container->get('locale.storage');
  }

  /**
   * Tests the config translation mapper page.
   */
  public function testMapperListPage() {
    $this->drupalGet('admin/config/regional/config-translation');
    $this->assertLinkByHref('admin/config/regional/config-translation/config_test');
    $this->assertLinkByHref('admin/config/people/accounts/translate');

    $labels = array(
      '&$nxd~i0',
      'some "label" with quotes',
      $this->randomString(),
    );

    foreach ($labels as $label) {
      $test_entity = entity_create('config_test', array(
79
        'id' => $this->randomMachineName(),
80 81 82 83 84 85 86 87 88
        'label' => $label,
      ));
      $test_entity->save();

      $base_url = 'admin/structure/config_test/manage/' . $test_entity->id();
      $this->drupalGet('admin/config/regional/config-translation/config_test');
      $this->assertLinkByHref($base_url . '/translate');
      $this->assertText(String::checkPlain($test_entity->label()));

89
      $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
90 91
      $this->drupalGet($base_url . '/translate');

92
      $title = t('!label !entity_type', array('!label' => $test_entity->label(), '!entity_type' => $entity_type->getLowercaseLabel()));
93 94 95 96 97
      $title = t('Translations for %label', array('%label' => $title));
      $this->assertRaw($title);
      $this->assertRaw('<th>' . t('Language') . '</th>');

      $this->drupalGet($base_url);
98
      $this->assertLink(t('Translate @title', array('@title' => $entity_type->getLowercaseLabel())));
99 100 101 102 103 104 105 106 107
    }
  }

  /**
   * Tests availability of hidden entities in the translation overview.
   */
  public function testHiddenEntities() {
    // Hidden languages are only available to translate through the
    // configuration translation listings.
108
    $this->drupalGet('admin/config/regional/config-translation/configurable_language');
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
    $this->assertText('Not applicable');
    $this->assertLinkByHref('admin/config/regional/language/edit/zxx/translate');
    $this->assertText('Not specified');
    $this->assertLinkByHref('admin/config/regional/language/edit/und/translate');

    // Hidden date formats are only available to translate through the
    // configuration translation listings. Test a couple of them.
    $this->drupalGet('admin/config/regional/config-translation/date_format');
    $this->assertText('HTML Date');
    $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_date/translate');
    $this->assertText('HTML Year');
    $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_year/translate');
  }

}