function FileAddPermissionsUpdateTest::testUpdate

Same name in other branches
  1. 11.x core/modules/file/tests/src/Functional/FileAddPermissionsUpdateTest.php \Drupal\Tests\file\Functional\FileAddPermissionsUpdateTest::testUpdate()

Tests adding 'delete own files' permission.

File

core/modules/file/tests/src/Functional/FileAddPermissionsUpdateTest.php, line 32

Class

FileAddPermissionsUpdateTest
Tests file_post_update_add_permissions_to_roles().

Namespace

Drupal\Tests\file\Functional

Code

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

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