public function ProductAttributeValueAccessTest::testAccess in Commerce Core 8.2
@covers ::checkAccess
File
- modules/
product/ tests/ src/ Kernel/ ProductAttributeValueAccessTest.php, line 43
Class
- ProductAttributeValueAccessTest
- Tests the product attribute value access control.
Namespace
Drupal\Tests\commerce_product\KernelCode
public function testAccess() {
/** @var \Drupal\commerce_product\Entity\ProductAttributeValueInterface $attribute */
$attribute = ProductAttribute::create([
'id' => 'color',
'label' => 'Color',
]);
$attribute
->save();
/** @var \Drupal\commerce_product\Entity\ProductAttributeValueInterface $attribute_value */
$attribute_value = ProductAttributeValue::create([
'attribute' => 'color',
'name' => 'Black',
'weight' => 3,
]);
$attribute_value
->save();
$account = $this
->createUser([], [
'access administration pages',
]);
$this
->assertFalse($attribute_value
->access('view', $account));
$this
->assertFalse($attribute_value
->access('update', $account));
$this
->assertFalse($attribute_value
->access('delete', $account));
$account = $this
->createUser([], [
'access content',
]);
$this
->assertTrue($attribute_value
->access('view', $account));
$this
->assertFalse($attribute_value
->access('update', $account));
$this
->assertFalse($attribute_value
->access('delete', $account));
$account = $this
->createUser([], [
'update commerce_product_attribute',
]);
$this
->assertFalse($attribute_value
->access('view', $account));
$this
->assertTrue($attribute_value
->access('update', $account));
$this
->assertTrue($attribute_value
->access('delete', $account));
$account = $this
->createUser([], [
'administer commerce_product_attribute',
]);
$this
->assertTrue($attribute_value
->access('view', $account));
$this
->assertTrue($attribute_value
->access('update', $account));
$this
->assertTrue($attribute_value
->access('delete', $account));
}