mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2026-05-21 10:51:38 +00:00
Merge branch 'master' into feature/kicad-enhancements
This commit is contained in:
commit
6ab75488b4
56 changed files with 7142 additions and 2997 deletions
|
|
@ -279,4 +279,32 @@ final class AttachmentTest extends TestCase
|
|||
$reflection_property->setAccessible(true);
|
||||
$reflection_property->setValue($object, $value);
|
||||
}
|
||||
|
||||
public function testIsLocalHTMLFile(): void
|
||||
{
|
||||
$attachment = new PartAttachment();
|
||||
|
||||
$attachment->setExternalPath('https://google.de');
|
||||
$this->assertFalse($attachment->isLocalHTMLFile());
|
||||
|
||||
$attachment->setExternalPath('https://google.de/test.html');
|
||||
$this->assertFalse($attachment->isLocalHTMLFile());
|
||||
|
||||
$attachment->setInternalPath('%MEDIA%/test.html');
|
||||
$this->assertTrue($attachment->isLocalHTMLFile());
|
||||
|
||||
$attachment->setInternalPath('%MEDIA%/test.htm');
|
||||
$this->assertTrue($attachment->isLocalHTMLFile());
|
||||
|
||||
$attachment->setInternalPath('%MEDIA%/test.txt');
|
||||
$this->assertFalse($attachment->isLocalHTMLFile());
|
||||
|
||||
//It works however, if the file is stored as txt, and the internal filename ends with .html
|
||||
$attachment->setInternalPath('%MEDIA%/test.txt');
|
||||
$this->setProtectedProperty($attachment, 'original_filename', 'test.html');
|
||||
$this->assertTrue($attachment->isLocalHTMLFile());
|
||||
|
||||
$this->setProtectedProperty($attachment, 'original_filename', 'test.htm');
|
||||
$this->assertTrue($attachment->isLocalHTMLFile());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,85 +0,0 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeRedirector;
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeSourceType;
|
||||
use App\Services\LabelSystem\BarcodeScanner\LocalBarcodeScanResult;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
final class BarcodeRedirectorTest extends KernelTestCase
|
||||
{
|
||||
private ?BarcodeRedirector $service = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(BarcodeRedirector::class);
|
||||
}
|
||||
|
||||
public static function urlDataProvider(): \Iterator
|
||||
{
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL), '/en/part/1'];
|
||||
//Part lot redirects to Part info page (Part lot 1 is associated with part 3)
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL), '/en/part/3?highlightLot=1'];
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL), '/en/store_location/1/parts'];
|
||||
}
|
||||
|
||||
#[DataProvider('urlDataProvider')]
|
||||
#[Group('DB')]
|
||||
public function testGetRedirectURL(LocalBarcodeScanResult $scanResult, string $url): void
|
||||
{
|
||||
$this->assertSame($url, $this->service->getRedirectURL($scanResult));
|
||||
}
|
||||
|
||||
public function testGetRedirectEntityNotFount(): void
|
||||
{
|
||||
$this->expectException(EntityNotFoundException::class);
|
||||
//If we encounter an invalid lot, we must throw an exception
|
||||
$this->service->getRedirectURL(new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT,
|
||||
12_345_678, BarcodeSourceType::INTERNAL));
|
||||
}
|
||||
}
|
||||
|
|
@ -49,6 +49,7 @@ use App\Services\LabelSystem\BarcodeScanner\BarcodeSourceType;
|
|||
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
|
||||
use App\Services\LabelSystem\BarcodeScanner\LocalBarcodeScanResult;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
use App\Services\LabelSystem\BarcodeScanner\LCSCBarcodeScanResult;
|
||||
|
||||
final class BarcodeScanHelperTest extends WebTestCase
|
||||
{
|
||||
|
|
@ -124,6 +125,14 @@ final class BarcodeScanHelperTest extends WebTestCase
|
|||
]);
|
||||
|
||||
yield [$eigp114Result, "[)>\x1E06\x1DP596-777A1-ND\x1D1PXAF4444\x1DQ3\x1D10D1452\x1D1TBF1103\x1D4LUS\x1E\x04"];
|
||||
|
||||
$lcscInput = '{pc:C138033,pm:RC0402FR-071ML,qty:10}';
|
||||
$lcscResult = new LCSCBarcodeScanResult(
|
||||
['pc' => 'C138033', 'pm' => 'RC0402FR-071ML', 'qty' => '10'],
|
||||
$lcscInput
|
||||
);
|
||||
|
||||
yield [$lcscResult, $lcscInput];
|
||||
}
|
||||
|
||||
public static function invalidDataProvider(): \Iterator
|
||||
|
|
@ -153,4 +162,33 @@ final class BarcodeScanHelperTest extends WebTestCase
|
|||
$this->expectException(\InvalidArgumentException::class);
|
||||
$this->service->scanBarcodeContent($input);
|
||||
}
|
||||
|
||||
public function testAutoDetectLcscBarcode(): void
|
||||
{
|
||||
$input = '{pbn:PB1,on:ON1,pc:C138033,pm:RC0402FR-071ML,qty:10}';
|
||||
|
||||
$result = $this->service->scanBarcodeContent($input);
|
||||
|
||||
$this->assertInstanceOf(LCSCBarcodeScanResult::class, $result);
|
||||
$this->assertSame('C138033', $result->lcscCode);
|
||||
$this->assertSame('RC0402FR-071ML', $result->mpn);
|
||||
}
|
||||
|
||||
public function testLcscExplicitTypeParses(): void
|
||||
{
|
||||
$input = '{pc:C138033,pm:RC0402FR-071ML,qty:10}';
|
||||
|
||||
$result = $this->service->scanBarcodeContent($input, BarcodeSourceType::LCSC);
|
||||
|
||||
$this->assertInstanceOf(LCSCBarcodeScanResult::class, $result);
|
||||
$this->assertSame('C138033', $result->lcscCode);
|
||||
$this->assertSame('RC0402FR-071ML', $result->mpn);
|
||||
}
|
||||
|
||||
public function testLcscExplicitTypeRejectsNonLcsc(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
$this->service->scanBarcodeContent('not-an-lcsc', BarcodeSourceType::LCSC);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,181 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2022 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2020 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Entity\Parts\PartLot;
|
||||
use App\Entity\Parts\StorageLocation;
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanResultHandler;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\Attributes\Group;
|
||||
use App\Entity\LabelSystem\LabelSupportedElement;
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeSourceType;
|
||||
use App\Services\LabelSystem\BarcodeScanner\LocalBarcodeScanResult;
|
||||
use Doctrine\ORM\EntityNotFoundException;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
use App\Services\LabelSystem\BarcodeScanner\EIGP114BarcodeScanResult;
|
||||
use App\Services\LabelSystem\BarcodeScanner\LCSCBarcodeScanResult;
|
||||
use App\Services\LabelSystem\BarcodeScanner\BarcodeScanResultInterface;
|
||||
use InvalidArgumentException;
|
||||
|
||||
|
||||
final class BarcodeScanResultHandlerTest extends KernelTestCase
|
||||
{
|
||||
private ?BarcodeScanResultHandler $service = null;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::getContainer()->get(BarcodeScanResultHandler::class);
|
||||
}
|
||||
|
||||
public static function urlDataProvider(): \Iterator
|
||||
{
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL), '/en/part/1'];
|
||||
//Part lot redirects to Part info page (Part lot 1 is associated with part 3)
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL), '/en/part/3?highlightLot=1'];
|
||||
yield [new LocalBarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL), '/en/store_location/1/parts'];
|
||||
}
|
||||
|
||||
#[DataProvider('urlDataProvider')]
|
||||
#[Group('DB')]
|
||||
public function testGetRedirectURL(LocalBarcodeScanResult $scanResult, string $url): void
|
||||
{
|
||||
$this->assertSame($url, $this->service->getInfoURL($scanResult));
|
||||
}
|
||||
|
||||
public function testGetRedirectEntityNotFound(): void
|
||||
{
|
||||
//If we encounter an invalid lot, we must get an null result
|
||||
$url = $this->service->getInfoURL(new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT,
|
||||
12_345_678, BarcodeSourceType::INTERNAL));
|
||||
|
||||
$this->assertNull($url);
|
||||
}
|
||||
|
||||
public function testGetRedirectURLReturnsNullOnUnknownScanType(): void
|
||||
{
|
||||
$unknown = new class implements BarcodeScanResultInterface {
|
||||
public function getDecodedForInfoMode(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
$this->assertNull($this->service->getInfoURL($unknown));
|
||||
}
|
||||
|
||||
public function testEIGPBarcodeResolvePartOrNullReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$scan = new EIGP114BarcodeScanResult([]);
|
||||
|
||||
$this->assertNull($this->service->resolvePart($scan));
|
||||
$this->assertNull($this->service->getInfoURL($scan));
|
||||
}
|
||||
|
||||
public function testLCSCBarcodeResolvePartOrNullReturnsNullWhenNotFound(): void
|
||||
{
|
||||
$scan = new LCSCBarcodeScanResult(
|
||||
fields: ['pc' => 'C0000000', 'pm' => ''],
|
||||
rawInput: '{pc:C0000000,pm:}'
|
||||
);
|
||||
|
||||
$this->assertNull($this->service->resolvePart($scan));
|
||||
$this->assertNull($this->service->getInfoURL($scan));
|
||||
}
|
||||
|
||||
public function testResolveEntityReturnNullOnUnknownScanType(): void
|
||||
{
|
||||
$unknown = new class implements BarcodeScanResultInterface {
|
||||
public function getDecodedForInfoMode(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
$this->assertNull($this->service->resolvePart($unknown));
|
||||
}
|
||||
|
||||
public function testResolveEntity(): void
|
||||
{
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL);
|
||||
$part = $this->service->resolveEntity($scan);
|
||||
|
||||
$this->assertSame(1, $part->getId());
|
||||
$this->assertInstanceOf(Part::class, $part);
|
||||
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL);
|
||||
$entity = $this->service->resolveEntity($scan);
|
||||
$this->assertSame(1, $entity->getId());
|
||||
$this->assertInstanceOf(PartLot::class, $entity);
|
||||
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL);
|
||||
$entity = $this->service->resolveEntity($scan);
|
||||
$this->assertSame(1, $entity->getId());
|
||||
$this->assertInstanceOf(StorageLocation::class, $entity);
|
||||
}
|
||||
|
||||
public function testResolvePart(): void
|
||||
{
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::PART, 1, BarcodeSourceType::INTERNAL);
|
||||
$part = $this->service->resolvePart($scan);
|
||||
|
||||
$this->assertSame(1, $part->getId());
|
||||
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::PART_LOT, 1, BarcodeSourceType::INTERNAL);
|
||||
$part = $this->service->resolvePart($scan);
|
||||
$this->assertSame(3, $part->getId());
|
||||
|
||||
$scan = new LocalBarcodeScanResult(LabelSupportedElement::STORELOCATION, 1, BarcodeSourceType::INTERNAL);
|
||||
$part = $this->service->resolvePart($scan);
|
||||
$this->assertNull($part); //Store location does not resolve to a part
|
||||
}
|
||||
|
||||
public function testGetCreateInfos(): void
|
||||
{
|
||||
$lcscScan = LCSCBarcodeScanResult::parse('{pbn:PB1,on:ON1,pc:C138033,pm:RC0402FR-071ML,qty:10}');
|
||||
$infos = $this->service->getCreateInfos($lcscScan);
|
||||
|
||||
$this->assertSame('lcsc', $infos['providerKey']);
|
||||
$this->assertSame('C138033', $infos['providerId']);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2026 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\LabelSystem\BarcodeScanner;
|
||||
|
||||
use App\Services\LabelSystem\BarcodeScanner\LCSCBarcodeScanResult;
|
||||
use InvalidArgumentException;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class LCSCBarcodeScanResultTest extends TestCase
|
||||
{
|
||||
public function testIsLCSCBarcode(): void
|
||||
{
|
||||
$this->assertFalse(LCSCBarcodeScanResult::isLCSCBarcode('invalid'));
|
||||
$this->assertFalse(LCSCBarcodeScanResult::isLCSCBarcode('LCSC-12345'));
|
||||
$this->assertFalse(LCSCBarcodeScanResult::isLCSCBarcode(''));
|
||||
|
||||
$this->assertTrue(LCSCBarcodeScanResult::isLCSCBarcode('{pbn:PB1,on:ON1,pc:C138033,pm:RC0402FR-071ML,qty:10}'));
|
||||
$this->assertTrue(LCSCBarcodeScanResult::isLCSCBarcode('{pbn:PICK2506270148,on:GB2506270877,pc:C22437266,pm:IA0509S-2W,qty:3,mc:,cc:1,pdi:164234874,hp:null,wc:ZH}'));
|
||||
}
|
||||
|
||||
public function testConstruct(): void
|
||||
{
|
||||
$raw = '{pbn:PB1,on:ON1,pc:C138033,pm:RC0402FR-071ML,qty:10}';
|
||||
$fields = ['pbn' => 'PB1', 'on' => 'ON1', 'pc' => 'C138033', 'pm' => 'RC0402FR-071ML', 'qty' => '10'];
|
||||
$scan = new LCSCBarcodeScanResult($fields, $raw);
|
||||
//Splitting up should work and assign the correct values to the properties:
|
||||
$this->assertSame('RC0402FR-071ML', $scan->mpn);
|
||||
$this->assertSame('C138033', $scan->lcscCode);
|
||||
|
||||
//Fields and raw input should be preserved
|
||||
$this->assertSame($fields, $scan->fields);
|
||||
$this->assertSame($raw, $scan->rawInput);
|
||||
}
|
||||
|
||||
public function testLCSCParseInvalidFormatThrows(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
LCSCBarcodeScanResult::parse('not-an-lcsc-barcode');
|
||||
}
|
||||
|
||||
public function testParse(): void
|
||||
{
|
||||
$scan = LCSCBarcodeScanResult::parse('{pbn:PICK2506270148,on:GB2506270877,pc:C22437266,pm:IA0509S-2W,qty:3,mc:,cc:1,pdi:164234874,hp:null,wc:ZH}');
|
||||
|
||||
$this->assertSame('IA0509S-2W', $scan->mpn);
|
||||
$this->assertSame('C22437266', $scan->lcscCode);
|
||||
$this->assertSame('PICK2506270148', $scan->pickBatchNumber);
|
||||
$this->assertSame('GB2506270877', $scan->orderNumber);
|
||||
$this->assertSame(3, $scan->quantity);
|
||||
$this->assertSame('1', $scan->countryChannel);
|
||||
$this->assertSame('164234874', $scan->pdi);
|
||||
$this->assertSame('null', $scan->hp);
|
||||
$this->assertSame('ZH', $scan->warehouseCode);
|
||||
}
|
||||
|
||||
public function testLCSCParseExtractsFields(): void
|
||||
{
|
||||
$scan = LCSCBarcodeScanResult::parse('{pbn:PB1,on:ON1,pc:C138033,pm:RC0402FR-071ML,qty:10}');
|
||||
|
||||
$this->assertSame('RC0402FR-071ML', $scan->mpn);
|
||||
$this->assertSame('C138033', $scan->lcscCode);
|
||||
|
||||
$decoded = $scan->getDecodedForInfoMode();
|
||||
$this->assertSame('LCSC', $decoded['Barcode type']);
|
||||
$this->assertSame('RC0402FR-071ML', $decoded['MPN (pm)']);
|
||||
$this->assertSame('C138033', $decoded['LCSC code (pc)']);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue