41419b031e6bf2c73a04b625185c4b77588a369a
[yaffs-website] / web / core / modules / config / src / Tests / ConfigEntityFormOverrideTest.php
1 <?php
2
3 namespace Drupal\config\Tests;
4
5 use Drupal\simpletest\WebTestBase;
6
7 /**
8  * Tests that config overrides do not bleed through in entity forms and lists.
9  *
10  * @group config
11  */
12 class ConfigEntityFormOverrideTest extends WebTestBase {
13
14   /**
15    * {@inheritdoc}
16    */
17   public static $modules = ['config_test'];
18
19   /**
20    * Tests that overrides do not affect forms or listing screens.
21    */
22   public function testFormsWithOverrides() {
23     $this->drupalLogin($this->drupalCreateUser(['administer site configuration']));
24
25     $original_label = 'Default';
26     $overridden_label = 'Overridden label';
27     $edited_label = 'Edited label';
28
29     $config_test_storage = $this->container->get('entity.manager')->getStorage('config_test');
30
31     // Set up an override.
32     $settings['config']['config_test.dynamic.dotted.default']['label'] = (object) [
33       'value' => $overridden_label,
34       'required' => TRUE,
35     ];
36     $this->writeSettings($settings);
37
38     // Test that the overridden label is loaded with the entity.
39     $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
40
41     // Test that the original label on the listing page is intact.
42     $this->drupalGet('admin/structure/config_test');
43     $this->assertText($original_label);
44     $this->assertNoText($overridden_label);
45
46     // Test that the original label on the editing page is intact.
47     $this->drupalGet('admin/structure/config_test/manage/dotted.default');
48     $elements = $this->xpath('//input[@name="label"]');
49     $this->assertIdentical((string) $elements[0]['value'], $original_label);
50     $this->assertNoText($overridden_label);
51
52     // Change to a new label and test that the listing now has the edited label.
53     $edit = [
54       'label' => $edited_label,
55     ];
56     $this->drupalPostForm(NULL, $edit, t('Save'));
57     $this->drupalGet('admin/structure/config_test');
58     $this->assertNoText($overridden_label);
59     $this->assertText($edited_label);
60
61     // Test that the editing page now has the edited label.
62     $this->drupalGet('admin/structure/config_test/manage/dotted.default');
63     $elements = $this->xpath('//input[@name="label"]');
64     $this->assertIdentical((string) $elements[0]['value'], $edited_label);
65
66     // Test that the overridden label is still loaded with the entity.
67     $this->assertEqual($config_test_storage->load('dotted.default')->label(), $overridden_label);
68   }
69
70 }