public function ViewsFieldAccessTest::setUp in Field Permissions 8
Same name and namespace in other branches
- 8.2 tests/src/Kernel/ViewsFieldAccessTest.php \Drupal\Tests\field_permissions\Kernel\ViewsFieldAccessTest::setUp()
Parameters
bool $import_test_views: Should the views specified on the test class be imported. If you need to setup some additional stuff, like fields, you need to call false and then call createTestViews for your own.
Overrides ViewsKernelTestBase::setUp
File
- tests/
src/ Kernel/ ViewsFieldAccessTest.php, line 91
Class
- ViewsFieldAccessTest
- Test that custom and private field access works with views.
Namespace
Drupal\Tests\field_permissions\KernelCode
public function setUp($import_test_views = TRUE) {
parent::setUp($import_test_views);
$this
->installEntitySchema('entity_test');
$this
->installEntitySchema('user');
$this
->installConfig('filter');
// Add a field to test, with default permissions initially.
$this->fieldStorage = FieldStorageConfig::create([
'field_name' => 'test_field',
'type' => 'text',
'entity_type' => 'entity_test',
]);
$this->fieldStorage
->setThirdPartySetting('field_permissions', 'permission_type', FieldPermissionTypeInterface::ACCESS_PUBLIC);
$this->fieldStorage
->save();
$this->field = FieldConfig::create([
'field_name' => 'test_field',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
]);
$this->field
->save();
// The roles are identical to start. Individual test methods will grant and
// revoke permissions as needed.
$role_with_access = Role::create([
'id' => 'with_access',
'permissions' => [
'view test entity',
],
]);
$role_with_access
->save();
$this->roleWithAccess = $role_with_access;
$role_without_access = Role::create([
'id' => 'without_access',
'permissions' => [
'view test entity',
],
]);
$role_without_access
->save();
$this->roleWithoutAccess = $role_without_access;
$this->userWithAccess = User::create([
'name' => $this
->randomMachineName(),
'roles' => [
$role_with_access
->id(),
],
]);
$this->userWithAccess
->save();
$this->userWithoutAccess = User::create([
'name' => $this
->randomMachineName(),
'roles' => [
$role_without_access
->id(),
],
]);
$this->userWithoutAccess
->save();
$this->entity = EntityTest::create([
$this->fieldStorage
->getName() => [
'value' => 'Test value',
'format' => filter_default_format(),
],
]);
$this->entity
->save();
}