ConfigAccessTest.php in Drupal 8
File
core/modules/settings_tray/tests/src/FunctionalJavascript/ConfigAccessTest.php
View source
<?php
namespace Drupal\Tests\settings_tray\FunctionalJavascript;
use Drupal\menu_link_content\Entity\MenuLinkContent;
use Drupal\user\Entity\Role;
class ConfigAccessTest extends SettingsTrayTestBase {
public static $modules = [
'menu_link_content',
'menu_ui',
];
protected $defaultTheme = 'stark';
protected function setUp() {
parent::setUp();
$user = $this
->createUser([
'administer blocks',
'access contextual links',
'access toolbar',
]);
$this
->drupalLogin($user);
}
public function testBlockConfigAccess() {
$page = $this
->getSession()
->getPage();
$web_assert = $this
->assertSession();
$block = $this
->placeBlock('system_branding_block');
$this
->drupalGet('user');
$this
->enableEditMode();
$this
->openBlockForm($this
->getBlockSelector($block));
$web_assert
->fieldNotExists('settings[site_information][site_name]');
$page
->pressButton('Save Site branding');
$this
->waitForOffCanvasToClose();
$this
->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)');
$web_assert
->assertWaitOnAjaxRequest();
$this
->assertEquals('Drupal', \Drupal::configFactory()
->getEditable('system.site')
->get('name'));
$this
->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [
'administer site configuration',
]);
$this
->drupalGet('user');
$this
->openBlockForm($this
->getBlockSelector($block));
$web_assert
->fieldExists('settings[site_information][site_name]');
$menu_link_content = MenuLinkContent::create([
'title' => 'This is on the menu',
'menu_name' => 'main',
'link' => [
'uri' => 'route:<front>',
],
]);
$menu_link_content
->save();
$this
->assertNotEmpty($menu_link_content
->isEnabled());
$menu_without_overrides = \Drupal::configFactory()
->getEditable('system.menu.main')
->get();
$block = $this
->placeBlock('system_menu_block:main');
$this
->drupalGet('user');
$web_assert
->pageTextContains('This is on the menu');
$this
->openBlockForm($this
->getBlockSelector($block));
$web_assert
->pageTextNotContains('Edit menu');
$page
->pressButton('Save Main navigation');
$this
->assertElementVisibleAfterWait('css', 'div:contains(The block configuration has been saved)');
$web_assert
->assertWaitOnAjaxRequest();
$this
->assertEquals($menu_without_overrides, \Drupal::configFactory()
->getEditable('system.menu.main')
->get());
$menu_link_content = MenuLinkContent::load($menu_link_content
->id());
$this
->assertNotEmpty($menu_link_content
->isEnabled());
$this
->drupalGet('user');
$web_assert
->pageTextContains('This is on the menu');
$this
->grantPermissions(Role::load(Role::AUTHENTICATED_ID), [
'administer menu',
]);
$this
->drupalGet('user');
$web_assert
->pageTextContains('This is on the menu');
$this
->openBlockForm($this
->getBlockSelector($block));
$web_assert
->pageTextContains('Edit menu');
}
}