You are here

public function ConfigEntityFormOverrideTest::testFormsWithOverrides in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php \Drupal\config\Tests\ConfigEntityFormOverrideTest::testFormsWithOverrides()

Tests that overrides do not affect forms or listing screens.

File

core/modules/config/src/Tests/ConfigEntityFormOverrideTest.php, line 27
Contains \Drupal\config\Tests\ConfigEntityFormOverrideTest.

Class

ConfigEntityFormOverrideTest
Tests that config overrides do not bleed through in entity forms and lists.

Namespace

Drupal\config\Tests

Code

public function testFormsWithOverrides() {
  $this
    ->drupalLogin($this
    ->drupalCreateUser([
    'administer site configuration',
  ]));
  $original_label = 'Default';
  $overridden_label = 'Overridden label';
  $edited_label = 'Edited label';
  $config_test_storage = $this->container
    ->get('entity.manager')
    ->getStorage('config_test');

  // Set up an override.
  $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) array(
    'value' => $overridden_label,
    'required' => TRUE,
  );
  $this
    ->writeSettings($settings);

  // Test that the overridden label is loaded with the entity.
  $this
    ->assertEqual($config_test_storage
    ->load('dotted.default')
    ->label(), $overridden_label);

  // Test that the original label on the listing page is intact.
  $this
    ->drupalGet('admin/structure/config_test');
  $this
    ->assertText($original_label);
  $this
    ->assertNoText($overridden_label);

  // Test that the original label on the editing page is intact.
  $this
    ->drupalGet('admin/structure/config_test/manage/dotted.default');
  $elements = $this
    ->xpath('//input[@name="label"]');
  $this
    ->assertIdentical((string) $elements[0]['value'], $original_label);
  $this
    ->assertNoText($overridden_label);

  // Change to a new label and test that the listing now has the edited label.
  $edit = array(
    'label' => $edited_label,
  );
  $this
    ->drupalPostForm(NULL, $edit, t('Save'));
  $this
    ->drupalGet('admin/structure/config_test');
  $this
    ->assertNoText($overridden_label);
  $this
    ->assertText($edited_label);

  // Test that the editing page now has the edited label.
  $this
    ->drupalGet('admin/structure/config_test/manage/dotted.default');
  $elements = $this
    ->xpath('//input[@name="label"]');
  $this
    ->assertIdentical((string) $elements[0]['value'], $edited_label);

  // Test that the overridden label is still loaded with the entity.
  $this
    ->assertEqual($config_test_storage
    ->load('dotted.default')
    ->label(), $overridden_label);
}