function AccessTest::testOnlyOwnerCanDeleteUpdateFile

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest::testOnlyOwnerCanDeleteUpdateFile()

Tests that only the file owner can delete or update a file.

File

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

Class

AccessTest
Tests for the File access control.

Namespace

Drupal\Tests\file\Kernel

Code

public function testOnlyOwnerCanDeleteUpdateFile() {
    \Drupal::currentUser()->setAccount($this->user2);
    $this->assertFalse($this->file
        ->access('delete'));
    $this->assertFalse($this->file
        ->access('update'));
    \Drupal::currentUser()->setAccount($this->user1);
    $this->assertTrue($this->file
        ->access('delete'));
    $this->assertTrue($this->file
        ->access('update'));
}

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