function EntityQueryAccessTest::testMediaEntityQueryAccess

Same name in other branches
  1. 8.9.x core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testMediaEntityQueryAccess()
  2. 10 core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testMediaEntityQueryAccess()
  3. 11.x core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest::testMediaEntityQueryAccess()

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

File

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

Class

EntityQueryAccessTest
Tests that Views respects 'ENTITY_TYPE_access' query tags.

Namespace

Drupal\Tests\views\Functional\Entity

Code

public function testMediaEntityQueryAccess() {
    $this->container
        ->get('module_installer')
        ->install([
        'media',
    ]);
    $media_type = $this->createMediaType('test');
    $source_field = $media_type->getSource()
        ->getSourceFieldDefinition($media_type)
        ->getName();
    $hidden_media = Media::create([
        'bundle' => $media_type->id(),
        // This UUID should prevent this media item from being visible in the
        // view.
        // @see views_test_access_query_media_access_alter()
'uuid' => 'hidden-media',
        'name' => $this->randomString(),
        $source_field => $this->randomString(),
    ]);
    $hidden_media->save();
    $accessible_media = Media::create([
        'bundle' => $media_type->id(),
        'name' => $this->randomString(),
        $source_field => $this->randomString(),
    ]);
    $accessible_media->save();
    $account = $this->drupalCreateUser([
        'access media overview',
        'administer media',
    ]);
    $this->drupalLogin($account);
    $this->drupalGet('/admin/content/media');
    $assert_session = $this->assertSession();
    $assert_session->statusCodeEquals(200);
    $assert_session->linkExists($accessible_media->label());
    $assert_session->linkNotExists($hidden_media->label());
}

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