public function IngredientAccessTest::testIngredientAccess in Recipe 8.2
Test Ingredient access by permission.
File
- modules/
ingredient/ tests/ src/ Kernel/ IngredientAccessTest.php, line 67
Class
- IngredientAccessTest
- @coversDefaultClass \Drupal\ingredient\IngredientAccessControlHandler
Namespace
Drupal\Tests\ingredient\KernelCode
public function testIngredientAccess() {
$ingredient = Ingredient::create([
'name' => 'test name',
]);
$ingredient
->save();
// Create a user with no permissions.
$user1 = $this
->drupalCreateUser();
$this
->assertIngredientCreateAccess(FALSE, $user1);
$this
->assertIngredientAccess([
'view' => FALSE,
'edit' => FALSE,
'delete' => FALSE,
], $ingredient, $user1);
// Create a user with all permissions.
$user2 = $this
->drupalCreateUser([
'add ingredient',
'view ingredient',
'edit ingredient',
'delete ingredient',
]);
$this
->assertIngredientCreateAccess(TRUE, $user2);
$this
->assertIngredientAccess([
'view' => TRUE,
'edit' => TRUE,
'delete' => TRUE,
], $ingredient, $user2);
}