function AddPermissionsUpdateTest::testUpdate

Same name in other branches
  1. 10 core/modules/help/tests/src/Functional/AddPermissionsUpdateTest.php \Drupal\Tests\help\Functional\AddPermissionsUpdateTest::testUpdate()

Tests adding 'access help pages' permission.

File

core/modules/help/tests/src/Functional/AddPermissionsUpdateTest.php, line 34

Class

AddPermissionsUpdateTest
Tests help_post_update_add_permissions_to_roles().

Namespace

Drupal\Tests\help\Functional

Code

public function testUpdate() : void {
    $roles = Role::loadMultiple();
    $this->assertGreaterThan(2, count($roles));
    foreach ($roles as $role) {
        $permissions = $role->toArray()['permissions'];
        $this->assertNotContains('access help pages', $permissions);
    }
    $this->runUpdates();
    $role = Role::load(Role::ANONYMOUS_ID);
    $permissions = $role->toArray()['permissions'];
    $this->assertNotContains('access help pages', $permissions);
    $role = Role::load(Role::AUTHENTICATED_ID);
    $permissions = $role->toArray()['permissions'];
    $this->assertNotContains('access help pages', $permissions);
    // Admin roles have the permission and do not need assigned.
    $role = Role::load('administrator');
    $permissions = $role->toArray()['permissions'];
    $this->assertNotContains('access help pages', $permissions);
    $role = Role::load('content_editor');
    $permissions = $role->toArray()['permissions'];
    $this->assertContains('access help pages', $permissions);
}

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