You are here

public function MediaHelperTest::testPrepareFileDestination in Lightning Media 8.4

@covers ::prepareFileDestination @covers ::getSourceField

File

tests/src/Kernel/MediaHelperTest.php, line 53

Class

MediaHelperTest
@group lightning_media

Namespace

Drupal\Tests\lightning_media\Kernel

Code

public function testPrepareFileDestination() {
  $media_type = $this
    ->createMediaType('file');
  $media = Media::create([
    'bundle' => $media_type
      ->id(),
  ]);

  /** @var \Drupal\field\Entity\FieldConfig $source_field */
  $source_field = $media
    ->getSource()
    ->getSourceFieldDefinition($media_type);
  $source_field
    ->setSetting('file_directory', 'wambooli')
    ->save();
  $file = File::create([
    'uri' => $this
      ->generateFile('foo', 80, 10),
  ]);
  $file
    ->save();
  $media
    ->set($source_field
    ->getName(), $file
    ->id());
  $this
    ->assertDirectoryNotExists('public://wambooli');
  MediaHelper::prepareFileDestination($media);
  $this
    ->assertDirectoryExists('public://wambooli');
}