You are here

public function OrderQueryAccessHandlerTest::testView in Commerce Core 8.2

@covers ::getConditions

File

modules/order/tests/src/Kernel/OrderQueryAccessHandlerTest.php, line 79

Class

OrderQueryAccessHandlerTest
Tests the order query access handler.

Namespace

Drupal\Tests\commerce_order\Kernel

Code

public function testView() {

  // Entity type permission.
  $user = $this
    ->createUser([], [
    'view commerce_order',
  ]);
  $conditions = $this->handler
    ->getConditions('view', $user);
  $this
    ->assertEquals(0, $conditions
    ->count());
  $this
    ->assertEquals([
    'user.permissions',
  ], $conditions
    ->getCacheContexts());
  $this
    ->assertFalse($conditions
    ->isAlwaysFalse());

  // Own permission.
  $user = $this
    ->createUser([], [
    'view own commerce_order',
  ]);
  $conditions = $this->handler
    ->getConditions('view', $user);
  $expected_conditions = [
    new Condition('uid', $user
      ->id()),
  ];
  $this
    ->assertEquals('OR', $conditions
    ->getConjunction());
  $this
    ->assertEquals(1, $conditions
    ->count());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEquals([
    'user',
    'user.permissions',
  ], $conditions
    ->getCacheContexts());
  $this
    ->assertFalse($conditions
    ->isAlwaysFalse());

  // Bundle permission.
  $user = $this
    ->createUser([], [
    'view first commerce_order',
  ]);
  $conditions = $this->handler
    ->getConditions('view', $user);
  $expected_conditions = [
    new Condition('type', [
      'first',
    ]),
  ];
  $this
    ->assertEquals('OR', $conditions
    ->getConjunction());
  $this
    ->assertEquals(1, $conditions
    ->count());
  $this
    ->assertEquals($expected_conditions, $conditions
    ->getConditions());
  $this
    ->assertEquals([
    'user.permissions',
  ], $conditions
    ->getCacheContexts());
  $this
    ->assertFalse($conditions
    ->isAlwaysFalse());
}