test element file routing

This commit is contained in:
Yisroel Baum 2026-06-14 23:05:45 +03:00
parent 14d2ce2284
commit 0d5783ba9c
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
14 changed files with 951 additions and 388 deletions

View file

@ -8,8 +8,10 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
use App\Element\UseCases\UpdateElement\UpdateDescriptionRequest;
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
use App\Element\UseCases\UpdateElement\UpdateIconImageUrlRequest;
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
use App\Element\UseCases\UpdateElement\UpdatePdfPathRequest;
use App\Element\UseCases\UpdateElement\UpdateLongPdfPath;
use App\Element\UseCases\UpdateElement\UpdateLongPdfPathRequest;
use App\Element\UseCases\UpdateElement\UpdateShortPdfPath;
use App\Element\UseCases\UpdateElement\UpdateShortPdfPathRequest;
use App\Element\UseCases\UpdateElement\UpdateRichText;
use App\Element\UseCases\UpdateElement\UpdateRichTextRequest;
use App\Element\UseCases\UpdateElement\UpdateTitle;
@ -134,19 +136,26 @@ class UpdateElementFieldsTest extends TestCase
);
}
public function testUpdatePdfPathClearsEmptyString(): void
public function testUpdateShortPdfPathClearsEmptyString(): void
{
$element = $this->createFilledElement();
$updatePdfPath = new UpdatePdfPath(
$updateShortPdfPath = new UpdateShortPdfPath(
$this->elementRepo,
$this->fileUploader,
);
$updatedElement = $updatePdfPath->execute(
new UpdatePdfPathRequest(id: $element->getId(), pdfPath: '')
$updatedElement = $updateShortPdfPath->execute(
new UpdateShortPdfPathRequest(
id: $element->getId(),
shortPdfPath: '',
)
);
$this->assertNull($updatedElement->getPdfPath());
$this->assertNull($updatedElement->getShortPdfPath());
$this->assertSame(
'/assets/pdfs/original-long.pdf',
$updatedElement->getLongPdfPath(),
);
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
$this->assertSame(
['/assets/pdfs/original.pdf'],
@ -154,6 +163,33 @@ class UpdateElementFieldsTest extends TestCase
);
}
public function testUpdateLongPdfPathClearsEmptyString(): void
{
$element = $this->createFilledElement();
$updateLongPdfPath = new UpdateLongPdfPath(
$this->elementRepo,
$this->fileUploader,
);
$updatedElement = $updateLongPdfPath->execute(
new UpdateLongPdfPathRequest(
id: $element->getId(),
longPdfPath: '',
)
);
$this->assertSame(
'/assets/pdfs/original.pdf',
$updatedElement->getShortPdfPath(),
);
$this->assertNull($updatedElement->getLongPdfPath());
$this->assertSame($element->getTitle(), $updatedElement->getTitle());
$this->assertSame(
['/assets/pdfs/original-long.pdf'],
$this->fileUploader->deletedPaths,
);
}
public function testUpdateYoutubeUrlClearsEmptyString(): void
{
$element = $this->createFilledElement();
@ -175,12 +211,14 @@ class UpdateElementFieldsTest extends TestCase
return $this->createElementWithMedia(
'/assets/original-icon.png',
'/assets/pdfs/original.pdf',
'/assets/pdfs/original-long.pdf',
);
}
private function createElementWithMedia(
?string $iconImageUrl,
?string $pdfPath,
?string $shortPdfPath,
?string $longPdfPath,
): Element {
$set = new DomainSet(
id: 1,
@ -195,7 +233,8 @@ class UpdateElementFieldsTest extends TestCase
description: 'Original description',
iconImageUrl: $iconImageUrl,
richText: '<p>Original rich text</p>',
pdfPath: $pdfPath,
shortPdfPath: $shortPdfPath,
longPdfPath: $longPdfPath,
youtubeUrl: 'https://www.youtube.com/watch?v=yHx-r4p6hHU',
parentElement: null,
));