ManagerTest.php in Field Permissions 8.2
File
tests/src/Kernel/Plugin/FieldPermissionType/ManagerTest.php
View source
<?php
namespace Drupal\Tests\field_permissions\Kernel\Plugin\FieldPermissionType;
use Drupal\entity_test\Entity\EntityTest;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\KernelTests\KernelTestBase;
use Drupal\Tests\user\Traits\UserCreationTrait;
class ManagerTest extends KernelTestBase {
use UserCreationTrait;
public static $modules = [
'entity_test',
'field',
'field_permissions',
'field_permissions_test',
'system',
'user',
];
protected $fieldPermissionTypeManager;
protected $account;
public function setUp() {
parent::setUp();
$this
->installSchema('system', [
'sequences',
]);
$this
->installEntitySchema('user');
$this
->installEntitySchema('entity_test');
$this->fieldPermissionTypeManager = $this->container
->get('plugin.field_permissions.types.manager');
$this->account = $this
->createUser([
'cancel account',
]);
}
public function testCreateInstance() {
$entity = EntityTest::create();
$field_storage = FieldStorageConfig::create([
'field_name' => 'test_foo',
'type' => 'text',
'entity_type' => 'entity_test',
]);
$plugin = $this->fieldPermissionTypeManager
->createInstance('test_access', [], $field_storage);
$this
->assertTrue($plugin
->hasFieldAccess('view', $entity, $this->account));
$this
->assertFalse($plugin
->hasFieldAccess('edit', $entity, $this->account));
}
public function testGetDefinitions() {
$definitions = $this->fieldPermissionTypeManager
->getDefinitions();
$this
->assertEquals(3, count($definitions));
$expected = [
'private',
'test_access',
'custom',
];
$this
->assertSame($expected, array_keys($definitions));
}
}
Classes
Name |
Description |
ManagerTest |
Integration tests for the field permission type plugin manager. |