Backup of db before drupal security update
[yaffs-website] / web / core / modules / config_translation / tests / src / Functional / ConfigTranslationOverviewTest.php
1 <?php
2
3 namespace Drupal\Tests\config_translation\Functional;
4
5 use Drupal\Component\Utility\Html;
6 use Drupal\language\Entity\ConfigurableLanguage;
7 use Drupal\Tests\BrowserTestBase;
8
9 /**
10  * Translate settings and entities to various languages.
11  *
12  * @group config_translation
13  */
14 class ConfigTranslationOverviewTest extends BrowserTestBase {
15
16   /**
17    * Modules to enable.
18    *
19    * @var array
20    */
21   public static $modules = [
22     'block',
23     'config_test',
24     'config_translation',
25     'config_translation_test',
26     'contact',
27     'contextual',
28     'entity_test_operation',
29     'views',
30     'views_ui',
31   ];
32
33   /**
34    * Languages to enable.
35    *
36    * @var array
37    */
38   protected $langcodes = ['fr', 'ta'];
39
40   /**
41    * String translation storage object.
42    *
43    * @var \Drupal\locale\StringStorageInterface
44    */
45   protected $localeStorage;
46
47   protected function setUp() {
48     parent::setUp();
49     $permissions = [
50       'translate configuration',
51       'administer languages',
52       'administer site configuration',
53       'administer contact forms',
54       'access site-wide contact form',
55       'access contextual links',
56       'administer views',
57     ];
58     // Create and log in user.
59     $this->drupalLogin($this->drupalCreateUser($permissions));
60
61     // Add languages.
62     foreach ($this->langcodes as $langcode) {
63       ConfigurableLanguage::createFromLangcode($langcode)->save();
64     }
65     $this->localeStorage = $this->container->get('locale.storage');
66     $this->drupalPlaceBlock('local_tasks_block');
67     $this->drupalPlaceBlock('page_title_block');
68   }
69
70   /**
71    * Tests the config translation mapper page.
72    */
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'));
82     }
83
84     $labels = [
85       '&$nxd~i0',
86       'some "label" with quotes',
87       $this->randomString(),
88     ];
89
90     foreach ($labels as $label) {
91       $test_entity = entity_create('config_test', [
92         'id' => $this->randomMachineName(),
93         'label' => $label,
94       ]);
95       $test_entity->save();
96
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());
101
102       // Make sure there is only a single 'Translate' operation for each
103       // dropbutton.
104       foreach ($this->cssSelect('ul.dropbutton') as $i => $dropbutton) {
105         $this->assertIdentical(1, count($dropbutton->find('xpath', 'li')));
106         $this->assertIdentical('Translate', $dropbutton->getText());
107       }
108
109       $entity_type = \Drupal::entityManager()->getDefinition($test_entity->getEntityTypeId());
110       $this->drupalGet($base_url . '/translate');
111
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>');
116
117       $this->drupalGet($base_url);
118       $this->assertLink(t('Translate @title', ['@title' => $entity_type->getLowercaseLabel()]));
119     }
120   }
121
122   /**
123    * Tests availability of hidden entities in the translation overview.
124    */
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');
133
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');
141   }
142
143   /**
144    * Tests that overrides do not affect listing screens.
145    */
146   public function testListingPageWithOverrides() {
147     $original_label = 'Default';
148     $overridden_label = 'Overridden label';
149
150     $config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
151
152     // Set up an override.
153     $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
154       'value' => $overridden_label,
155       'required' => TRUE,
156     ];
157     $this->writeSettings($settings);
158
159     // Test that the overridden label is loaded with the entity.
160     $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
161
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);
166   }
167
168 }