3 namespace Drupal\Tests\config_translation\Functional;
5 use Drupal\Component\Utility\Html;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase;
10 * Translate settings and entities to various languages.
12 * @group config_translation
14 class ConfigTranslationOverviewTest extends BrowserTestBase {
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, count($dropbutton->findAll('xpath', 'li')));
81 $this->assertTrue(($dropbutton->getText() === 'Translate') || ($dropbutton->getText() === 'List'));
86 'some "label" with quotes',
87 $this->randomString(),
90 $storage = \Drupal::entityTypeManager()->getStorage('config_test');
91 foreach ($labels as $label) {
92 $test_entity = $storage->create([
93 'id' => $this->randomMachineName(),
98 $base_url = 'admin/structure/config_test/manage/' . $test_entity->id();
99 $this->drupalGet('admin/config/regional/config-translation/config_test');
100 $this->assertLinkByHref($base_url . '/translate');
101 $this->assertEscaped($test_entity->label());
103 // Make sure there is only a single 'Translate' operation for each
105 foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
106 $this->assertIdentical(1, count($dropbutton->findAll('xpath', 'li')));
107 $this->assertIdentical('Translate', $dropbutton->getText());
110 $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
111 $this->drupalGet($base_url . '/translate');
113 $title = $test_entity->label() . ' ' . $entity_type->getLowercaseLabel();
114 $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
115 $this->assertRaw($title);
116 $this->assertRaw('<th>' . t('Language') . '</th>');
118 $this->drupalGet($base_url);
119 $this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
124 * Tests availability of hidden entities in the translation overview.
126 public function testHiddenEntities() {
127 // Hidden languages are only available to translate through the
128 // configuration translation listings.
129 $this->drupalGet('admin/config/regional/config-translation/configurable_language');
130 $this->assertText('Not applicable');
131 $this->assertLinkByHref('admin/config/regional/language/edit/zxx/translate');
132 $this->assertText('Not specified');
133 $this->assertLinkByHref('admin/config/regional/language/edit/und/translate');
135 // Hidden date formats are only available to translate through the
136 // configuration translation listings. Test a couple of them.
137 $this->drupalGet('admin/config/regional/config-translation/date_format');
138 $this->assertText('HTML Date');
139 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_date/translate');
140 $this->assertText('HTML Year');
141 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_year/translate');
145 * Tests that overrides do not affect listing screens.
147 public function testListingPageWithOverrides() {
148 $original_label = 'Default';
149 $overridden_label = 'Overridden label';
151 $config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
153 // Set up an override.
154 $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
155 'value' => $overridden_label,
158 $this->writeSettings($settings);
160 // Test that the overridden label is loaded with the entity.
161 $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
163 // Test that the original label on the listing page is intact.
164 $this->drupalGet('admin/config/regional/config-translation/config_test');
165 $this->assertText($original_label);
166 $this->assertNoText($overridden_label);