protected function AccessByUserFormTest::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.
string $section_label: Section label.
2 calls to AccessByUserFormTest::doFormTests()
- AccessByUserFormTest::testAccessByUserForm in tests/
src/ Functional/ AccessByUserFormTest.php - Tests that the correct users are displayed on the access by user form.
- AccessByUserFormTest::testAccessByUserFormMenu in tests/
src/ Functional/ AccessByUserFormTest.php - Tests that the correct users are displayed on the access by user form.
File
- tests/
src/ Functional/ AccessByUserFormTest.php, line 90
Class
- AccessByUserFormTest
- Tests for the access by user form.
Namespace
Drupal\Tests\workbench_access\FunctionalCode
protected function doFormTests(AccessSchemeInterface $scheme, $section_id, $section_label) {
$web_assert = $this
->assertSession();
$page = $this
->getSession()
->getPage();
$user_storage = $this->container
->get('workbench_access.user_section_storage');
$non_staff_rid = $this
->createRole([], 'non_staff');
$staff_rid = $this
->createRole([
'use workbench access',
], 'staff');
$user1 = $this
->createUserWithRole($non_staff_rid);
$user2 = $this
->createUserWithRole($staff_rid);
$user3 = $this
->createUserWithRole($staff_rid);
$user4 = $this
->createUserWithRole($staff_rid);
$this
->drupalLogin($this
->setUpAdminUser());
$this
->drupalGet('/admin/config/workflow/workbench_access/editorial_section/sections');
$web_assert
->pageTextContains('Editorial sections');
$web_assert
->pageTextContains($section_label);
$this
->drupalGet(sprintf('/admin/config/workflow/workbench_access/editorial_section/sections/%s/users', $section_id));
// Add a user from staff with autocomplete.
$page
->fillField('edit-editors-add', $user2
->label() . ' (' . $user2
->id() . ')');
$page
->pressButton('add');
// We expect to find user 2 in the active list.
$expected = [
$user2
->id(),
];
$existing_users = $user_storage
->getEditors($scheme, $section_id);
$this
->assertEquals($expected, array_keys($existing_users));
// Check remove editors list.
$editors = $page
->findField('editors_remove');
$web_assert
->fieldNotExists('editors_remove[' . $user1
->id() . ']', $editors);
$web_assert
->fieldExists('editors_remove[' . $user2
->id() . ']', $editors);
// Test remove the user.
$page
->checkField('editors_remove[' . $user2
->id() . ']');
$page
->pressButton('remove');
// We expect to find no users in the active list.
$expected = [];
$existing_users = $user_storage
->getEditors($scheme, $section_id);
$this
->assertEquals($expected, array_keys($existing_users));
// Check user has been removed to the section.
$editors = $page
->findField('editors_remove');
$web_assert
->fieldNotExists('editors_remove[' . $user2
->id() . ']', $editors);
// Test adding users with the textarea, mixed username and uid.
$page
->fillField('edit-editors-add-mass', $user3
->label() . ', ' . $user4
->id());
$page
->pressButton('add');
// We expect to find users 3 and 4 in the active list.
$expected = [
$user3
->id(),
$user4
->id(),
];
$existing_users = $user_storage
->getEditors($scheme, $section_id);
$this
->assertEquals($expected, array_keys($existing_users));
$editors = $page
->findField('editors_remove');
$web_assert
->fieldExists('editors_remove[' . $user3
->id() . ']', $editors);
$web_assert
->fieldExists('editors_remove[' . $user4
->id() . ']', $editors);
}