test element file routing
This commit is contained in:
parent
14d2ce2284
commit
0d5783ba9c
14 changed files with 951 additions and 388 deletions
|
|
@ -9,9 +9,11 @@ use App\Element\UseCases\UpdateElement\UpdateElement;
|
|||
use App\Element\UseCases\UpdateElement\UpdateElementRequest;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateRichText;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
|
||||
use App\Element\UseCases\UpdateElement\UpdateTitle;
|
||||
use App\Element\UseCases\UpdateElement\UpdateYoutubeUrl;
|
||||
use App\Exceptions\BadRequestException;
|
||||
|
|
@ -38,13 +40,18 @@ class UpdateElementTest extends TestCase
|
|||
new UpdateDescription($this->elementRepo),
|
||||
new UpdateIconImageUrl($this->elementRepo, $this->fileUploader),
|
||||
new UpdateRichText($this->elementRepo),
|
||||
new UpdatePdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateShortPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateLongPdfPath($this->elementRepo, $this->fileUploader),
|
||||
new UpdateYoutubeUrl($this->elementRepo),
|
||||
new UpdateIconImage(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdatePdf(
|
||||
new UpdateShortPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
new UpdateLongPdf(
|
||||
$this->elementRepo,
|
||||
$this->fileUploader,
|
||||
),
|
||||
|
|
@ -62,6 +69,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -73,16 +81,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: '/assets/updated-icon.png',
|
||||
richText: '<p>Updated rich text</p>',
|
||||
pdfPath: '/assets/pdfs/updated.pdf',
|
||||
shortPdfPath: '/assets/pdfs/updated.pdf',
|
||||
longPdfPath: '/assets/pdfs/updated-long.pdf',
|
||||
pdfPath: null,
|
||||
youtubeUrl: 'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -102,7 +109,11 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/updated.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/updated-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
|
||||
|
|
@ -114,6 +125,50 @@ class UpdateElementTest extends TestCase
|
|||
$this->assertSame('Updated title', $persistedElement->getTitle());
|
||||
}
|
||||
|
||||
public function testLegacyPdfPathUpdatesShortPdfPath(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Original title',
|
||||
'Original description',
|
||||
null,
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$updatedElement = $this->updateElement->execute(
|
||||
new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: '/assets/pdfs/legacy-updated.pdf',
|
||||
youtubeUrl: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/legacy-updated.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
}
|
||||
|
||||
public function testConvertsEmptyNullableFieldsToNull(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
|
|
@ -124,6 +179,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -135,21 +191,21 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: '',
|
||||
richText: '<p>Updated rich text</p>',
|
||||
pdfPath: '',
|
||||
shortPdfPath: '',
|
||||
longPdfPath: '',
|
||||
pdfPath: null,
|
||||
youtubeUrl: '',
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
$this->assertNull($updatedElement->getIconImageUrl());
|
||||
$this->assertNull($updatedElement->getPdfPath());
|
||||
$this->assertNull($updatedElement->getShortPdfPath());
|
||||
$this->assertNull($updatedElement->getLongPdfPath());
|
||||
$this->assertNull($updatedElement->getYoutubeUrl());
|
||||
}
|
||||
|
||||
|
|
@ -163,6 +219,7 @@ class UpdateElementTest extends TestCase
|
|||
'/assets/original-icon.png',
|
||||
'<p>Original rich text</p>',
|
||||
'/assets/pdfs/original.pdf',
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -174,16 +231,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -202,7 +258,11 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/original-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
|
|
@ -210,7 +270,7 @@ class UpdateElementTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdatesUploadedFiles(): void
|
||||
public function testRoutesUploadedFilesByFileType(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
|
|
@ -222,8 +282,41 @@ class UpdateElementTest extends TestCase
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'iconImage',
|
||||
fileContents: 'binary-image-bytes',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'shortPdf',
|
||||
fileContents: 'binary-short-pdf-bytes',
|
||||
fileOriginalName: 'baderech.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
$updatedElement = $this->updateElement->execute(
|
||||
new UpdateElementRequest(
|
||||
id: $element->getId(),
|
||||
|
|
@ -231,16 +324,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: 'binary-image-bytes',
|
||||
iconImageOriginalName: 'icon.png',
|
||||
iconImageMimeType: 'image/png',
|
||||
iconImageSizeBytes: 1024,
|
||||
pdfContents: 'binary-pdf-bytes',
|
||||
pdfOriginalName: 'baderech.pdf',
|
||||
pdfMimeType: 'application/pdf',
|
||||
pdfSizeBytes: 1024,
|
||||
fileType: 'longPdf',
|
||||
fileContents: 'binary-long-pdf-bytes',
|
||||
fileOriginalName: 'baderech-long.pdf',
|
||||
fileMimeType: 'application/pdf',
|
||||
fileSizeBytes: 1024,
|
||||
)
|
||||
);
|
||||
|
||||
|
|
@ -249,17 +341,71 @@ class UpdateElementTest extends TestCase
|
|||
$updatedElement->getIconImageUrl(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/fake-baderech.pdf',
|
||||
$updatedElement->getPdfPath(),
|
||||
'element-pdfs/short/fake-baderech.pdf',
|
||||
$updatedElement->getShortPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long/fake-baderech-long.pdf',
|
||||
$updatedElement->getLongPdfPath(),
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-icons',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs',
|
||||
'element-pdfs/short',
|
||||
$this->fileUploader->uploads[1]['folder'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long',
|
||||
$this->fileUploader->uploads[2]['folder'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testThrowsWhenFileTypeMissingForUpload(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('fileType is required');
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: 1,
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: null,
|
||||
fileContents: 'binary-image-bytes',
|
||||
fileOriginalName: 'icon.png',
|
||||
fileMimeType: 'image/png',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenFileTypeInvalid(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('fileType is invalid');
|
||||
|
||||
$this->updateElement->execute(new UpdateElementRequest(
|
||||
id: 1,
|
||||
title: null,
|
||||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
fileType: 'audio',
|
||||
fileContents: 'binary-audio-bytes',
|
||||
fileOriginalName: 'shiur.mp3',
|
||||
fileMimeType: 'audio/mpeg',
|
||||
fileSizeBytes: 1024,
|
||||
));
|
||||
}
|
||||
|
||||
public function testThrowsWhenIdMissing(): void
|
||||
|
|
@ -273,16 +419,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -297,16 +442,15 @@ class UpdateElementTest extends TestCase
|
|||
description: null,
|
||||
iconImageUrl: null,
|
||||
richText: null,
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -321,16 +465,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -345,16 +488,15 @@ class UpdateElementTest extends TestCase
|
|||
description: 'Updated description',
|
||||
iconImageUrl: null,
|
||||
richText: '<p>Updated rich text</p>',
|
||||
shortPdfPath: null,
|
||||
longPdfPath: null,
|
||||
pdfPath: null,
|
||||
youtubeUrl: null,
|
||||
iconImageContents: null,
|
||||
iconImageOriginalName: null,
|
||||
iconImageMimeType: null,
|
||||
iconImageSizeBytes: null,
|
||||
pdfContents: null,
|
||||
pdfOriginalName: null,
|
||||
pdfMimeType: null,
|
||||
pdfSizeBytes: null,
|
||||
fileType: null,
|
||||
fileContents: null,
|
||||
fileOriginalName: null,
|
||||
fileMimeType: null,
|
||||
fileSizeBytes: null,
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -374,7 +516,8 @@ class UpdateElementTest extends TestCase
|
|||
string $description,
|
||||
?string $iconImageUrl,
|
||||
string $richText,
|
||||
?string $pdfPath,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
?string $youtubeUrl,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
|
|
@ -384,7 +527,8 @@ class UpdateElementTest extends TestCase
|
|||
description: $description,
|
||||
iconImageUrl: $iconImageUrl,
|
||||
richText: $richText,
|
||||
pdfPath: $pdfPath,
|
||||
shortPdfPath: $shortPdfPath,
|
||||
longPdfPath: $longPdfPath,
|
||||
youtubeUrl: $youtubeUrl,
|
||||
parentElement: $parentElement,
|
||||
));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue