3 namespace Drupal\Tests\config_translation\Functional;
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
9 * Tests for altering configuration translation forms.
11 * @group config_translation
13 class ConfigTranslationFormTest extends BrowserTestBase {
20 public static $modules = ['config_translation', 'config_translation_test', 'editor'];
23 * The plugin ID of the mapper to test.
30 * The language code of the language to use for testing.
36 protected function setUp() {
39 $definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions();
40 $this->pluginId = key($definitions);
42 $this->langcode = 'xx';
43 ConfigurableLanguage::create(['id' => $this->langcode, 'label' => 'XX'])->save();
45 \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
49 * Tests altering of the configuration translation forms.
51 public function testConfigTranslationFormAlter() {
52 $form_builder = \Drupal::formBuilder();
53 $add_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationAddForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
54 $edit_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationEditForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode);
56 // Test that hook_form_BASE_FORM_ID_alter() was called for the base form ID
57 // 'config_translation_form'.
58 $this->assertTrue($add_form['#base_altered']);
59 $this->assertTrue($edit_form['#base_altered']);
61 // Test that hook_form_FORM_ID_alter() was called for the form IDs
62 // 'config_translation_add_form' and 'config_translation_edit_form'.
63 $this->assertTrue($add_form['#altered']);
64 $this->assertTrue($edit_form['#altered']);