You are here

protected function AccessByRoleFormTest::doFormTests in Workbench Access 8

Test the form with the given section.

Parameters

\Drupal\workbench_access\Entity\AccessSchemeInterface $scheme: The access scheme.

string $section_id: Section ID.

2 calls to AccessByRoleFormTest::doFormTests()
AccessByRoleFormTest::testAccessByRoleForm in tests/src/Functional/AccessByRoleFormTest.php
Tests that the correct roles are displayed on the access by role form.
AccessByRoleFormTest::testAccessByRoleFormMenu in tests/src/Functional/AccessByRoleFormTest.php
Tests that the correct roles are displayed on the access by role form.

File

tests/src/Functional/AccessByRoleFormTest.php, line 90

Class

AccessByRoleFormTest
Tests for the access by role form.

Namespace

Drupal\Tests\workbench_access\Functional

Code

protected function doFormTests(AccessSchemeInterface $scheme, $section_id) {
  $page = $this
    ->getSession()
    ->getPage();
  $web_assert = $this
    ->assertSession();
  $this
    ->createRole([], 'non_staff', 'Non staff');
  $expected_role_id = $this
    ->createRole([
    'use workbench access',
  ], 'staff', 'Staff');
  $this
    ->createRole([
    'use workbench access',
  ], 'super_staff', 'Super staff');
  $this
    ->drupalLogin($this
    ->setUpAdminUser());
  $this
    ->drupalGet(sprintf('/admin/config/workflow/workbench_access/editorial_section/sections/%s/roles', $section_id));
  $editors = $page
    ->findField('edit-editors');
  $web_assert
    ->fieldNotExists('Non staff', $editors);
  $web_assert
    ->fieldExists('Staff', $editors);
  $web_assert
    ->fieldExists('Super staff', $editors);
  $page
    ->checkField('Staff');
  $page
    ->pressButton('Submit');
  $expected = [
    $expected_role_id,
  ];
  $role_storage = $this->container
    ->get('workbench_access.role_section_storage');
  $existing_roles = $role_storage
    ->getRoles($scheme, $section_id);
  $this
    ->assertEquals($expected, $existing_roles);
  $this
    ->drupalGet(sprintf('/admin/config/workflow/workbench_access/editorial_section/sections/%s/roles', $section_id));
  $editors = $page
    ->findField('edit-editors');
  $web_assert
    ->checkboxChecked('Staff', $editors);
  $web_assert
    ->checkboxNotChecked('Super staff', $editors);
  $page
    ->uncheckField('Staff');
  $page
    ->pressButton('Submit');
  $expected = [];
  $role_storage = $this->container
    ->get('workbench_access.role_section_storage');
  $existing_roles = $role_storage
    ->getRoles($scheme, $section_id);
  $this
    ->assertEquals($expected, $existing_roles);
  $this
    ->drupalGet(sprintf('/admin/config/workflow/workbench_access/editorial_section/sections/%s/roles', $section_id));
  $editors = $page
    ->findField('edit-editors');
  $web_assert
    ->checkboxNotChecked('Staff', $editors);
  $web_assert
    ->checkboxNotChecked('Super staff', $editors);
}