protected function FileDownloadLinkMediaTestTrait::createTestMedia in File Download Link 8
Helper function to create media that can be used for testing.
Return value
Drupal\media\Entity\Media A media to be used for testing.
2 calls to FileDownloadLinkMediaTestTrait::createTestMedia()
- FileDownloadLinkMediaTest::setUp in tests/
src/ Kernel/ FileDownloadLinkMediaTest.php - FileDownloadLinkMediaTokenTest::setUp in tests/
src/ Kernel/ FileDownloadLinkMediaTokenTest.php
File
- tests/
src/ Kernel/ FileDownloadLinkMediaTestTrait.php, line 42
Class
- FileDownloadLinkMediaTestTrait
- Trait for testing file_download_link_media formatter.
Namespace
Drupal\Tests\file_download_link\KernelCode
protected function createTestMedia() {
$this
->createMediaType('file', [
'id' => 'test_media',
'label' => 'Test Media',
]);
file_put_contents('public://file.txt', str_repeat('t', 10));
$file_file = File::create([
'uri' => 'public://file.txt',
'filename' => 'file.txt',
]);
$file_file
->save();
$media = Media::create([
'bundle' => 'test_media',
'name' => 'Test Media',
]);
$media
->set('field_media_file', $file_file
->id());
$media
->set('status', 1);
$media
->save();
return $media;
}