test pdf use case
This commit is contained in:
parent
208c683dac
commit
b1bee8a16e
3 changed files with 165 additions and 0 deletions
|
|
@ -8,6 +8,7 @@ use App\Element\Element;
|
|||
use App\Element\UseCases\CreateChildElement\CreateChildElement;
|
||||
use App\Element\UseCases\DeleteChildElement\DeleteChildElement;
|
||||
use App\Element\UseCases\GetElement\GetElement;
|
||||
use App\Element\UseCases\GetElementPdf\GetElementPdf;
|
||||
use App\Element\UseCases\ReorderChildElements\ReorderChildElements;
|
||||
use App\Element\UseCases\UpdateElement\UpdateDescription;
|
||||
use App\Element\UseCases\UpdateElement\UpdateElement;
|
||||
|
|
@ -25,6 +26,7 @@ use Illuminate\Http\Request;
|
|||
use Illuminate\Http\UploadedFile;
|
||||
use Tests\Fakes\FakeElementRepository;
|
||||
use Tests\Fakes\FakeFileUploader;
|
||||
use Tests\Fakes\FakeStoredFileReader;
|
||||
use Tests\TestCase;
|
||||
|
||||
class ElementControllerTest extends TestCase
|
||||
|
|
@ -35,10 +37,13 @@ class ElementControllerTest extends TestCase
|
|||
|
||||
private FakeFileUploader $fileUploader;
|
||||
|
||||
private FakeStoredFileReader $storedFileReader;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->elementRepo = new FakeElementRepository();
|
||||
$this->fileUploader = new FakeFileUploader();
|
||||
$this->storedFileReader = new FakeStoredFileReader();
|
||||
$getElement = new GetElement($this->elementRepo);
|
||||
$updateElement = new UpdateElement(
|
||||
new UpdateTitle($this->elementRepo),
|
||||
|
|
@ -68,6 +73,7 @@ class ElementControllerTest extends TestCase
|
|||
new DeleteChildElement($this->elementRepo, $this->fileUploader),
|
||||
new ReorderChildElements($this->elementRepo),
|
||||
$updateElement,
|
||||
new GetElementPdf($this->storedFileReader),
|
||||
$this->fileUploader,
|
||||
);
|
||||
}
|
||||
|
|
@ -244,6 +250,38 @@ class ElementControllerTest extends TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testShowPdfReturnsPdfResponse(): void
|
||||
{
|
||||
$this->storedFileReader->put(
|
||||
'element-pdfs/short/baderech.pdf',
|
||||
'pdf-bytes',
|
||||
);
|
||||
|
||||
$response = $this->controller->showPdf('short', 'baderech.pdf');
|
||||
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertSame('pdf-bytes', $response->getContent());
|
||||
$this->assertSame(
|
||||
'application/pdf',
|
||||
$response->headers->get('Content-Type'),
|
||||
);
|
||||
$this->assertSame(
|
||||
'inline; filename="baderech.pdf"',
|
||||
$response->headers->get('Content-Disposition'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testShowPdfReturns404WhenPdfDoesNotExist(): void
|
||||
{
|
||||
$response = $this->controller->showPdf('short', 'missing.pdf');
|
||||
|
||||
$this->assertEquals(404, $response->getStatusCode());
|
||||
$this->assertSame(
|
||||
['error' => 'PDF not found'],
|
||||
json_decode($response->getContent(), true),
|
||||
);
|
||||
}
|
||||
|
||||
public function testUpdateWithIconImageReturnsElementPayload(): void
|
||||
{
|
||||
$set = $this->createSet(1, 'Baderech');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue