public function MediaSourceFileTest::testFileDeletion in Drupal 9
Same name and namespace in other branches
- 8 core/modules/media/tests/src/Kernel/MediaSourceFileTest.php \Drupal\Tests\media\Kernel\MediaSourceFileTest::testFileDeletion()
Tests a media file can be deleted.
File
- core/
modules/ media/ tests/ src/ Kernel/ MediaSourceFileTest.php, line 33
Class
- MediaSourceFileTest
- Tests the file media source.
Namespace
Drupal\Tests\media\KernelCode
public function testFileDeletion() {
$mediaType = $this
->createMediaType('file');
$media = $this
->generateMedia('test.txt', $mediaType);
$media
->save();
$source_field_name = $mediaType
->getSource()
->getSourceFieldDefinition($mediaType)
->getName();
/** @var \Drupal\file\FileInterface $file */
$file = $media
->get($source_field_name)->entity;
$file
->delete();
$this
->assertEmpty($this->container
->get('entity_type.manager')
->getStorage('file')
->loadByProperties([
'filename' => 'test.txt',
]));
}