function EntityQueryAccessTest::testBlockContentEntityQueryAccess

Same name in other branches
  1. 9 core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testBlockContentEntityQueryAccess()
  2. 8.9.x core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testBlockContentEntityQueryAccess()
  3. 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 80

Class

EntityQueryAccessTest
Tests that Views respects 'ENTITY_TYPE_access' query tags.

Namespace

Drupal\Tests\views\Functional\Entity

Code

public function testBlockContentEntityQueryAccess() : void {
    $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([
        'access block library',
    ]);
    $this->drupalLogin($account);
    $this->drupalGet('/admin/content/block');
    $assert_session = $this->assertSession();
    $assert_session->statusCodeEquals(200);
    $assert_session->pageTextContains($accessible_block->label());
    $assert_session->pageTextNotContains($hidden_block->label());
}

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