You are here

public function ProductAttributeValueAccessTest::testCreateAccess in Commerce Core 8.2

@covers ::checkCreateAccess

File

modules/product/tests/src/Kernel/ProductAttributeValueAccessTest.php, line 82

Class

ProductAttributeValueAccessTest
Tests the product attribute value access control.

Namespace

Drupal\Tests\commerce_product\Kernel

Code

public function testCreateAccess() {
  $access_control_handler = \Drupal::entityTypeManager()
    ->getAccessControlHandler('commerce_product_attribute_value');

  /** @var \Drupal\commerce_product\Entity\ProductAttributeValueInterface $attribute */
  $attribute = ProductAttribute::create([
    'id' => 'color',
    'label' => 'Color',
  ]);
  $attribute
    ->save();
  $account = $this
    ->createUser([], [
    'access content',
  ]);
  $this
    ->assertFalse($access_control_handler
    ->createAccess('color', $account));
  $account = $this
    ->createUser([], [
    'administer commerce_product_attribute',
  ]);
  $this
    ->assertTrue($access_control_handler
    ->createAccess('color', $account));
  $account = $this
    ->createUser([], [
    'update commerce_product_attribute',
  ]);
  $this
    ->assertTrue($access_control_handler
    ->createAccess('color', $account));
}