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->find('xpath', 'li')));
81 $this->assertTrue(($dropbutton->getText() === 'Translate') || ($dropbutton->getText() === 'List'));
86 'some "label" with quotes',
87 $this->randomString(),
90 foreach ($labels as $label) {
91 $test_entity = entity_create('config_test', [
92 'id' => $this->randomMachineName(),
97 $base_url = 'admin/structure/config_test/manage/' . $test_entity->id();
98 $this->drupalGet('admin/config/regional/config-translation/config_test');
99 $this->assertLinkByHref($base_url . '/translate');
100 $this->assertEscaped($test_entity->label());
102 // Make sure there is only a single 'Translate' operation for each
104 foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
105 $this->assertIdentical(1, count($dropbutton->find('xpath', 'li')));
106 $this->assertIdentical('Translate', $dropbutton->getText());
109 $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
110 $this->drupalGet($base_url . '/translate');
112 $title = $test_entity->label() . ' ' . $entity_type->getLowercaseLabel();
113 $title = 'Translations for <em class="placeholder">' . Html::escape($title) . '</em>';
114 $this->assertRaw($title);
115 $this->assertRaw('<th>' . t('Language') . '</th>');
117 $this->drupalGet($base_url);
118 $this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
123 * Tests availability of hidden entities in the translation overview.
125 public function testHiddenEntities() {
126 // Hidden languages are only available to translate through the
127 // configuration translation listings.
128 $this->drupalGet('admin/config/regional/config-translation/configurable_language');
129 $this->assertText('Not applicable');
130 $this->assertLinkByHref('admin/config/regional/language/edit/zxx/translate');
131 $this->assertText('Not specified');
132 $this->assertLinkByHref('admin/config/regional/language/edit/und/translate');
134 // Hidden date formats are only available to translate through the
135 // configuration translation listings. Test a couple of them.
136 $this->drupalGet('admin/config/regional/config-translation/date_format');
137 $this->assertText('HTML Date');
138 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_date/translate');
139 $this->assertText('HTML Year');
140 $this->assertLinkByHref('admin/config/regional/date-time/formats/manage/html_year/translate');
144 * Tests that overrides do not affect listing screens.
146 public function testListingPageWithOverrides() {
147 $original_label = 'Default';
148 $overridden_label = 'Overridden label';
150 $config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
152 // Set up an override.
153 $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
154 'value' => $overridden_label,
157 $this->writeSettings($settings);
159 // Test that the overridden label is loaded with the entity.
160 $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
162 // Test that the original label on the listing page is intact.
163 $this->drupalGet('admin/config/regional/config-translation/config_test');
164 $this->assertText($original_label);
165 $this->assertNoText($overridden_label);