mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-08-03 09:44:41 +02:00
Use enums for LabelOptions
This commit is contained in:
parent
485b35fbd4
commit
71cd4057a7
23 changed files with 329 additions and 157 deletions
|
@ -41,6 +41,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace App\Tests\Services\LabelSystem;
|
||||
|
||||
use App\Entity\LabelSystem\BarcodeType;
|
||||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\LabelSystem\BarcodeGenerator;
|
||||
|
@ -65,13 +66,13 @@ final class BarcodeGeneratorTest extends WebTestCase
|
|||
$part->setName('Test');
|
||||
|
||||
//Test that all barcodes types are supported
|
||||
foreach (LabelOptions::BARCODE_TYPES as $type) {
|
||||
foreach (BarcodeType::cases() as $type) {
|
||||
$options = new LabelOptions();
|
||||
$options->setBarcodeType($type);
|
||||
$content = $this->services->generateSVG($options, $part);
|
||||
|
||||
//When type is none, service must return null.
|
||||
if ('none' === $type) {
|
||||
if (BarcodeType::NONE === $type) {
|
||||
$this->assertNull($content);
|
||||
} else {
|
||||
$this->assertIsString($content);
|
||||
|
@ -85,13 +86,13 @@ final class BarcodeGeneratorTest extends WebTestCase
|
|||
$part->setName('Test');
|
||||
|
||||
//Test that all barcodes types are supported
|
||||
foreach (LabelOptions::BARCODE_TYPES as $type) {
|
||||
foreach (BarcodeType::cases() as $type) {
|
||||
$options = new LabelOptions();
|
||||
$options->setBarcodeType($type);
|
||||
$svg = $this->services->generateSVG($options, $part);
|
||||
|
||||
//When type is none, service must return null.
|
||||
if ('none' === $type) {
|
||||
if (BarcodeType::NONE === $type) {
|
||||
$this->assertNull($svg);
|
||||
} else {
|
||||
$this->assertStringContainsStringIgnoringCase('SVG', $svg);
|
||||
|
|
|
@ -43,6 +43,7 @@ namespace App\Tests\Services\LabelSystem;
|
|||
|
||||
use App\Entity\Base\AbstractDBElement;
|
||||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
|
@ -62,19 +63,19 @@ class LabelGeneratorTest extends WebTestCase
|
|||
$this->service = self::getContainer()->get(LabelGenerator::class);
|
||||
}
|
||||
|
||||
public function supportsDataProvider(): array
|
||||
public static function supportsDataProvider(): array
|
||||
{
|
||||
return [
|
||||
['part', Part::class],
|
||||
['part_lot', PartLot::class],
|
||||
['storelocation', Storelocation::class],
|
||||
[LabelSupportedElement::PART, Part::class],
|
||||
[LabelSupportedElement::PART_LOT, PartLot::class],
|
||||
[LabelSupportedElement::STORELOCATION, Storelocation::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider supportsDataProvider
|
||||
*/
|
||||
public function testSupports(string $type, string $class): void
|
||||
public function testSupports(LabelSupportedElement $type, string $class): void
|
||||
{
|
||||
$options = new LabelOptions();
|
||||
$options->setSupportedElement($type);
|
||||
|
@ -102,7 +103,7 @@ class LabelGeneratorTest extends WebTestCase
|
|||
$part = new Part();
|
||||
$options = new LabelOptions();
|
||||
$options->setLines('Test');
|
||||
$options->setSupportedElement('part');
|
||||
$options->setSupportedElement(LabelSupportedElement::PART);
|
||||
|
||||
//Test for a single passed element:
|
||||
$pdf = $this->service->generateLabel($options, $part);
|
||||
|
|
|
@ -42,6 +42,8 @@ declare(strict_types=1);
|
|||
namespace App\Tests\Services\LabelSystem;
|
||||
|
||||
use App\Entity\LabelSystem\LabelOptions;
|
||||
use App\Entity\LabelSystem\LabelProcessMode;
|
||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\Storelocation;
|
||||
|
@ -104,9 +106,9 @@ class SandboxedTwigProviderTest extends WebTestCase
|
|||
public function testTwigFeatures(string $twig): void
|
||||
{
|
||||
$options = new LabelOptions();
|
||||
$options->setSupportedElement('part');
|
||||
$options->setSupportedElement(LabelSupportedElement::PART);
|
||||
$options->setLines($twig);
|
||||
$options->setLinesMode('twig');
|
||||
$options->setProcessMode(LabelProcessMode::TWIG);
|
||||
|
||||
$twig = $this->service->getTwig($options);
|
||||
$str = $twig->render('lines', [
|
||||
|
@ -126,9 +128,9 @@ class SandboxedTwigProviderTest extends WebTestCase
|
|||
$this->expectException(SecurityError::class);
|
||||
|
||||
$options = new LabelOptions();
|
||||
$options->setSupportedElement('part');
|
||||
$options->setSupportedElement(LabelSupportedElement::PART);
|
||||
$options->setLines($twig);
|
||||
$options->setLinesMode('twig');
|
||||
$options->setProcessMode(LabelProcessMode::TWIG);
|
||||
|
||||
$twig = $this->service->getTwig($options);
|
||||
$str = $twig->render('lines', [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue