You are here

public function ConfigFormOverrideTest::testFormsWithOverrides in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/config/tests/src/Functional/ConfigFormOverrideTest.php \Drupal\Tests\config\Functional\ConfigFormOverrideTest::testFormsWithOverrides()
  2. 9 core/modules/config/tests/src/Functional/ConfigFormOverrideTest.php \Drupal\Tests\config\Functional\ConfigFormOverrideTest::testFormsWithOverrides()

Tests that overrides do not affect forms.

File

core/modules/config/tests/src/Functional/ConfigFormOverrideTest.php, line 23

Class

ConfigFormOverrideTest
Tests config overrides do not appear on forms that extend ConfigFormBase.

Namespace

Drupal\Tests\config\Functional

Code

public function testFormsWithOverrides() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'access administration pages',
    'administer site configuration',
  ]));
  $overridden_name = 'Site name global conf override';

  // Set up an override.
  $settings['config']['system.site']['name'] = (object) [
    'value' => $overridden_name,
    'required' => TRUE,
  ];
  $this
    ->writeSettings($settings);

  // Test that everything on the form is the same, but that the override
  // worked for the actual site name.
  $this
    ->drupalGet('admin/config/system/site-information');
  $this
    ->assertSession()
    ->titleEquals('Basic site settings | ' . $overridden_name);
  $this
    ->assertSession()
    ->fieldValueEquals("site_name", 'Drupal');

  // Submit the form and ensure the site name is not changed.
  $edit = [
    'site_name' => 'Custom site name',
  ];
  $this
    ->drupalGet('admin/config/system/site-information');
  $this
    ->submitForm($edit, 'Save configuration');
  $this
    ->assertSession()
    ->titleEquals('Basic site settings | ' . $overridden_name);
  $this
    ->assertSession()
    ->fieldValueEquals("site_name", $edit['site_name']);
}