ConfigTranslationFormTest.php 1.86 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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']);
  }

}