3 namespace Drupal\metatag\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Ensures that the Metatag config translations work correctly.
12 class MetatagConfigTranslationTest extends WebTestBase {
19 protected $profile = 'testing';
24 * @var \Drupal\Core\Session\AccountInterface
33 public static $modules = [
40 * Permissions to grant admin user.
44 protected $permissions = [
46 'administer meta tags',
48 // From system module, in order to access the /admin pages.
49 'access administration pages',
51 // From language module.
52 'administer languages',
54 // From config_translations module.
55 'translate configuration',
61 protected function setUp() {
63 $this->adminUser = $this->drupalCreateUser($this->permissions);
64 $this->drupalLogin($this->adminUser);
66 // Enable the French language.
67 $this->drupalGet('admin/config/regional/language/add');
68 $this->assertResponse(200);
70 'predefined_langcode' => 'fr',
72 $this->drupalPostForm(NULL, $edit, t('Add language'));
74 'The language %language has been created and can now be used.',
75 ['%language' => t('French')]
80 * Confirm the config defaults show on the translations page.
82 public function testConfigTranslationsExist() {
83 // Ensure the config shows on the admin form.
84 $this->drupalGet('admin/config/regional/config-translation');
85 $this->assertResponse(200);
86 $this->assertText(t('Metatag defaults'));
88 // Load the main metatag_defaults config translation page.
89 $this->drupalGet('admin/config/regional/config-translation/metatag_defaults');
90 $this->assertResponse(200);
91 // @todo Update this to confirm the H1 is loaded.
92 $this->assertRaw(t('Metatag defaults'));
94 // Load all of the Metatag defaults.
95 $defaults = \Drupal::configFactory()->listAll('metatag.metatag_defaults');
97 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
98 $config_manager = \Drupal::service('config.manager');
100 // Confirm each of the configs is available on the translation form.
101 foreach ($defaults as $config_name) {
102 if ($config_entity = $config_manager->loadConfigEntityByName($config_name)) {
103 $this->assertText($config_entity->label());
107 // Confirm that each config translation page can be loaded.
108 foreach ($defaults as $config_name) {
109 if ($config_entity = $config_manager->loadConfigEntityByName($config_name)) {
110 $this->drupalGet('admin/config/search/metatag/' . $config_entity->id() . '/translate');
111 $this->assertResponse(200);
114 $this->error('Unable to load a Metatag default config: ' . $config_name);
120 * Confirm the global configs are translatable page.
122 public function testConfigTranslations() {
123 // Add something to the Global config.
124 $this->drupalGet('admin/config/search/metatag/global');
125 $this->assertResponse(200);
127 'title' => 'Test title',
128 'description' => 'Test description',
130 $this->drupalPostForm(NULL, $edit, t('Save'));
131 $this->assertResponse(200);
132 $this->assertText(t('Saved the Global Metatag defaults.'));
134 // Confirm the config has languages available to translate into.
135 $this->drupalGet('admin/config/search/metatag/global/translate');
136 $this->assertResponse(200);
138 // Load the translation form.
139 $this->drupalGet('admin/config/search/metatag/global/translate/fr/add');
140 $this->assertResponse(200);
142 // Confirm the meta tag fields are shown on the form. Confirm the fields and
143 // values separately to make it easier to pinpoint where the problem is if
145 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][title]');
146 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][title]', $edit['title']);
147 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][description]');
148 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][description]', $edit['description']);
150 // Confirm the form can be saved correctly.
152 'translation[config_names][metatag.metatag_defaults.global][tags][title]' => 'Le title',
153 'translation[config_names][metatag.metatag_defaults.global][tags][description]' => 'Le description',
155 $this->drupalPostForm(NULL, $edit, t('Save translation'));
156 $this->assertResponse(200);
157 $this->assertText(t('Successfully saved French translation'));