Files
Starseed/tests/Module/Logistique/Api/WeighingTicketPrintApiTest.php
T
tristan faafd99ef8
Auto Tag Develop / tag (push) Successful in 8s
feat : M5 — Tickets de pesée (ERP-188 → ERP-193) (#144)
MR unique regroupant tout le module M5 « Tickets de pesée » (remplace les MR empilées #140/#141/#142/#143).

## Périmètre
- **ERP-188** — Page liste des tickets de pesée + export XLSX (colonnes Fournisseur/Client/Autre + Statut).
- **ERP-189** — Écran « Ajouter » (4 champs en haut, 2 blocs de pesée, pesée bascule/manuelle, date+heure horodatée à la validation).
- **ERP-190** — Écran « Modifier » + bouton Imprimer.
- **ERP-191** — i18n + libellés + branchement site courant.
- **ERP-192** — Bon de pesée PDF généré côté back (template Twig → Dompdf), endpoint `GET /api/weighing_tickets/{id}/print.pdf`.
- **ERP-193** — Cycle de vie brouillon/validé (status DRAFT/VALIDATED, numéro attribué à la validation), DSD saisi conservé en pesée manuelle, retours métier design.

## Vérifications
- Back : tests Logistique + architecture verts, php-cs-fixer propre, migrations appliquées (dev + test).
- Front : suite Vitest complète verte, ESLint propre.

Base : `develop` — contient les 16 commits du M5 (rien d'autre).
Reviewed-on: #144
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
2026-06-24 14:38:01 +00:00

74 lines
2.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Module\Logistique\Api;
/**
* Tests fonctionnels de l'impression du bon de pesee PDF (M5, spec-back § 2.12 /
* § 4.6 — RG-5.08, ERP-192) : operation `GET /api/weighing_tickets/{id}/print.pdf`.
*
* Couvre la verification du ticket :
* - 200 + PDF non vide (Content-Type application/pdf, disposition inline,
* signature %PDF) pour un ticket existant et visible ;
* - 403 sans la permission `logistique.weighing_tickets.view` ;
* - 404 pour un ticket inexistant.
*
* @internal
*/
final class WeighingTicketPrintApiTest extends AbstractWeighingTicketApiTestCase
{
public function testPrintReturnsNonEmptyPdfForExistingTicket(): void
{
$site = $this->firstSite();
$http = $this->authManageOnSite($site);
$client = $this->seedTestClient('Print');
$created = $this->postTicket($http, $this->validClientTicketPayload($client));
self::assertResponseStatusCodeSame(201);
$ticketId = $created->toArray()['id'];
$response = $http->request('GET', sprintf('/api/weighing_tickets/%d/print.pdf', $ticketId));
self::assertResponseIsSuccessful();
$headers = $response->getHeaders(false);
self::assertStringContainsString('application/pdf', $headers['content-type'][0] ?? '');
self::assertStringContainsString('inline', $headers['content-disposition'][0] ?? '');
// PDF non vide + signature de fichier PDF (« %PDF-1.x »).
$binary = $response->getContent(false);
self::assertNotSame('', $binary, 'Le PDF du bon de pesée ne doit pas être vide.');
self::assertStringStartsWith('%PDF', $binary);
}
public function testForbiddenWithoutViewPermission(): void
{
// On seede un ticket reel via un user habilite, puis on tente l'impression
// avec un user depourvu de `logistique.weighing_tickets.view`.
$site = $this->firstSite();
$manager = $this->authManageOnSite($site);
$client = $this->seedTestClient('Forbidden');
$created = $this->postTicket($manager, $this->validClientTicketPayload($client));
self::assertResponseStatusCodeSame(201);
$ticketId = $created->toArray()['id'];
$creds = $this->createUserWithPermission('core.users.view');
$intrus = $this->authenticatedClient($creds['username'], $creds['password']);
$intrus->request('GET', sprintf('/api/weighing_tickets/%d/print.pdf', $ticketId));
self::assertResponseStatusCodeSame(403);
}
public function testNotFoundForUnknownTicket(): void
{
$http = $this->authManageOnSite($this->firstSite());
$http->request('GET', '/api/weighing_tickets/99999999/print.pdf');
self::assertResponseStatusCodeSame(404);
}
}