diff --git a/src/Controller/ScanController.php b/src/Controller/ScanController.php index 947df5b2..fc575b50 100644 --- a/src/Controller/ScanController.php +++ b/src/Controller/ScanController.php @@ -49,6 +49,7 @@ use InvalidArgumentException; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\HttpKernel\Attribute\MapQueryParameter; use Symfony\Component\Routing\Annotation\Route; #[Route(path: '/scan')] @@ -59,16 +60,18 @@ class ScanController extends AbstractController } #[Route(path: '/', name: 'scan_dialog')] - public function dialog(Request $request): Response + public function dialog(Request $request, #[MapQueryParameter] ?string $input = null): Response { $this->denyAccessUnlessGranted('@tools.label_scanner'); $form = $this->createForm(ScanDialogType::class); $form->handleRequest($request); - if ($form->isSubmitted() && $form->isValid()) { + if ($input === null && $form->isSubmitted() && $form->isValid()) { $input = $form['input']->getData(); + } + if ($input !== null) { try { [$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input); diff --git a/tests/ApplicationAvailabilityFunctionalTest.php b/tests/ApplicationAvailabilityFunctionalTest.php index b050df72..399270b9 100644 --- a/tests/ApplicationAvailabilityFunctionalTest.php +++ b/tests/ApplicationAvailabilityFunctionalTest.php @@ -124,7 +124,6 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase //Scan test yield ['/scan']; //Interactive scan dialog - yield ['/scan/part/1']; //Scan a part //Tools yield ['/tools/reel_calc']; diff --git a/tests/Controller/ScanControllerTest.php b/tests/Controller/ScanControllerTest.php new file mode 100644 index 00000000..deb1311c --- /dev/null +++ b/tests/Controller/ScanControllerTest.php @@ -0,0 +1,49 @@ +. + */ + +namespace App\Tests\Controller; + +use Symfony\Bundle\FrameworkBundle\KernelBrowser; +use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; + +class ScanControllerTest extends WebTestCase +{ + + private ?KernelBrowser $client = null; + + public function setUp(): void + { + $this->client = static::createClient(); + $this->client->disableReboot(); + $this->client->catchExceptions(false); + } + + public function testRedirectOnInputParameter(): void + { + $this->client->request('GET', '/en/scan/?input=0000001'); + $this->assertResponseRedirects('/en/part/1'); + } + + public function testScanQRCode(): void + { + $this->client->request('GET', '/scan/part/1'); + $this->assertResponseRedirects('/en/part/1'); + } +} \ No newline at end of file