public function LogAccessTest::testAccess in Commerce Core 8.2
@covers ::checkAccess
File
- modules/
log/ tests/ src/ Kernel/ LogAccessTest.php, line 41
Class
- LogAccessTest
- Tests the log access control.
Namespace
Drupal\Tests\commerce_log\KernelCode
public function testAccess() {
$order = Order::create([
'type' => 'default',
'state' => 'canceled',
]);
$order
->save();
/** @var \Drupal\commerce_log\Entity\LogInterface $log */
$log = Log::create([
'category_id' => 'commerce_order',
'template_id' => 'order_canceled',
'source_entity_id' => $order
->id(),
'source_entity_type' => 'commerce_order',
'params' => [],
]);
$log
->save();
$account = $this
->createUser([], [
'access administration pages',
]);
$this
->assertFalse($log
->access('view', $account));
$this
->assertFalse($log
->access('update', $account));
$this
->assertFalse($log
->access('delete', $account));
$account = $this
->createUser([], [
'view commerce_order',
]);
$this
->assertTrue($log
->access('view', $account));
$this
->assertFalse($log
->access('update', $account));
$this
->assertFalse($log
->access('delete', $account));
$account = $this
->createUser([], [
'update default commerce_order',
]);
$this
->assertFalse($log
->access('view', $account));
$this
->assertTrue($log
->access('update', $account));
$this
->assertTrue($log
->access('delete', $account));
$account = $this
->createUser([], [
'administer commerce_order',
]);
$this
->assertTrue($log
->access('view', $account));
$this
->assertTrue($log
->access('update', $account));
$this
->assertTrue($log
->access('delete', $account));
// Broken source reference.
$log
->set('source_entity_id', '999');
$account = $this
->createUser([], [
'update default commerce_order',
]);
$this
->assertFalse($log
->access('view', $account));
$this
->assertFalse($log
->access('update', $account));
$this
->assertFalse($log
->access('delete', $account));
}