function OverriddenConfigurationTest::testOverriddenConfigurationRemoved

Same name in other branches
  1. 9 core/modules/settings_tray/tests/src/FunctionalJavascript/OverriddenConfigurationTest.php \Drupal\Tests\settings_tray\FunctionalJavascript\OverriddenConfigurationTest::testOverriddenConfigurationRemoved()
  2. 8.9.x core/modules/settings_tray/tests/src/FunctionalJavascript/OverriddenConfigurationTest.php \Drupal\Tests\settings_tray\FunctionalJavascript\OverriddenConfigurationTest::testOverriddenConfigurationRemoved()
  3. 10 core/modules/settings_tray/tests/src/FunctionalJavascript/OverriddenConfigurationTest.php \Drupal\Tests\settings_tray\FunctionalJavascript\OverriddenConfigurationTest::testOverriddenConfigurationRemoved()

Tests blocks with overridden related configuration removed when overridden.

File

core/modules/settings_tray/tests/src/FunctionalJavascript/OverriddenConfigurationTest.php, line 49

Class

OverriddenConfigurationTest
Tests handling of configuration overrides.

Namespace

Drupal\Tests\settings_tray\FunctionalJavascript

Code

public function testOverriddenConfigurationRemoved() : void {
    $web_assert = $this->assertSession();
    $page = $this->getSession()
        ->getPage();
    $this->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [
        'administer site configuration',
        'administer menu',
    ]);
    // Confirm the branding block does include 'site_information' section when
    // the site name is not overridden.
    $branding_block = $this->placeBlock('system_branding_block');
    $this->drupalGet('user');
    $this->enableEditMode();
    $this->openBlockForm($this->getBlockSelector($branding_block));
    $web_assert->fieldExists('settings[site_information][site_name]');
    // Confirm the branding block does not include 'site_information' section
    // when the site name is overridden.
    $this->container
        ->get('state')
        ->set('settings_tray_override_test.site_name', TRUE);
    $this->drupalGet('user');
    $this->openBlockForm($this->getBlockSelector($branding_block));
    $web_assert->fieldNotExists('settings[site_information][site_name]');
    $page_load_hash_1 = $this->getSession()
        ->evaluateScript('window.performance.timeOrigin');
    $page->pressButton('Save Site branding');
    // Pressing the button triggered no validation errors and an AJAX redirect
    // that reloaded the page.
    $this->waitForOffCanvasToClose();
    $page_load_hash_2 = $this->getSession()
        ->evaluateScript('window.performance.timeOrigin');
    $this->assertNotSame($page_load_hash_1, $page_load_hash_2);
    $web_assert->elementExists('css', 'div:contains(The block configuration has been saved)');
    // Confirm we did not save changes to the configuration.
    $this->assertEquals('Llama Fan Club', \Drupal::configFactory()->get('system.site')
        ->get('name'));
    $this->assertEquals('Drupal', \Drupal::configFactory()->getEditable('system.site')
        ->get('name'));
    // Add a link or the menu will not render.
    $menu_link_content = MenuLinkContent::create([
        'title' => 'This is on the menu',
        'menu_name' => 'main',
        'link' => [
            'uri' => 'route:<front>',
        ],
    ]);
    $menu_link_content->save();
    // Confirm the menu block does include menu section when the menu is not
    // overridden.
    $menu_block = $this->placeBlock('system_menu_block:main');
    $this->drupalGet('user');
    $web_assert->pageTextContains('This is on the menu');
    $this->openBlockForm($this->getBlockSelector($menu_block));
    $web_assert->elementExists('css', '#menu-overview');
    // Confirm the menu block does not include menu section when the menu is
    // overridden.
    $this->container
        ->get('state')
        ->set('settings_tray_override_test.menu', TRUE);
    $this->drupalGet('user');
    $web_assert->pageTextContains('This is on the menu');
    $menu_with_overrides = \Drupal::configFactory()->get('system.menu.main')
        ->get();
    $menu_without_overrides = \Drupal::configFactory()->getEditable('system.menu.main')
        ->get();
    $this->openBlockForm($this->getBlockSelector($menu_block));
    $web_assert->elementNotExists('css', '#menu-overview');
    $page_load_hash_3 = $this->getSession()
        ->evaluateScript('window.performance.timeOrigin');
    $page->pressButton('Save Main navigation');
    // Pressing the button triggered no validation errors and an AJAX redirect
    // that reloaded the page.
    $this->waitForOffCanvasToClose();
    $page_load_hash_4 = $this->getSession()
        ->evaluateScript('window.performance.timeOrigin');
    $this->assertNotSame($page_load_hash_3, $page_load_hash_4);
    $web_assert->elementExists('css', 'div:contains(The block configuration has been saved)');
    // Confirm we did not save changes to the configuration.
    $this->assertEquals('Foo label', \Drupal::configFactory()->get('system.menu.main')
        ->get('label'));
    $this->assertEquals('Main navigation', \Drupal::configFactory()->getEditable('system.menu.main')
        ->get('label'));
    $this->assertEquals($menu_with_overrides, \Drupal::configFactory()->get('system.menu.main')
        ->get());
    $this->assertEquals($menu_without_overrides, \Drupal::configFactory()->getEditable('system.menu.main')
        ->get());
    $web_assert->pageTextContains('This is on the menu');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.