You are here

public function DisableFieldTest::testDisableFieldOnEditFormDisableForCertainRoles in Disable Field 8.2

Disable the field for certain roles on the content edit form.

File

tests/src/Functional/DisableFieldTest.php, line 238

Class

DisableFieldTest
Disable field tests.

Namespace

Drupal\Tests\disable_field\Functional

Code

public function testDisableFieldOnEditFormDisableForCertainRoles() : void {
  $this
    ->fieldUIAddNewField('admin/structure/types/manage/test', 'test', 'Test field', 'string', [], [
    'disable_field[edit][disable]' => 'roles',
    'disable_field[edit][roles][]' => [
      $this->role1,
    ],
  ]);
  $node = $this
    ->drupalCreateNode([
    'type' => 'test',
  ]);
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $this
    ->checkIfFieldIsNotDisabledByFieldName('field_test');
  $this
    ->drupalLogin($this->user1);
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $this
    ->checkIfFieldIsDisabledByFieldName('field_test');
  $this
    ->drupalLogin($this->user2);
  $this
    ->drupalGet($node
    ->toUrl('edit-form'));
  $this
    ->checkIfFieldIsNotDisabledByFieldName('field_test');
}