|
30 | 30 | use App\Services\InfoProviderSystem\DTOs\PriceDTO; |
31 | 31 | use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO; |
32 | 32 | use App\Services\InfoProviderSystem\DTOtoEntityConverter; |
| 33 | +use PhpParser\Node\Param; |
33 | 34 | use PHPUnit\Framework\TestCase; |
34 | 35 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
35 | 36 |
|
@@ -150,9 +151,9 @@ public function testConvertFileWithoutName(): void |
150 | 151 |
|
151 | 152 | public function testConvertPart(): void |
152 | 153 | { |
153 | | - $parameters = [new ParameterDTO('Test', 'Test')]; |
154 | | - $datasheets = [new FileDTO('https://invalid.invalid/file.pdf'), new FileDTO('https://invalid.invalid/file.pdf', name: 'TestFile')]; |
155 | | - $images = [new FileDTO('https://invalid.invalid/image.png'), new FileDTO('https://invalid.invalid/image2.png', name: 'TestImage2'), new FileDTO('https://invalid.invalid/image2.png')]; |
| 154 | + $parameters = [new ParameterDTO('Test', 'Test'), new ParameterDTO('Duplicate', 'Test'), new ParameterDTO('Test', 'test', group: "Other"), new ParameterDTO('Duplicate', 'ds')]; |
| 155 | + $datasheets = [new FileDTO('https://invalid.invalid/file.pdf'), new FileDTO('https://invalid.invalid/file.pdf', name: 'TestFile'), new FileDTO('https://invalid.invalid/file2.pdf', name: 'Duplicate'), new FileDTO('https://invalid.invalid/file3.pdf', name: 'Duplicate')]; |
| 156 | + $images = [new FileDTO('https://invalid.invalid/image.png'), new FileDTO('https://invalid.invalid/image2.png', name: 'TestImage2'), new FileDTO('https://invalid.invalid/image3.png', name: "Duplicate")]; |
156 | 157 | $shopping_infos = [new PurchaseInfoDTO('TestDistributor', 'TestOrderNumber', [new PriceDTO(1, "10.0", 'EUR')])]; |
157 | 158 |
|
158 | 159 | $dto = new PartDetailDTO( |
@@ -182,15 +183,31 @@ public function testConvertPart(): void |
182 | 183 | $this->assertCount(count($parameters), $entity->getParameters()); |
183 | 184 | $this->assertCount(count($shopping_infos), $entity->getOrderdetails()); |
184 | 185 |
|
| 186 | + //Test that duplicate parameters get renamed: |
| 187 | + $this->assertSame('Test', $entity->getParameters()[0]->getName()); |
| 188 | + $this->assertSame('Duplicate', $entity->getParameters()[1]->getName()); |
| 189 | + $this->assertSame('Test', $entity->getParameters()[2]->getName()); |
| 190 | + $this->assertSame('Duplicate (2)', $entity->getParameters()[3]->getName()); |
| 191 | + |
185 | 192 | //Datasheets and images are stored as attachments and the duplicates, should be filtered out |
186 | | - $this->assertCount(3, $entity->getAttachments()); |
| 193 | + $this->assertCount(6, $entity->getAttachments()); |
187 | 194 | //The attachments should have the name of the named duplicate file |
188 | 195 | $image1 = $entity->getAttachments()[0]; |
189 | 196 | $this->assertSame('Main image', $image1->getName()); |
190 | 197 |
|
191 | 198 | $image1 = $entity->getAttachments()[1]; |
| 199 | + $this->assertSame('TestImage2', $image1->getName()); |
192 | 200 |
|
193 | 201 | $datasheet = $entity->getAttachments()[2]; |
| 202 | + $this->assertSame('Duplicate', $datasheet->getName()); |
| 203 | + |
| 204 | + $datasheet = $entity->getAttachments()[3]; |
194 | 205 | $this->assertSame('TestFile', $datasheet->getName()); |
| 206 | + |
| 207 | + $datasheet = $entity->getAttachments()[4]; |
| 208 | + $this->assertSame('Duplicate (2)', $datasheet->getName()); |
| 209 | + |
| 210 | + $datasheet = $entity->getAttachments()[5]; |
| 211 | + $this->assertSame('Duplicate (3)', $datasheet->getName()); |
195 | 212 | } |
196 | 213 | } |
0 commit comments