test element file routing
This commit is contained in:
parent
14d2ce2284
commit
0d5783ba9c
14 changed files with 951 additions and 388 deletions
|
|
@ -10,9 +10,11 @@ use App\Element\UseCases\UpdateElement\UpdateDescription;
|
|||
use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImage;
|
||||
use App\Element\UseCases\UpdateElement\UpdateIconImageUrl;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdf;
|
||||
use App\Element\UseCases\UpdateElement\UpdatePdfPath;
|
||||
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\Set\Set as DomainSet;
|
||||
|
|
@ -40,13 +42,18 @@ class ElementControllerTest 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,
|
||||
),
|
||||
|
|
@ -69,6 +76,7 @@ class ElementControllerTest extends TestCase
|
|||
'/assets/baderech-icon.png',
|
||||
'<p>A structured path for growth</p>',
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
'https://www.youtube.com/watch?v=yHx-r4p6hHU&t=1s',
|
||||
null,
|
||||
);
|
||||
|
|
@ -80,6 +88,7 @@ class ElementControllerTest extends TestCase
|
|||
'<p>Foundations rich text</p>',
|
||||
'/assets/pdfs/foundations.pdf',
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
$secondChildElement = $this->createElement(
|
||||
|
|
@ -90,6 +99,7 @@ class ElementControllerTest extends TestCase
|
|||
'<p>Daily practice rich text</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
$element,
|
||||
);
|
||||
|
||||
|
|
@ -111,6 +121,14 @@ class ElementControllerTest extends TestCase
|
|||
'/assets/baderech-icon.png',
|
||||
$body['element']['iconImageUrl'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
$body['element']['shortPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech-long.pdf',
|
||||
$body['element']['longPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'/assets/pdfs/baderech.pdf',
|
||||
$body['element']['pdfPath'],
|
||||
|
|
@ -158,21 +176,13 @@ class ElementControllerTest extends TestCase
|
|||
public function testUpdateWithIconImageReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/icon.png';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'iconImage',
|
||||
], [], [], [
|
||||
'iconImage' => new UploadedFile(
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'icon.png',
|
||||
'image/png',
|
||||
|
|
@ -196,24 +206,16 @@ class ElementControllerTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testUpdateWithPdfReturnsElementPayload(): void
|
||||
public function testUpdateWithShortPdfReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'shortPdf',
|
||||
], [], [], [
|
||||
'pdf' => new UploadedFile(
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'baderech.pdf',
|
||||
'application/pdf',
|
||||
|
|
@ -228,11 +230,48 @@ class ElementControllerTest extends TestCase
|
|||
$body = json_decode($response->getContent(), true);
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertSame(
|
||||
'https://test.local/storage/element-pdfs/fake-baderech.pdf',
|
||||
'https://test.local/storage/element-pdfs/short/fake-baderech.pdf',
|
||||
$body['element']['shortPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
$body['element']['shortPdfPath'],
|
||||
$body['element']['pdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs',
|
||||
'element-pdfs/short',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateWithLongPdfReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
$element = $this->createEmptyElement($set);
|
||||
$fixturePath = __DIR__ . '/../../fixtures/baderech.pdf';
|
||||
$request = new Request([], [
|
||||
'elementId' => (string) $element->getId(),
|
||||
'fileType' => 'longPdf',
|
||||
], [], [], [
|
||||
'file' => new UploadedFile(
|
||||
$fixturePath,
|
||||
'baderech.pdf',
|
||||
'application/pdf',
|
||||
null,
|
||||
true,
|
||||
),
|
||||
], ['REQUEST_METHOD' => 'POST']);
|
||||
|
||||
$response = $this->controller->update($request);
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$body = json_decode($response->getContent(), true);
|
||||
$this->assertSame($element->getId(), $body['element']['id']);
|
||||
$this->assertSame(
|
||||
'https://test.local/storage/element-pdfs/long/fake-baderech.pdf',
|
||||
$body['element']['longPdfPath'],
|
||||
);
|
||||
$this->assertSame(
|
||||
'element-pdfs/long',
|
||||
$this->fileUploader->uploads[0]['folder'],
|
||||
);
|
||||
}
|
||||
|
|
@ -247,13 +286,29 @@ class ElementControllerTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
private function createEmptyElement(DomainSet $set): Element
|
||||
{
|
||||
return $this->createElement(
|
||||
$set,
|
||||
'Baderech HaAvodah',
|
||||
'A structured path for growth',
|
||||
null,
|
||||
'<p>A structured path for growth</p>',
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
);
|
||||
}
|
||||
|
||||
private function createElement(
|
||||
DomainSet $set,
|
||||
string $title,
|
||||
string $description,
|
||||
?string $iconImageUrl,
|
||||
string $richText,
|
||||
?string $pdfPath,
|
||||
?string $shortPdfPath,
|
||||
?string $longPdfPath,
|
||||
?string $youtubeUrl,
|
||||
?Element $parentElement,
|
||||
): Element {
|
||||
|
|
@ -263,7 +318,8 @@ class ElementControllerTest 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