This commit is contained in:
web-devinition.de 2026-01-13 01:09:39 +06:00 committed by GitHub
commit 30840ac8b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
136 changed files with 23994 additions and 112 deletions

View file

@ -0,0 +1,76 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 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);
namespace App\Tests\API\Endpoints;
use App\Tests\API\Endpoints\CrudEndpointTestCase;
class AssembliesEndpointTest extends CrudEndpointTestCase
{
protected function getBasePath(): string
{
return '/api/assemblies';
}
public function testGetCollection(): void
{
$this->_testGetCollection();
self::assertJsonContains([
'hydra:totalItems' => 7,
]);
}
public function testGetChildrenCollection(): void
{
$this->_testGetChildrenCollection(1);
}
public function testGetItem(): void
{
$this->_testGetItem(1);
$this->_testGetItem(2);
$this->_testGetItem(3);
}
public function testCreateItem(): void
{
$this->_testPostItem([
'name' => 'Test API',
'parent' => '/api/assemblies/1',
]);
}
public function testUpdateItem(): void
{
$this->_testPatchItem(5, [
'name' => 'Updated',
'parent' => '/api/assemblies/2',
]);
}
public function testDeleteItem(): void
{
$this->_testDeleteItem(7);
}
}

View file

@ -0,0 +1,44 @@
<?php
/*
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
*
* Copyright (C) 2019 - 2024 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);
namespace App\Tests\API\Endpoints;
class AssemblyBOMEntriesEndpointTest extends CrudEndpointTestCase
{
protected function getBasePath(): string
{
return '/api/assembly_bom_entries';
}
public function testGetCollection(): void
{
$this->_testGetCollection();
}
public function testGetBomFromAssembly(): void
{
$response = self::createAuthenticatedClient()->request('GET', '/api/assemblies/1/bom');
self::assertResponseIsSuccessful();
}
}

View file

@ -142,6 +142,12 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase
yield ['/project/1/build?n=1'];
yield ['/project/1/import_bom'];
//Assemblies
yield ['/assembly/1/info'];
yield ['/assembly/1/add_parts'];
yield ['/assembly/1/add_parts?parts=1,2'];
yield ['/assembly/1/import_bom'];
//Test info provider system
yield ['/tools/info_providers/providers']; //List all providers
yield ['/tools/info_providers/search']; //Search page

View file

@ -0,0 +1,35 @@
<?php
/**
* 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/>.
*/
declare(strict_types=1);
namespace App\Tests\Controller\AdminPages;
use App\Entity\AssemblySystem\Assembly;
use PHPUnit\Framework\Attributes\Group;
#[Group('slow')]
#[Group('DB')]
class AssemblyController extends AbstractAdminController
{
protected static string $base_path = '/en/assembly';
protected static string $entity_class = Assembly::class;
}

View file

@ -24,6 +24,8 @@ namespace App\Tests\Entity\Attachments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Depends;
use App\Entity\AssemblySystem\Assembly;
use App\Entity\Attachments\AssemblyAttachment;
use App\Entity\Attachments\Attachment;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Attachments\AttachmentTypeAttachment;
@ -83,6 +85,7 @@ class AttachmentTest extends TestCase
yield [CategoryAttachment::class, Category::class];
yield [CurrencyAttachment::class, Currency::class];
yield [ProjectAttachment::class, Project::class];
yield [AssemblyAttachment::class, Assembly::class];
yield [FootprintAttachment::class, Footprint::class];
yield [GroupAttachment::class, Group::class];
yield [ManufacturerAttachment::class, Manufacturer::class];

View file

@ -29,7 +29,7 @@ use App\Entity\ProjectSystem\ProjectBOMEntry;
use App\Services\ImportExportSystem\BOMImporter;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\File\UploadedFile;
class BOMImporterTest extends WebTestCase
{
@ -62,15 +62,17 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$file = $this->createMock(File::class);
$file = $this->createMock(UploadedFile::class);
$file->method('getContent')->willReturn($input);
$file->method('getClientOriginalName')->willReturn('import.kicad_pcb');
$file->method('getClientOriginalExtension')->willReturn('kicad_pcb');
$project = new Project();
$this->assertCount(0, $project->getBOMEntries());
$bom_entries = $this->service->importFileIntoProject($file, $project, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom_entries);
$this->assertCount(4, $bom_entries);
$importerResult = $this->service->importFileIntoProject($file, $project, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $importerResult->getBomEntries());
$this->assertCount(4, $importerResult->getBomEntries());
//Check that the BOM entries are added to the project
$this->assertCount(4, $project->getBOMEntries());
@ -87,7 +89,8 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$bom = $this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$bom = $this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
$this->assertCount(4, $bom);
@ -106,7 +109,8 @@ class BOMImporterTest extends WebTestCase
4;"C6";"CP_Radial_D6.3mm_P2.50mm";1;"47uF";;;
CSV;
$bom = $this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$bom = $this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
$this->assertContainsOnlyInstancesOf(ProjectBOMEntry::class, $bom);
$this->assertCount(4, $bom);
@ -126,7 +130,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->service->stringToBOMEntries($input, ['type' => 'kicad_pcbnew']);
$project = new Project();
$this->service->stringToBOMEntries($project, $input, ['type' => 'kicad_pcbnew']);
}
public function testDetectFields(): void
@ -370,7 +375,8 @@ class BOMImporterTest extends WebTestCase
'Mouser SPN' => 'Mouser SPN'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -413,7 +419,8 @@ class BOMImporterTest extends WebTestCase
'MPN2' => 2
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'field_priorities' => $field_priorities,
@ -451,7 +458,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -483,7 +491,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -512,7 +521,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -541,7 +551,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Required field "Designator" is missing or empty');
$this->service->stringToBOMEntries($input, [
$project = new Project();
$this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -564,7 +575,8 @@ class BOMImporterTest extends WebTestCase
$this->expectException(\UnexpectedValueException::class);
$this->expectExceptionMessage('Mismatch between quantity and component references');
$this->service->stringToBOMEntries($input, [
$project = new Project();
$this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','
@ -585,7 +597,8 @@ class BOMImporterTest extends WebTestCase
'Quantity' => 'Quantity'
];
$bom_entries = $this->service->stringToBOMEntries($input, [
$project = new Project();
$bom_entries = $this->service->stringToBOMEntries($project, $input, [
'type' => 'kicad_schematic',
'field_mapping' => $field_mapping,
'delimiter' => ','

View file

@ -22,6 +22,7 @@ declare(strict_types=1);
*/
namespace App\Tests\Twig;
use App\Entity\AssemblySystem\Assembly;
use App\Entity\Attachments\PartAttachment;
use App\Entity\Parts\PartCustomState;
use App\Entity\ProjectSystem\Project;
@ -61,6 +62,7 @@ class EntityExtensionTest extends WebTestCase
$this->assertSame('manufacturer', $this->service->getEntityType(new Manufacturer()));
$this->assertSame('category', $this->service->getEntityType(new Category()));
$this->assertSame('device', $this->service->getEntityType(new Project()));
$this->assertSame('assembly', $this->service->getEntityType(new Assembly()));
$this->assertSame('attachment', $this->service->getEntityType(new PartAttachment()));
$this->assertSame('supplier', $this->service->getEntityType(new Supplier()));
$this->assertSame('user', $this->service->getEntityType(new User()));