You are here

public function AccessTest::testOnlyOwnerCanDeleteUpdateFile in Drupal 8

Same name and namespace in other branches
  1. 9 core/modules/file/tests/src/Kernel/AccessTest.php \Drupal\Tests\file\Kernel\AccessTest::testOnlyOwnerCanDeleteUpdateFile()
  2. 10 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'));
}