function UserPermissionsTest::testPermissionCheckboxes

Same name in other branches
  1. 9 core/modules/user/tests/src/FunctionalJavascript/UserPermissionsTest.php \Drupal\Tests\user\FunctionalJavascript\UserPermissionsTest::testPermissionCheckboxes()
  2. 11.x core/modules/user/tests/src/FunctionalJavascript/UserPermissionsTest.php \Drupal\Tests\user\FunctionalJavascript\UserPermissionsTest::testPermissionCheckboxes()

Tests the fake checkboxes added to the permissions page.

File

core/modules/user/tests/src/FunctionalJavascript/UserPermissionsTest.php, line 55

Class

UserPermissionsTest
Tests the JS components added to the user permissions page.

Namespace

Drupal\Tests\user\FunctionalJavascript

Code

public function testPermissionCheckboxes() : void {
    $this->drupalLogin($this->adminUser);
    $this->drupalGet('admin/people/permissions');
    $page = $this->getSession()
        ->getPage();
    $wrapper = $page->find('css', '.form-item-' . $this->rid . '-administer-modules');
    $fake_checkbox = $wrapper->find('css', '.fake-checkbox');
    // The real per-role checkbox is visible and unchecked, the fake copy does
    // not exist yet.
    $this->assertNull($fake_checkbox);
    // Enable the permission for all authenticated users.
    $page->findField('authenticated[administer modules]')
        ->click();
    // The checkboxes have been initialized.
    $real_checkbox = $wrapper->find('css', '.real-checkbox');
    $fake_checkbox = $wrapper->find('css', '.fake-checkbox');
    // The real and fake checkboxes switch visibility and the fake is now both
    // checked and disabled.
    $this->assertFalse($real_checkbox->isVisible());
    $this->assertTrue($fake_checkbox->isVisible());
    $this->assertTrue($fake_checkbox->isChecked());
    $this->assertTrue($fake_checkbox->hasAttribute('disabled'));
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.