public function QueryAccessTest::testEntityQueryWithRevisions in Entity API 8
Tests EntityQuery filtering when all revisions are queried.
File
- tests/
src/ Kernel/ QueryAccess/ QueryAccessTest.php, line 144
Class
- QueryAccessTest
- Test query access filtering for EntityQuery and Views.
Namespace
Drupal\Tests\entity\Kernel\QueryAccessCode
public function testEntityQueryWithRevisions() {
// Admin permission, full access.
$admin_user = $this
->createUser([], [
'administer entity_test_enhanced',
]);
$this->container
->get('current_user')
->setAccount($admin_user);
$result = $this->storage
->getQuery()
->allRevisions()
->sort('id')
->execute();
$this
->assertEquals([
'1' => $this->entities[0]
->id(),
'2' => $this->entities[0]
->id(),
'3' => $this->entities[1]
->id(),
'4' => $this->entities[1]
->id(),
'5' => $this->entities[2]
->id(),
'6' => $this->entities[2]
->id(),
], $result);
// No view permissions, no access.
$user = $this
->createUser([], [
'access content',
]);
$this->container
->get('current_user')
->setAccount($user);
$result = $this->storage
->getQuery()
->execute();
$this
->assertEmpty($result);
// View (published-only).
$user = $this
->createUser([], [
'view entity_test_enhanced',
]);
$this->container
->get('current_user')
->setAccount($user);
$result = $this->storage
->getQuery()
->allRevisions()
->sort('id')
->execute();
$this
->assertEquals([
'1' => $this->entities[0]
->id(),
'4' => $this->entities[1]
->id(),
'5' => $this->entities[2]
->id(),
'6' => $this->entities[2]
->id(),
], $result);
// View $bundle (published-only).
$user = $this
->createUser([], [
'view first entity_test_enhanced',
]);
$this->container
->get('current_user')
->setAccount($user);
$result = $this->storage
->getQuery()
->allRevisions()
->sort('id')
->execute();
$this
->assertEquals([
'1' => $this->entities[0]
->id(),
'4' => $this->entities[1]
->id(),
], $result);
}