public function QueryAccessHandlerTest::testView in Entity API 8
@covers ::getConditions
File
- tests/
src/ Kernel/ QueryAccess/ QueryAccessHandlerTest.php, line 82
Class
- QueryAccessHandlerTest
- Tests the query access handler.
Namespace
Drupal\Tests\entity\Kernel\QueryAccessCode
public function testView() {
// Entity type permission.
$user = $this
->createUser([], [
'view entity_test_enhanced',
]);
$conditions = $this->handler
->getConditions('view', $user);
$expected_conditions = [
new Condition('status', '1'),
];
$this
->assertEquals(1, $conditions
->count());
$this
->assertEquals($expected_conditions, $conditions
->getConditions());
$this
->assertEquals([
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertFalse($conditions
->isAlwaysFalse());
// Bundle permission.
$user = $this
->createUser([], [
'view first entity_test_enhanced',
]);
$conditions = $this->handler
->getConditions('view', $user);
$expected_conditions = [
new Condition('type', [
'first',
]),
new Condition('status', '1'),
];
$this
->assertEquals('AND', $conditions
->getConjunction());
$this
->assertEquals(2, $conditions
->count());
$this
->assertEquals($expected_conditions, $conditions
->getConditions());
$this
->assertEquals([
'user.permissions',
], $conditions
->getCacheContexts());
$this
->assertFalse($conditions
->isAlwaysFalse());
}