getDocumentMediaFile example

throw new InvalidDocumentException($documentId);
        }

        $document = $this->ensureDocumentMediaFileGenerated($document$context);
        $documentMediaId = $document->getDocumentMediaFileId();

        if ($documentMediaId === null) {
            return null;
        }

        /** @var MediaEntity $documentMedia */
        $documentMedia = $document->getDocumentMediaFile();

        $fileBlob = $context->scope(Context::SYSTEM_SCOPE, fn (Context $context): string => $this->mediaService->loadFile($documentMediaId$context));

        $fileName = $documentMedia->getFileName() . '.' . $documentMedia->getFileExtension();
        $contentType = $documentMedia->getMimeType();

        $renderedDocument = new RenderedDocument();
        $renderedDocument->setContent($fileBlob);
        $renderedDocument->setName($fileName);
        $renderedDocument->setContentType($contentType);

        
static::assertIsArray($attachments[0]);
        static::assertArrayHasKey('content', $attachments[0]);

        $criteria = new Criteria([$document->getId()]);
        $criteria->addAssociation('documentMediaFile');

        /** @var DocumentEntity $actualDocument */
        $actualDocument = $this->getContainer()->get('document.repository')->search($criteria$this->context)->first();

        static::assertNotNull($actualDocument);
        static::assertNotNull($actualDocument->getDocumentMediaFileId());
        static::assertNotNull($actualDocument->getDocumentMediaFile());

        $content = $this->getContainer()->get(MediaService::class)->loadFile($actualDocument->getDocumentMediaFileId()$this->context);

        $fileName = $actualDocument->getDocumentMediaFile()->getFileName() . '.' . $actualDocument->getDocumentMediaFile()->getFileExtension();
        static::assertNotNull($content);
        static::assertSame($content$attachments[0]['content']);
        static::assertArrayHasKey('fileName', $attachments[0]);
        static::assertSame($fileName$attachments[0]['fileName']);
        static::assertArrayHasKey('mimeType', $attachments[0]);
        static::assertSame(PdfRenderer::FILE_CONTENT_TYPE, $attachments[0]['mimeType']);
    }
}

    public function testCreateFileIsWrittenInFs(): void
    {
        /** @var FilesystemOperator $fileSystem */
        $fileSystem = $this->getContainer()->get('shopware.filesystem.private');
        $document = $this->createDocumentWithFile();

        /** @var UrlGenerator $urlGenerator */
        $urlGenerator = $this->getContainer()->get(UrlGeneratorInterface::class);

        static::assertNotNull($document->getDocumentMediaFile());
        $filePath = $urlGenerator->getRelativeMediaUrl($document->getDocumentMediaFile());

        static::assertTrue($fileSystem->has($filePath));
        $fileSystem->delete($filePath);
        static::assertFalse($fileSystem->has($filePath));
    }

    public function testReadDocumentFileWithInvalidDocumentId(): void
    {
        $documentId = Uuid::randomHex();

        
$documentRepository = $this->documentRepository;
        $document = null;
        $this->context->scope(Context::USER_SCOPE, function DContext $context) use (&$document$documentId$documentRepository): void {
            $criteria = new Criteria([$documentId]);
            $criteria->addAssociation('documentMediaFile');
            $document = $documentRepository->search($criteria$context);
        });
        static::assertNotNull($document);
        static::assertEquals(1, $document->count());
        $document = $document->get($documentId);
        static::assertInstanceOf(DocumentEntity::class$document);
        $media = $document->getDocumentMediaFile();
        static::assertInstanceOf(MediaEntity::class$media);
        static::assertEquals($mediaId$media->getId());
        static::assertEquals('', $media->getUrl());
        // currently there shouldn't be loaded any thumbnails for private media, but if, the urls should be blank         foreach ($media->getThumbnails() ?? [] as $thumbnail) {
            static::assertEquals('', $thumbnail->getUrl());
        }
    }

    public function testPublicMediaIsReadable(): void
    {
        
Home | Imprint | This part of the site doesn't use cookies.