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

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

namespace Drupal\config_translation\Tests;

use Drupal\Component\Utility\String;
use Drupal\Core\Language\Language;
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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
 */
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;

  public function setUp() {
    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) {
      $language = new Language(array('id' => $langcode));
      language_save($language);
    }
    $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(
80
        'id' => $this->randomMachineName(),
81 82 83 84 85 86 87 88 89
        '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()));

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

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

      $this->drupalGet($base_url);
99
      $this->assertLink(t('Translate @title', array('@title' => $entity_type->getLowercaseLabel())));
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
    }
  }

  /**
   * Tests availability of hidden entities in the translation overview.
   */
  public function testHiddenEntities() {
    // Hidden languages are only available to translate through the
    // configuration translation listings.
    $this->drupalGet('admin/config/regional/config-translation/language_entity');
    $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');
  }

}