Merge branch 'master' into settings-bundle

This commit is contained in:
Jan Böhmer 2025-06-15 18:39:49 +02:00
commit 442457f11b
131 changed files with 12759 additions and 6750 deletions

View file

@ -91,7 +91,7 @@ class AttachmentsEndpointTest extends AuthenticatedApiTestCase
//Attachment must be set (not null)
$array = json_decode($response->getContent(), true);
self::assertNotNull($array['media_url']);
self::assertNotNull($array['internal_path']);
//Attachment must be private
self::assertJsonContains([

View file

@ -59,14 +59,15 @@ class AttachmentTest extends TestCase
$this->assertNull($attachment->getAttachmentType());
$this->assertFalse($attachment->isPicture());
$this->assertFalse($attachment->isExternal());
$this->assertFalse($attachment->hasExternal());
$this->assertFalse($attachment->hasInternal());
$this->assertFalse($attachment->isSecure());
$this->assertFalse($attachment->isBuiltIn());
$this->assertFalse($attachment->is3DModel());
$this->assertFalse($attachment->getShowInTable());
$this->assertEmpty($attachment->getPath());
$this->assertEmpty($attachment->getInternalPath());
$this->assertEmpty($attachment->getExternalPath());
$this->assertEmpty($attachment->getName());
$this->assertEmpty($attachment->getURL());
$this->assertEmpty($attachment->getExtension());
$this->assertNull($attachment->getElement());
$this->assertEmpty($attachment->getFilename());
@ -119,82 +120,63 @@ class AttachmentTest extends TestCase
$attachment->setElement($element);
}
public function externalDataProvider(): \Iterator
{
yield ['', false];
yield ['%MEDIA%/foo/bar.txt', false];
yield ['%BASE%/foo/bar.jpg', false];
yield ['%FOOTPRINTS%/foo/bar.jpg', false];
yield ['%FOOTPRINTS3D%/foo/bar.jpg', false];
yield ['%SECURE%/test.txt', false];
yield ['%test%/foo/bar.ghp', true];
yield ['foo%MEDIA%/foo.jpg', true];
yield ['foo%MEDIA%/%BASE%foo.jpg', true];
}
/**
* @dataProvider externalDataProvider
*/
public function testIsExternal($path, $expected): void
public static function extensionDataProvider(): \Iterator
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->assertSame($expected, $attachment->isExternal());
}
public function extensionDataProvider(): \Iterator
{
yield ['%MEDIA%/foo/bar.txt', null, 'txt'];
yield ['%MEDIA%/foo/bar.JPeg', null, 'jpeg'];
yield ['%MEDIA%/foo/bar.JPeg', 'test.txt', 'txt'];
yield ['%MEDIA%/foo/bar', null, ''];
yield ['%MEDIA%/foo.bar', 'bar', ''];
yield ['http://google.de', null, null];
yield ['https://foo.bar', null, null];
yield ['https://foo.bar/test.jpeg', null, null];
yield ['test', null, null];
yield ['test.txt', null, null];
yield ['%MEDIA%/foo/bar.txt', 'http://google.de', null, 'txt'];
yield ['%MEDIA%/foo/bar.JPeg', 'https://foo.bar', null, 'jpeg'];
yield ['%MEDIA%/foo/bar.JPeg', null, 'test.txt', 'txt'];
yield ['%MEDIA%/foo/bar', 'https://foo.bar/test.jpeg', null, ''];
yield ['%MEDIA%/foo.bar', 'test.txt', 'bar', ''];
yield [null, 'http://google.de', null, null];
yield [null, 'https://foo.bar', null, null];
yield [null, ',https://foo.bar/test.jpeg', null, null];
yield [null, 'test', null, null];
yield [null, 'test.txt', null, null];
}
/**
* @dataProvider extensionDataProvider
*/
public function testGetExtension($path, $originalFilename, $expected): void
public function testGetExtension(?string $internal_path, ?string $external_path, ?string $originalFilename, ?string $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'internal_path', $internal_path);
$this->setProtectedProperty($attachment, 'external_path', $external_path);
$this->setProtectedProperty($attachment, 'original_filename', $originalFilename);
$this->assertSame($expected, $attachment->getExtension());
}
public function pictureDataProvider(): \Iterator
public static function pictureDataProvider(): \Iterator
{
yield ['%MEDIA%/foo/bar.txt', false];
yield ['https://test.de/picture.jpeg', true];
yield ['https://test.de/picture.png?test=fdsj&width=34', true];
yield ['https://invalid.invalid/file.txt', false];
yield ['http://infsf.inda/file.zip?test', false];
yield ['https://test.de', true];
yield ['https://invalid.com/invalid/pic', true];
yield ['%MEDIA%/foo/bar.jpeg', true];
yield ['%MEDIA%/foo/bar.webp', true];
yield ['%MEDIA%/foo', false];
yield ['%SECURE%/foo.txt/test', false];
yield [null, '%MEDIA%/foo/bar.txt', false];
yield [null, 'https://test.de/picture.jpeg', true];
yield [null, 'https://test.de/picture.png?test=fdsj&width=34', true];
yield [null, 'https://invalid.invalid/file.txt', false];
yield [null, 'http://infsf.inda/file.zip?test', false];
yield [null, 'https://test.de', true];
yield [null, 'https://invalid.com/invalid/pic', true];
yield ['%MEDIA%/foo/bar.jpeg', 'https://invalid.invalid/file.txt', true];
yield ['%MEDIA%/foo/bar.webp', '', true];
yield ['%MEDIA%/foo', '', false];
yield ['%SECURE%/foo.txt/test', 'https://test.de/picture.jpeg', false];
}
/**
* @dataProvider pictureDataProvider
*/
public function testIsPicture($path, $expected): void
public function testIsPicture(?string $internal_path, ?string $external_path, bool $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'internal_path', $internal_path);
$this->setProtectedProperty($attachment, 'external_path', $external_path);
$this->assertSame($expected, $attachment->isPicture());
}
public function builtinDataProvider(): \Iterator
public static function builtinDataProvider(): \Iterator
{
yield ['', false];
yield [null, false];
yield ['%MEDIA%/foo/bar.txt', false];
yield ['%BASE%/foo/bar.txt', false];
yield ['/', false];
@ -205,14 +187,14 @@ class AttachmentTest extends TestCase
/**
* @dataProvider builtinDataProvider
*/
public function testIsBuiltIn($path, $expected): void
public function testIsBuiltIn(?string $path, $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'internal_path', $path);
$this->assertSame($expected, $attachment->isBuiltIn());
}
public function hostDataProvider(): \Iterator
public static function hostDataProvider(): \Iterator
{
yield ['%MEDIA%/foo/bar.txt', null];
yield ['https://www.google.de/test.txt', 'www.google.de'];
@ -222,55 +204,60 @@ class AttachmentTest extends TestCase
/**
* @dataProvider hostDataProvider
*/
public function testGetHost($path, $expected): void
public function testGetHost(?string $path, ?string $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'external_path', $path);
$this->assertSame($expected, $attachment->getHost());
}
public function filenameProvider(): \Iterator
public static function filenameProvider(): \Iterator
{
yield ['%MEDIA%/foo/bar.txt', null, 'bar.txt'];
yield ['%MEDIA%/foo/bar.JPeg', 'test.txt', 'test.txt'];
yield ['https://www.google.de/test.txt', null, null];
yield ['%MEDIA%/foo/bar.txt', 'https://www.google.de/test.txt', null, 'bar.txt'];
yield ['%MEDIA%/foo/bar.JPeg', 'https://www.google.de/foo.txt', 'test.txt', 'test.txt'];
yield ['', 'https://www.google.de/test.txt', null, null];
yield [null, 'https://www.google.de/test.txt', null, null];
}
/**
* @dataProvider filenameProvider
*/
public function testGetFilename($path, $original_filename, $expected): void
public function testGetFilename(?string $internal_path, ?string $external_path, ?string $original_filename, ?string $expected): void
{
$attachment = new PartAttachment();
$this->setProtectedProperty($attachment, 'path', $path);
$this->setProtectedProperty($attachment, 'internal_path', $internal_path);
$this->setProtectedProperty($attachment, 'external_path', $external_path);
$this->setProtectedProperty($attachment, 'original_filename', $original_filename);
$this->assertSame($expected, $attachment->getFilename());
}
public function testSetURL(): void
public function testSetExternalPath(): void
{
$attachment = new PartAttachment();
//Set URL
$attachment->setURL('https://google.de');
$this->assertSame('https://google.de', $attachment->getURL());
$attachment->setExternalPath('https://google.de');
$this->assertSame('https://google.de', $attachment->getExternalPath());
//Ensure that an empty url does not overwrite the existing one
$attachment->setPath('%MEDIA%/foo/bar.txt');
$attachment->setURL(' ');
$this->assertSame('%MEDIA%/foo/bar.txt', $attachment->getPath());
//Ensure that changing the external path does reset the internal one
$attachment->setInternalPath('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('https://example.de');
$this->assertSame(null, $attachment->getInternalPath());
//Ensure that setting the same value to the external path again doesn't reset the internal one
$attachment->setExternalPath('https://google.de');
$attachment->setInternalPath('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('https://google.de');
$this->assertSame('%MEDIA%/foo/bar.txt', $attachment->getInternalPath());
//Ensure that resetting the external path doesn't reset the internal one
$attachment->setInternalPath('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('');
$this->assertSame('%MEDIA%/foo/bar.txt', $attachment->getInternalPath());
//Ensure that spaces get replaced by %20
$attachment->setURL('https://google.de/test file.txt');
$this->assertSame('https://google.de/test%20file.txt', $attachment->getURL());
}
public function testSetURLForbiddenURL(): void
{
$attachment = new PartAttachment();
$this->expectException(InvalidArgumentException::class);
$attachment->setURL('%MEDIA%/foo/bar.txt');
$attachment->setExternalPath('https://example.de/test file.txt');
$this->assertSame('https://example.de/test%20file.txt', $attachment->getExternalPath());
}
public function testIsURL(): void

View file

@ -67,6 +67,19 @@ class PartParameterTest extends TestCase
yield ['10.23 V (9 V ... 11 V) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
public function formattedValueWithLatexDataProvider(): \Iterator
{
yield ['Text Test', null, null, null, 'V', 'Text Test'];
yield ['10.23 $\mathrm{V}$', null, 10.23, null, 'V', ''];
yield ['10.23 $\mathrm{V}$ [Text]', null, 10.23, null, 'V', 'Text'];
yield ['max. 10.23 $\mathrm{V}$', null, null, 10.23, 'V', ''];
yield ['max. 10.23 [Text]', null, null, 10.23, '', 'Text'];
yield ['min. 10.23 $\mathrm{V}$', 10.23, null, null, 'V', ''];
yield ['10.23 $\mathrm{V}$ ... 11 $\mathrm{V}$', 10.23, null, 11, 'V', ''];
yield ['10.23 $\mathrm{V}$ (9 $\mathrm{V}$ ... 11 $\mathrm{V}$)', 9, 10.23, 11, 'V', ''];
yield ['10.23 $\mathrm{V}$ (9 $\mathrm{V}$ ... 11 $\mathrm{V}$) [Test]', 9, 10.23, 11, 'V', 'Test'];
}
/**
* @dataProvider valueWithUnitDataProvider
*/
@ -117,4 +130,22 @@ class PartParameterTest extends TestCase
$param->setValueText($text);
$this->assertSame($expected, $param->getFormattedValue());
}
/**
* @dataProvider formattedValueWithLatexDataProvider
*
* @param float $min
* @param float $typical
* @param float $max
*/
public function testGetFormattedValueWithLatex(string $expected, ?float $min, ?float $typical, ?float $max, string $unit, string $text): void
{
$param = new PartParameter();
$param->setUnit($unit);
$param->setValueMin($min);
$param->setValueTypical($typical);
$param->setValueMax($max);
$param->setValueText($text);
$this->assertSame($expected, $param->getFormattedValue(true));
}
}

View file

@ -70,6 +70,16 @@ class ParameterDTOTest extends TestCase
'test'
];
//Test ranges
yield [
new ParameterDTO('test', value_min: 1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),
'test',
'1.0..2.0',
'kg',
'm',
'test'
];
//Test ranges with tilde
yield [
new ParameterDTO('test', value_min: -1.0, value_max: 2.0, unit: 'kg', symbol: 'm', group: 'test'),

View file

@ -30,6 +30,7 @@ use App\Services\InfoProviderSystem\DTOs\PartDetailDTO;
use App\Services\InfoProviderSystem\DTOs\PriceDTO;
use App\Services\InfoProviderSystem\DTOs\PurchaseInfoDTO;
use App\Services\InfoProviderSystem\DTOtoEntityConverter;
use PhpParser\Node\Param;
use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
@ -150,9 +151,9 @@ class DTOtoEntityConverterTest extends WebTestCase
public function testConvertPart(): void
{
$parameters = [new ParameterDTO('Test', 'Test')];
$datasheets = [new FileDTO('https://invalid.invalid/file.pdf'), new FileDTO('https://invalid.invalid/file.pdf', name: 'TestFile')];
$images = [new FileDTO('https://invalid.invalid/image.png'), new FileDTO('https://invalid.invalid/image2.png', name: 'TestImage2'), new FileDTO('https://invalid.invalid/image2.png')];
$parameters = [new ParameterDTO('Test', 'Test'), new ParameterDTO('Duplicate', 'Test'), new ParameterDTO('Test', 'test', group: "Other"), new ParameterDTO('Duplicate', 'ds')];
$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')];
$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")];
$shopping_infos = [new PurchaseInfoDTO('TestDistributor', 'TestOrderNumber', [new PriceDTO(1, "10.0", 'EUR')])];
$dto = new PartDetailDTO(
@ -182,15 +183,31 @@ class DTOtoEntityConverterTest extends WebTestCase
$this->assertCount(count($parameters), $entity->getParameters());
$this->assertCount(count($shopping_infos), $entity->getOrderdetails());
//Test that duplicate parameters get renamed:
$this->assertSame('Test', $entity->getParameters()[0]->getName());
$this->assertSame('Duplicate', $entity->getParameters()[1]->getName());
$this->assertSame('Test', $entity->getParameters()[2]->getName());
$this->assertSame('Duplicate (2)', $entity->getParameters()[3]->getName());
//Datasheets and images are stored as attachments and the duplicates, should be filtered out
$this->assertCount(3, $entity->getAttachments());
$this->assertCount(6, $entity->getAttachments());
//The attachments should have the name of the named duplicate file
$image1 = $entity->getAttachments()[0];
$this->assertSame('Main image', $image1->getName());
$image1 = $entity->getAttachments()[1];
$this->assertSame('TestImage2', $image1->getName());
$datasheet = $entity->getAttachments()[2];
$this->assertSame('Duplicate', $datasheet->getName());
$datasheet = $entity->getAttachments()[3];
$this->assertSame('TestFile', $datasheet->getName());
$datasheet = $entity->getAttachments()[4];
$this->assertSame('Duplicate (2)', $datasheet->getName());
$datasheet = $entity->getAttachments()[5];
$this->assertSame('Duplicate (3)', $datasheet->getName());
}
}