configurable csv/xlsx export templates (#5531)

This commit is contained in:
Kevin Papst
2025-06-11 13:06:33 +02:00
committed by GitHub
parent 46129c7ab9
commit 05aaa1950a
83 changed files with 2632 additions and 412 deletions

View File

@@ -0,0 +1,92 @@
<?php
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace App\Tests\Validator\Constraints;
use App\Validator\Constraints\ExportRenderer;
use App\Validator\Constraints\ExportRendererValidator;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
/**
* @covers \App\Validator\Constraints\ExportRenderer
* @covers \App\Validator\Constraints\ExportRendererValidator
* @extends ConstraintValidatorTestCase<ExportRendererValidator>
*/
class ExportRendererValidatorTest extends ConstraintValidatorTestCase
{
protected function createValidator(): ExportRendererValidator
{
return new ExportRendererValidator();
}
public static function getValidColors(): iterable
{
yield ['csv'];
yield ['xlsx'];
yield [null];
}
public function testConstraintIsInvalid(): void
{
$this->expectException(UnexpectedTypeException::class);
$this->validator->validate('#000', new NotBlank());
}
/**
* @dataProvider getValidColors
*/
public function testConstraintWithValidColor(?string $color): void
{
$constraint = new ExportRenderer();
$this->validator->validate($color, $constraint);
$this->assertNoViolation();
}
public static function getInvalidColors(): iterable
{
yield ['CSV'];
yield ['XLSX'];
yield ['PDF'];
yield ['HTML'];
yield ['fff000'];
yield ['000aaa'];
yield ['fffaaa'];
yield ['#f'];
yield ['#ff'];
yield ['#ffdd'];
yield ['#ffddd'];
yield ['#ffddddd'];
yield [new \stdClass(), 'object'];
yield [[], 'array'];
}
/**
* @dataProvider getInvalidColors
*/
public function testValidationError(mixed $color, ?string $parameterType = null): void
{
$constraint = new ExportRenderer();
$this->validator->validate($color, $constraint);
if (\is_string($color)) {
$expectedFormat = '"' . $color . '"';
} else {
$expectedFormat = $parameterType ?? '';
}
$this->buildViolation('Unknown exporter type.')
->setParameter('{{ value }}', $expectedFormat)
->setCode(ExportRenderer::UNKNOWN_TYPE)
->assertRaised();
}
}