You are here

public function BlockFormRoutesAccessTest::testBlockAddFormAccess in Block permissions 8

Tests access to "/admin/structure/block/add/{plugin_id}/{theme}" page.

@covers ::blockAddFormAccess

File

tests/src/Functional/BlockFormRoutesAccessTest.php, line 72

Class

BlockFormRoutesAccessTest
Tests Block permissions access control handler for block configuration pages.

Namespace

Drupal\Tests\block_permissions\Functional

Code

public function testBlockAddFormAccess() {

  // Ensure that the user with permissions to administer blocks in the default
  // theme can create core's blocks only.
  $this
    ->drupalLogin($this->coreBlocksUser);
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('page_title_block', $this->defaultTheme));
  $this
    ->assertBlockFormPageHasAccess();
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('system_branding_block', $this->defaultTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Ensure that the user with permissions to administer blocks in the default
  // theme can create system's blocks only.
  $this
    ->drupalLogin($this->systemBlocksUser);
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('page_title_block', $this->defaultTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('system_branding_block', $this->defaultTheme));
  $this
    ->assertBlockFormPageHasAccess();

  // Ensure that the user can add blocks only to a theme where it can
  // administer blocks.
  $this
    ->drupalLogin($this->secondThemeUser);
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('page_title_block', $this->secondTheme));
  $this
    ->assertBlockFormPageHasAccess();
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('system_branding_block', $this->secondTheme));
  $this
    ->assertBlockFormPageHasAccess();
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('page_title_block', $this->defaultTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet($this
    ->getBlockAdminAddUrl('system_branding_block', $this->defaultTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
}