diff --git a/core/modules/config_translation/tests/src/Functional/ConfigTranslationFormTest.php b/core/modules/config_translation/tests/src/Functional/ConfigTranslationFormTest.php deleted file mode 100644 index 4698b05a8ec313aa8dc02f8e9ab5d8a2103a9976..0000000000000000000000000000000000000000 --- a/core/modules/config_translation/tests/src/Functional/ConfigTranslationFormTest.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -namespace Drupal\Tests\config_translation\Functional; - -use Drupal\language\Entity\ConfigurableLanguage; -use Drupal\Tests\BrowserTestBase; - -/** - * Tests for altering configuration translation forms. - * - * @group config_translation - */ -class ConfigTranslationFormTest extends BrowserTestBase { - - /** - * Modules to enable. - * - * @var array - */ - public static $modules = ['config_translation', 'config_translation_test', 'editor']; - - /** - * The plugin ID of the mapper to test. - * - * @var string - */ - protected $pluginId; - - /** - * The language code of the language to use for testing. - * - * @var string - */ - protected $langcode; - - protected function setUp() { - parent::setUp(); - - $definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions(); - $this->pluginId = key($definitions); - - $this->langcode = 'xx'; - ConfigurableLanguage::create(['id' => $this->langcode, 'label' => 'XX'])->save(); - - \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE); - } - - /** - * Tests altering of the configuration translation forms. - */ - public function testConfigTranslationFormAlter() { - $form_builder = \Drupal::formBuilder(); - $add_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationAddForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode); - $edit_form = $form_builder->getForm('Drupal\config_translation\Form\ConfigTranslationEditForm', \Drupal::routeMatch(), $this->pluginId, $this->langcode); - - // Test that hook_form_BASE_FORM_ID_alter() was called for the base form ID - // 'config_translation_form'. - $this->assertTrue($add_form['#base_altered']); - $this->assertTrue($edit_form['#base_altered']); - - // Test that hook_form_FORM_ID_alter() was called for the form IDs - // 'config_translation_add_form' and 'config_translation_edit_form'. - $this->assertTrue($add_form['#altered']); - $this->assertTrue($edit_form['#altered']); - } - -} diff --git a/core/modules/config_translation/tests/src/Kernel/ConfigTranslationFormTest.php b/core/modules/config_translation/tests/src/Kernel/ConfigTranslationFormTest.php new file mode 100644 index 0000000000000000000000000000000000000000..32e1731e0b7f8576b8ffcf6746ce9b2e418404e4 --- /dev/null +++ b/core/modules/config_translation/tests/src/Kernel/ConfigTranslationFormTest.php @@ -0,0 +1,58 @@ +<?php + +namespace Drupal\Tests\config_translation\Kernel; + +use Drupal\config_translation\Form\ConfigTranslationAddForm; +use Drupal\config_translation\Form\ConfigTranslationEditForm; +use Drupal\KernelTests\KernelTestBase; +use Drupal\language\Entity\ConfigurableLanguage; + +/** + * Tests for altering configuration translation forms. + * + * @group config_translation + */ +class ConfigTranslationFormTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + protected static $modules = [ + 'config_translation', + 'config_translation_test', + 'language', + 'locale', + ]; + + /** + * Tests altering of the configuration translation forms. + */ + public function testConfigTranslationFormAlter() { + $this->installConfig(['config_translation_test']); + + $definitions = $this->container->get('plugin.manager.config_translation.mapper')->getDefinitions(); + $plugin_id = key($definitions); + $langcode = 'xx'; + + ConfigurableLanguage::create(['id' => $langcode, 'label' => 'XX'])->save(); + + $this->container->get('state')->set('config_translation_test_alter_form_alter', TRUE); + + $form_builder = $this->container->get('form_builder'); + $route_match = $this->container->get('current_route_match'); + + $add_form = $form_builder->getForm(ConfigTranslationAddForm::class, $route_match, $plugin_id, $langcode); + $edit_form = $form_builder->getForm(ConfigTranslationEditForm::class, $route_match, $plugin_id, $langcode); + + // Test that hook_form_BASE_FORM_ID_alter() was called for the base form ID + // 'config_translation_form'. + $this->assertTrue($add_form['#base_altered']); + $this->assertTrue($edit_form['#base_altered']); + + // Test that hook_form_FORM_ID_alter() was called for the form IDs + // 'config_translation_add_form' and 'config_translation_edit_form'. + $this->assertTrue($add_form['#altered']); + $this->assertTrue($edit_form['#altered']); + } + +}