public function UncacheableQueryAccessTest::testViewsWithRevisions in Entity API 8
Tests Views filtering when all revisions are queried.
File
- tests/
src/ Kernel/ QueryAccess/ UncacheableQueryAccessTest.php, line 403
Class
- UncacheableQueryAccessTest
- Test uncacheable query access filtering for EntityQuery and Views.
Namespace
Drupal\Tests\entity\Kernel\QueryAccessCode
public function testViewsWithRevisions() {
// Admin permission, full access.
$admin_user = $this
->createUser([], [
'administer entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($admin_user);
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '1',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '2',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '3',
'id' => $this->entities[1]
->id(),
],
[
'vid' => '4',
'id' => $this->entities[1]
->id(),
],
[
'vid' => '5',
'id' => $this->entities[2]
->id(),
],
[
'vid' => '6',
'id' => $this->entities[2]
->id(),
],
], [
'vid' => 'vid',
]);
// No view permissions, no access.
$user = $this
->createUser([], [
'access content',
]);
$this->container
->get('current_user')
->setAccount($user);
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, []);
// View own (published-only).
$user = $this
->createUser([], [
'view own entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($user);
$this->entities[0]
->set('user_id', $user
->id());
$this->entities[0]
->save();
$this->entities[1]
->set('user_id', $user
->id());
$this->entities[1]
->save();
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '1',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '4',
'id' => $this->entities[1]
->id(),
],
], [
'vid' => 'vid',
]);
// View any (published-only).
$user = $this
->createUser([], [
'view any entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($user);
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '1',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '4',
'id' => $this->entities[1]
->id(),
],
[
'vid' => '5',
'id' => $this->entities[2]
->id(),
],
[
'vid' => '6',
'id' => $this->entities[2]
->id(),
],
], [
'vid' => 'vid',
]);
// View own unpublished.
$user = $this
->createUser([], [
'view own unpublished entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($user);
$this->entities[0]
->set('user_id', $user
->id());
$this->entities[0]
->save();
$this->entities[1]
->set('user_id', $user
->id());
$this->entities[1]
->save();
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '2',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '3',
'id' => $this->entities[1]
->id(),
],
], [
'vid' => 'vid',
]);
// View own unpublished + view any (published-only).
$user = $this
->createUser([], [
'view own unpublished entity_test_enhanced_with_owner',
'view any entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($user);
$this->entities[0]
->set('user_id', $user
->id());
$this->entities[0]
->save();
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '1',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '2',
'id' => $this->entities[0]
->id(),
],
[
'vid' => '4',
'id' => $this->entities[1]
->id(),
],
[
'vid' => '5',
'id' => $this->entities[2]
->id(),
],
[
'vid' => '6',
'id' => $this->entities[2]
->id(),
],
], [
'vid' => 'vid',
]);
// View own $first_bundle + View any $second_bundle.
$user = $this
->createUser([], [
'view own first entity_test_enhanced_with_owner',
'view any second entity_test_enhanced_with_owner',
]);
$this->container
->get('current_user')
->setAccount($user);
$this->entities[1]
->set('user_id', $user
->id());
$this->entities[1]
->save();
$view = Views::getView('entity_test_enhanced_with_owner_revisions');
$view
->execute();
$this
->assertIdenticalResultset($view, [
[
'vid' => '4',
'id' => $this->entities[1]
->id(),
],
[
'vid' => '5',
'id' => $this->entities[2]
->id(),
],
[
'vid' => '6',
'id' => $this->entities[2]
->id(),
],
], [
'vid' => 'vid',
]);
}