Backup of db before drupal security update
[yaffs-website] / web / core / modules / config_translation / tests / src / Functional / ConfigTranslationFormTest.php
1 <?php
2
3 namespace Drupal\Tests\config_translation\Functional;
4
5 use Drupal\language\Entity\ConfigurableLanguage;
6 use Drupal\Tests\BrowserTestBase;
7
8 /**
9  * Tests for altering configuration translation forms.
10  *
11  * @group config_translation
12  */
13 class ConfigTranslationFormTest extends BrowserTestBase {
14
15   /**
16    * Modules to enable.
17    *
18    * @var array
19    */
20   public static $modules = ['config_translation', 'config_translation_test', 'editor'];
21
22   /**
23    * The plugin ID of the mapper to test.
24    *
25    * @var string
26    */
27   protected $pluginId;
28
29   /**
30    * The language code of the language to use for testing.
31    *
32    * @var string
33    */
34   protected $langcode;
35
36   protected function setUp() {
37     parent::setUp();
38
39     $definitions = \Drupal::service('plugin.manager.config_translation.mapper')->getDefinitions();
40     $this->pluginId = key($definitions);
41
42     $this->langcode = 'xx';
43     ConfigurableLanguage::create(['id' => $this->langcode, 'label' => 'XX'])->save();
44
45     \Drupal::state()->set('config_translation_test_alter_form_alter', TRUE);
46   }
47
48   /**
49    * Tests altering of the configuration translation forms.
50    */
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);
55
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']);
60
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']);
65   }
66
67 }