diff --git a/core/modules/rest/src/Tests/FileTest.php b/core/modules/rest/src/Tests/FileTest.php index bc4fcc7..705de75 100644 --- a/core/modules/rest/src/Tests/FileTest.php +++ b/core/modules/rest/src/Tests/FileTest.php @@ -4,6 +4,7 @@ use Drupal\Core\Url; use Drupal\file\Entity\File; +use Drupal\file\FileInterface; /** * Tests CRUD operations for file entity. @@ -91,6 +92,9 @@ public function testCrudFile() { $file = File::load(1); $this->assertEqual('default2.txt', $file->getFilename(), 'The name was updated as expected'); + $file_uri = $file->getFileUri(); + $this->assertTrue($this->isFileInFileSystem($file_uri), 'File exists in file system'); + // Only the owner can remove the file. $this->drupalLogin($account2); $this->httpRequest('entity/' . $entity_type . '/1', 'DELETE', NULL, 'application/hal+json'); @@ -99,6 +103,27 @@ public function testCrudFile() { $this->drupalLogin($account1); $this->httpRequest('entity/' . $entity_type . '/1', 'DELETE', NULL, 'application/hal+json'); $this->assertResponse(204); + + \Drupal::entityTypeManager()->getStorage('file')->resetCache([1]); + $this->assertFalse($this->isFileInFileSystem($file_uri), 'File no longer exists in file system'); + $this->assertNull(File::load(1), 'The file no longer exists after delete.'); + + // Attempt to get the file again after delete. + $this->httpRequest(Url::fromUri('base://entity/file/1', ['query' => ['_format' => 'hal_json']]), 'GET', NULL, 'application/hal+json'); + $this->assertResponse(404); + } + + /** + * Determines whether a file is actually in the file system. + * + * @param $uri + * The URI of the file to check. + * + * @return bool + */ + protected function isFileInFileSystem($uri) { + $path = \Drupal::service('file_system')->realpath($uri); + return file_exists($path); } }