You are here

public function EntityQueryAccessTest::testBlockContentEntityQueryAccess in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testBlockContentEntityQueryAccess()
  2. 10 core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testBlockContentEntityQueryAccess()

Tests that the 'block_content_access' query tag is respected by Views.

File

core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php, line 78

Class

EntityQueryAccessTest
Tests that Views respects 'ENTITY_TYPE_access' query tags.

Namespace

Drupal\Tests\views\Functional\Entity

Code

public function testBlockContentEntityQueryAccess() {
  $this->container
    ->get('module_installer')
    ->install([
    'block_content',
  ]);
  BlockContentType::create([
    'id' => 'test',
    'label' => 'Test',
  ])
    ->save();
  $hidden_block = BlockContent::create([
    'type' => 'test',
    // This UUID should prevent this block from being visible in the view.
    // @see views_test_access_query_block_content_access_alter()
    'uuid' => 'hidden-block_content',
    'info' => $this
      ->randomString(),
  ]);
  $hidden_block
    ->save();
  $accessible_block = BlockContent::create([
    'type' => 'test',
    'info' => $this
      ->randomString(),
  ]);
  $accessible_block
    ->save();
  $account = $this
    ->drupalCreateUser([
    'administer blocks',
  ]);
  $this
    ->drupalLogin($account);
  $this
    ->drupalGet('/admin/structure/block/block-content');
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->statusCodeEquals(200);
  $assert_session
    ->pageTextContains($accessible_block
    ->label());
  $assert_session
    ->pageTextNotContains($hidden_block
    ->label());
}