You are here

public function UncacheableQueryAccessHandlerTest::testUpdateDuplicateDelete in Entity API 8

@covers ::getConditions

File

tests/src/Kernel/QueryAccess/UncacheableQueryAccessHandlerTest.php, line 163

Class

UncacheableQueryAccessHandlerTest
Tests the uncacheable query access handler.

Namespace

Drupal\Tests\entity\Kernel\QueryAccess

Code

public function testUpdateDuplicateDelete() {
  foreach ([
    'update',
    'duplicate',
    'delete',
  ] as $operation) {

    // Any permission for the first bundle, own permission for the second.
    $user = $this
      ->createUser([], [
      "{$operation} any first entity_test_enhanced_with_owner",
      "{$operation} own second entity_test_enhanced_with_owner",
    ]);
    $conditions = $this->handler
      ->getConditions($operation, $user);
    $expected_conditions = [
      new Condition('type', [
        'first',
      ]),
      (new ConditionGroup('AND'))
        ->addCondition('user_id', $user
        ->id())
        ->addCondition('type', [
        'second',
      ]),
    ];
    $this
      ->assertEquals('OR', $conditions
      ->getConjunction());
    $this
      ->assertEquals(2, $conditions
      ->count());
    $this
      ->assertEquals($expected_conditions, $conditions
      ->getConditions());
    $this
      ->assertEquals([
      'user',
      'user.permissions',
    ], $conditions
      ->getCacheContexts());
    $this
      ->assertFalse($conditions
      ->isAlwaysFalse());
  }
}