function AccessTest::testCreateAccess

Same name in other branches
  1. 9 core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest::testCreateAccess()
  2. 8.9.x core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest::testCreateAccess()
  3. 11.x core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest::testCreateAccess()

Tests create access is always denied even for user 1.

See also

\Drupal\file\FileAccessControlHandler::checkCreateAccess()

File

core/modules/file/tests/src/Kernel/AccessTest.php, line 148

Class

AccessTest
Tests for the File access control.

Namespace

Drupal\Tests\file\Kernel

Code

public function testCreateAccess() : void {
    $user1 = $this->createUser([
        'delete own files',
    ]);
    $this->assertSame('1', $user1->id());
    $file = File::create([
        'uid' => $user1->id(),
        'filename' => 'druplicon.txt',
        'filemime' => 'text/plain',
    ]);
    $this->assertFalse($file->access('create'));
    \Drupal::currentUser()->setAccount($user1);
    $this->assertFalse($file->access('create'));
}

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