You are here

public function BlockPermissionsBlockLibraryControllerTest::testListBlocks in Block permissions 8

Tests blocks visibility on the "/admin/structure/block/library/{theme}".

@covers ::listBlocks

File

tests/src/Functional/BlockPermissionsBlockLibraryControllerTest.php, line 53

Class

BlockPermissionsBlockLibraryControllerTest
Tests Block permissions block library controller.

Namespace

Drupal\Tests\block_permissions\Functional

Code

public function testListBlocks() {
  $page_title_block_definition = \Drupal::service('plugin.manager.block')
    ->getDefinition('page_title_block');
  $system_branding_block_definition = \Drupal::service('plugin.manager.block')
    ->getDefinition('system_branding_block');

  // Ensure that the user has the access to the library page of the theme
  // which blocks it is able to manage and block is visible.
  $this
    ->drupalLogin($this->coreBlocksUser);
  $this
    ->drupalGet($this
    ->getBlockAdminLibraryThemeUrl($this->defaultTheme));
  $this
    ->assertBlockLibraryPageHasAccess();
  $this
    ->assertSession()
    ->pageTextContains($page_title_block_definition['admin_label']);
  $this
    ->assertSession()
    ->pageTextNotContains($system_branding_block_definition['admin_label']);
  $this
    ->drupalGet($this
    ->getBlockAdminLibraryThemeUrl($this->secondTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);

  // Ensure the same for the another user.
  $this
    ->drupalLogin($this->systemBlocksUser);
  $this
    ->drupalGet($this
    ->getBlockAdminLibraryThemeUrl($this->defaultTheme));
  $this
    ->assertSession()
    ->statusCodeEquals(403);
  $this
    ->drupalGet($this
    ->getBlockAdminLibraryThemeUrl($this->secondTheme));
  $this
    ->assertBlockLibraryPageHasAccess();
  $this
    ->assertSession()
    ->pageTextNotContains($page_title_block_definition['admin_label']);
  $this
    ->assertSession()
    ->pageTextContains($system_branding_block_definition['admin_label']);
}