ConfigTranslationFormTest.php in Drupal 9
File
core/modules/config_translation/tests/src/Kernel/ConfigTranslationFormTest.php
View source
<?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;
class ConfigTranslationFormTest extends KernelTestBase {
protected static $modules = [
'config_translation',
'config_translation_test',
'language',
'locale',
];
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);
$this
->assertTrue($add_form['#base_altered']);
$this
->assertTrue($edit_form['#base_altered']);
$this
->assertTrue($add_form['#altered']);
$this
->assertTrue($edit_form['#altered']);
}
}