mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 10:49:00 +02:00
Added tests for various label services.
This commit is contained in:
parent
e925bec5b6
commit
236249e4a1
10 changed files with 467 additions and 47 deletions
|
@ -22,7 +22,7 @@ namespace App\Controller;
|
|||
|
||||
|
||||
use App\Form\LabelSystem\ScanDialogType;
|
||||
use App\Services\LabelSystem\BarcodeParser;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeRedirector;
|
||||
use App\Services\LabelSystem\Barcodes\BarcodeNormalizer;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
@ -40,7 +40,7 @@ class ScanController extends AbstractController
|
|||
protected $barcodeParser;
|
||||
protected $barcodeNormalizer;
|
||||
|
||||
public function __construct(BarcodeParser $barcodeParser, BarcodeNormalizer $barcodeNormalizer)
|
||||
public function __construct(BarcodeRedirector $barcodeParser, BarcodeNormalizer $barcodeNormalizer)
|
||||
{
|
||||
$this->barcodeParser = $barcodeParser;
|
||||
$this->barcodeNormalizer = $barcodeNormalizer;
|
||||
|
@ -61,7 +61,7 @@ class ScanController extends AbstractController
|
|||
try {
|
||||
[$type, $id] = $this->barcodeNormalizer->normalizeBarcodeContent($input);
|
||||
try {
|
||||
return $this->redirect($this->barcodeParser->getQRRedirectTarget($type, $id));
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
|
||||
} catch (EntityNotFoundException $exception) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
}
|
||||
|
@ -84,7 +84,7 @@ class ScanController extends AbstractController
|
|||
{
|
||||
try {
|
||||
$this->addFlash('success', 'scan.qr_success');
|
||||
return $this->redirect($this->barcodeParser->getQRRedirectTarget($type, $id));
|
||||
return $this->redirect($this->barcodeParser->getRedirectURL($type, $id));
|
||||
} catch (EntityNotFoundException $exception) {
|
||||
$this->addFlash('success', 'scan.qr_not_found');
|
||||
return $this->redirectToRoute('homepage');
|
||||
|
|
|
@ -76,7 +76,7 @@ final class BarcodeContentGenerator
|
|||
public function get1DBarcodeContent(AbstractDBElement $target): string
|
||||
{
|
||||
$prefix = $this->classToString(self::PREFIX_MAP, $target);
|
||||
$id = sprintf('%04d', $target->getID());
|
||||
$id = sprintf('%04d', $target->getID() ?? 0);
|
||||
return $prefix . $id;
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Services\LabelSystem;
|
||||
namespace App\Services\LabelSystem\Barcodes;
|
||||
|
||||
|
||||
use App\Entity\Parts\PartLot;
|
||||
|
@ -26,7 +26,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
|||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
|
||||
final class BarcodeParser
|
||||
final class BarcodeRedirector
|
||||
{
|
||||
private $urlGenerator;
|
||||
private $em;
|
||||
|
@ -45,7 +45,7 @@ final class BarcodeParser
|
|||
* @return string The URL to which should be redirected.
|
||||
* @throws EntityNotFoundException
|
||||
*/
|
||||
public function getQRRedirectTarget(string $type, int $id): string
|
||||
public function getRedirectURL(string $type, int $id): string
|
||||
{
|
||||
switch ($type) {
|
||||
case 'part':
|
|
@ -62,8 +62,6 @@ final class LabelGenerator
|
|||
$elements = [$elements];
|
||||
}
|
||||
|
||||
$elements_html = [];
|
||||
|
||||
foreach ($elements as $element) {
|
||||
if (!$this->supports($options, $element)) {
|
||||
throw new \InvalidArgumentException('The given options are not compatible with the given element!');
|
||||
|
@ -94,8 +92,14 @@ final class LabelGenerator
|
|||
return is_a($element, static::CLASS_SUPPORT_MAPPING[$supported_type]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts width and height given in mm to an size array, that can be used by DOMPDF for page size
|
||||
* @param float $width The width of the paper
|
||||
* @param float $height The height of the paper
|
||||
* @return float[]
|
||||
*/
|
||||
public function mmToPointsArray(float $width, float $height): array
|
||||
{
|
||||
return [0, 0, $width * self::MM_TO_POINTS_FACTOR, $height * self::MM_TO_POINTS_FACTOR];
|
||||
return [0.0, 0.0, $width * self::MM_TO_POINTS_FACTOR, $height * self::MM_TO_POINTS_FACTOR];
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue