3 namespace Drupal\config_translation\Tests;
5 use Drupal\Component\Utility\Html;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\simpletest\WebTestBase;
10 * Translate settings and entities to various languages.
12 * @group config_translation
14 class ConfigTranslationOverviewTest extends WebTestBase {
21 public static $modules = [
25 'config_translation_test',
28 'entity_test_operation',
34 * Languages to enable.
38 protected $langcodes = ['fr', 'ta'];
41 * String translation storage object.
43 * @var \Drupal\locale\StringStorageInterface
45 protected $localeStorage;
47 protected function setUp() {
50 'translate configuration',
51 'administer languages',
52 'administer site configuration',
53 'administer contact forms',
54 'access site-wide contact form',
55 'access contextual links',
58 // Create and log in user.
59 $this->drupalLogin($this->drupalCreateUser($permissions));
62 foreach ($this->langcodes as $langcode) {
63 ConfigurableLanguage::createFromLangcode($langcode)->save();
65 $this->localeStorage = $this->container->get('locale.storage');
66 $this->drupalPlaceBlock('local_tasks_block');
67 $this->drupalPlaceBlock('page_title_block');
71 * Tests the config translation mapper page.
73 public function testMapperListPage() {
74 $this->drupalGet('admin/config/regional/config-translation');
75 $this->assertLinkByHref('admin/config/regional/config-translation/config_test');
76 $this->assertLinkByHref('admin/config/people/accounts/translate');
77 // Make sure there is only a single operation for each dropbutton, either
78 // 'List' or 'Translate'.
79 foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
80 $this->assertIdentical(1, $dropbutton->count());
81 foreach ($dropbutton->li as $link) {
82 $this->assertTrue(((string) $link->a === 'Translate') || ((string) $link->a === 'List'));
88 'some "label" with quotes',
89 $this->randomString(),
92 foreach ($labels as $label) {
93 $test_entity = entity_create('config_test', [
94 'id' => $this->randomMachineName(),
99 $base_url = 'admin/structure/config_test/manage/' . $test_entity->id();
100 $this->drupalGet('admin/config/regional/config-translation/config_test');
101 $this->assertLinkByHref($base_url . '/translate');
102 $this->assertEscaped($test_entity->label());
104 // Make sure there is only a single 'Translate' operation for each
106 foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
107 $this->assertIdentical(1, $dropbutton->count());
108 foreach ($dropbutton->li as $link) {
109 $this->assertIdentical('Translate', (string) $link->a);
113 $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
114 $this->drupalGet($base_url . '/translate');
116 $title = $test_entity->label() . ' ' . $entity_type->getLowercaseLabel();
117 $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
118 $this->assertRaw($title);
119 $this->assertRaw('<th>' . t('Language') . '</th>');
121 $this->drupalGet($base_url);
122 $this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
127 * Tests availability of hidden entities in the translation overview.
129 public function testHiddenEntities() {
130 // Hidden languages are only available to translate through the
131 // configuration translation listings.
132 $this->drupalGet('admin/config/regional/config-translation/configurable_language');
133 $this->assertText('Not applicable');
134 $this->assertLinkByHref('admin/config/regional/language/edit/zxx/translate');
135 $this->assertText('Not specified');
136 $this->assertLinkByHref('admin/config/regional/language/edit/und/translate');
138 // Hidden date formats are only available to translate through the
139 // configuration translation listings. Test a couple of them.
140 $this->drupalGet('admin/config/regional/config-translation/date_format');
141 $this->assertText('HTML Date');
142 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_date/translate');
143 $this->assertText('HTML Year');
144 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_year/translate');
148 * Tests that overrides do not affect listing screens.
150 public function testListingPageWithOverrides() {
151 $original_label = 'Default';
152 $overridden_label = 'Overridden label';
154 $config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
156 // Set up an override.
157 $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
158 'value' => $overridden_label,
161 $this->writeSettings($settings);
163 // Test that the overridden label is loaded with the entity.
164 $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
166 // Test that the original label on the listing page is intact.
167 $this->drupalGet('admin/config/regional/config-translation/config_test');
168 $this->assertText($original_label);
169 $this->assertNoText($overridden_label);