-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1902 from MTES-MCT/hotfix/1886-pdf-replace-file-a…
…ttached-email-by-download-file [QA] Export PDF - Remplacer la pièce jointe par un lien de téléchargement dans le mail
- Loading branch information
Showing
18 changed files
with
135 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
33 changes: 33 additions & 0 deletions
33
src/Service/Signalement/Export/SignalementExportPdfGenerator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
namespace App\Service\Signalement\Export; | ||
|
||
use App\Entity\Signalement; | ||
use Knp\Snappy\Pdf; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
|
||
class SignalementExportPdfGenerator | ||
{ | ||
public function __construct(private readonly Pdf $pdf, private readonly ParameterBagInterface $parameterBag) | ||
{ | ||
} | ||
|
||
public function generate(string $content, ?array $options = null): string | ||
{ | ||
return $this->pdf->getOutputFromHtml($content, $options ?? []); | ||
} | ||
|
||
public function generateToTempFolder( | ||
Signalement $signalement, | ||
string $content, | ||
?array $options = null | ||
): string { | ||
$pdfContent = $this->generate($content, $options); | ||
|
||
$filename = 'export-pdf-signalement-'.$signalement->getUuid().'.pdf'; | ||
$tmpFilepath = $this->parameterBag->get('uploads_tmp_dir').$filename; | ||
file_put_contents($tmpFilepath, $pdfContent); | ||
|
||
return $filename; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ public function testShowUploadedFileSucceed(): void | |
$userRepository = static::getContainer()->get(UserRepository::class); | ||
$user = $userRepository->findOneBy(['email' => '[email protected]']); | ||
$client->loginUser($user); | ||
$client->request('GET', '/_up/check.png'); | ||
$client->request('GET', '/_up/check.png/00000000-0000-0000-2022-000000000001'); | ||
/** @var BinaryFileResponse $response */ | ||
$response = $client->getResponse(); | ||
$this->assertTrue($response->isSuccessful()); | ||
|
@@ -30,7 +30,7 @@ public function testShowUploadedFileFailed(): void | |
$user = $userRepository->findOneBy(['email' => '[email protected]']); | ||
$client->loginUser($user); | ||
|
||
$client->request('GET', '/_up/file_not_exist.txt'); | ||
$client->request('GET', '/_up/file_not_exist.txt/00000000-0000-0000-2022-000000000001'); | ||
/** @var BinaryFileResponse $response */ | ||
$response = $client->getResponse(); | ||
$this->assertEquals('image-404.png', $response->getFile()->getFilename()); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
use Symfony\Bridge\Twig\Mime\NotificationEmail; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\Messenger\MessageBusInterface; | ||
use Symfony\Component\Mime\Part\DataPart; | ||
|
||
class PdfExportMessageHandlerTest extends WebTestCase | ||
{ | ||
|
@@ -39,13 +38,8 @@ public function testHandleGeneratePdfMessage() | |
$this->assertEmailCount(1); | ||
/** @var NotificationEmail $email */ | ||
$email = $this->getMailerMessage(); | ||
$this->assertEmailAttachmentCount($email, 1); | ||
$this->assertEmailHtmlBodyContains($email, 'Un export pdf est disponible pour le signalement'); | ||
$this->assertEmailHtmlBodyContains($email, '#2023-1'); | ||
$this->assertEmailAddressContains($email, 'To', '[email protected]'); | ||
/** @var DataPart $attachment */ | ||
$attachment = $email->getAttachments()[0]; | ||
$this->assertEquals('2023-1.pdf', $attachment->getFilename()); | ||
$this->assertEquals('%PDF-1.4', substr($attachment->getBody(), 0, 8)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.