3 namespace Drupal\metatag\Tests;
5 use Drupal\simpletest\WebTestBase;
8 * Ensures that the Metatag config translations work correctly.
12 class MetatagConfigTranslationTest extends WebTestBase {
17 protected $profile = 'testing';
22 * @var \Drupal\Core\Session\AccountInterface
31 public static $modules = [
38 * Permissions to grant admin user.
42 protected $permissions = [
44 'administer meta tags',
46 // From system module, in order to access the /admin pages.
47 'access administration pages',
49 // From language module.
50 'administer languages',
52 // From config_translations module.
53 'translate configuration',
59 protected function setUp() {
61 $this->adminUser = $this->drupalCreateUser($this->permissions);
62 $this->drupalLogin($this->adminUser);
64 // Enable the French language.
65 $this->drupalGet('admin/config/regional/language/add');
66 $this->assertResponse(200);
68 'predefined_langcode' => 'fr',
70 $this->drupalPostForm(NULL, $edit, t('Add language'));
72 'The language %language has been created and can now be used.',
73 ['%language' => t('French')]
78 * Confirm the config defaults show on the translations page.
80 public function testConfigTranslationsExist() {
81 // Ensure the config shows on the admin form.
82 $this->drupalGet('admin/config/regional/config-translation');
83 $this->assertResponse(200);
84 $this->assertText(t('Metatag defaults'));
86 // Load the main metatag_defaults config translation page.
87 $this->drupalGet('admin/config/regional/config-translation/metatag_defaults');
88 $this->assertResponse(200);
89 // @todo Update this to confirm the H1 is loaded.
90 $this->assertRaw(t('Metatag defaults'));
92 // Load all of the Metatag defaults.
93 $defaults = \Drupal::configFactory()->listAll('metatag.metatag_defaults');
95 /** @var \Drupal\Core\Config\ConfigManagerInterface $config_manager */
96 $config_manager = \Drupal::service('config.manager');
98 // Confirm each of the configs is available on the translation form.
99 foreach ($defaults as $config_name) {
100 if ($config_entity = $config_manager->loadConfigEntityByName($config_name)) {
101 $this->assertText($config_entity->label());
105 // Confirm that each config translation page can be loaded.
106 foreach ($defaults as $config_name) {
107 if ($config_entity = $config_manager->loadConfigEntityByName($config_name)) {
108 $this->drupalGet('admin/config/search/metatag/' . $config_entity->id() . '/translate');
109 $this->assertResponse(200);
112 $this->error('Unable to load a Metatag default config: ' . $config_name);
118 * Confirm the global configs are translatable page.
120 public function testConfigTranslations() {
121 // Add something to the Global config.
122 $this->drupalGet('admin/config/search/metatag/global');
123 $this->assertResponse(200);
125 'title' => 'Test title',
126 'description' => 'Test description',
128 $this->drupalPostForm(NULL, $values, t('Save'));
129 $this->assertResponse(200);
130 $this->assertText(t('Saved the Global Metatag defaults.'));
132 // Confirm the config has languages available to translate into.
133 $this->drupalGet('admin/config/search/metatag/global/translate');
134 $this->assertResponse(200);
136 // Load the translation form.
137 $this->drupalGet('admin/config/search/metatag/global/translate/fr/add');
138 $this->assertResponse(200);
140 // Confirm the meta tag fields are shown on the form. Confirm the fields and
141 // values separately to make it easier to pinpoint where the problem is if
143 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][title]');
144 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][title]', $values['title']);
145 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][description]');
146 $this->assertFieldByName('translation[config_names][metatag.metatag_defaults.global][tags][description]', $values['description']);
148 // Confirm the form can be saved correctly.
150 'translation[config_names][metatag.metatag_defaults.global][tags][title]' => 'Le title',
151 'translation[config_names][metatag.metatag_defaults.global][tags][description]' => 'Le description',
153 $this->drupalPostForm(NULL, $values, t('Save translation'));
154 $this->assertResponse(200);
155 $this->assertText(t('Successfully saved French translation'));