Same name and namespace in other branches
- 8.9.x core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest
- 9 core/modules/views/tests/src/Functional/Entity/EntityQueryAccessTest.php \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest
Tests that Views respects 'ENTITY_TYPE_access' query tags.
@group views
Hierarchy
- class \Drupal\Tests\views\Functional\ViewTestBase extends \Drupal\Tests\BrowserTestBase uses ViewResultAssertionTrait
- class \Drupal\Tests\views\Functional\Entity\EntityQueryAccessTest uses MediaTypeCreationTrait
Expanded class hierarchy of EntityQueryAccessTest
File
- core/
modules/ views/ tests/ src/ Functional/ Entity/ EntityQueryAccessTest.php, line 18
Namespace
Drupal\Tests\views\Functional\EntityView source
class EntityQueryAccessTest extends ViewTestBase {
use MediaTypeCreationTrait;
/**
* {@inheritdoc}
*/
protected static $modules = [
'media_test_source',
'views_test_query_access',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests that the 'media_access' query tag is respected by Views.
*/
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());
}
/**
* Tests that the 'block_content_access' query tag is respected by Views.
*/
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([
'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());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
EntityQueryAccessTest:: |
protected | property | ||
EntityQueryAccessTest:: |
protected static | property |
Modules to enable. Overrides ViewTestBase:: |
|
EntityQueryAccessTest:: |
public | function | Tests that the 'block_content_access' query tag is respected by Views. | |
EntityQueryAccessTest:: |
public | function | Tests that the 'media_access' query tag is respected by Views. | |
MediaTypeCreationTrait:: |
protected | function | Create a media type for a source plugin. | |
ViewResultAssertionTrait:: |
protected | function | Verifies that a result set returned by a View matches expected values. | |
ViewResultAssertionTrait:: |
protected | function | Performs View result assertions. | |
ViewResultAssertionTrait:: |
protected | function | Verifies that a result set returned by a View differs from certain values. | |
ViewTestBase:: |
protected | function | Returns a very simple test dataset. | 1 |
ViewTestBase:: |
protected | function | Sets up the views_test_data.module. | |
ViewTestBase:: |
protected | function | Executes a view. | |
ViewTestBase:: |
protected | function | Asserts the existence of a button with a certain ID and label. | |
ViewTestBase:: |
protected | function | Orders a nested array containing a result set based on a given column. | |
ViewTestBase:: |
protected | function | Returns the schema definition. | 1 |
ViewTestBase:: |
protected | function | Sets up the test. | 74 |
ViewTestBase:: |
protected | function | Returns the views data definition. | 8 |