Some checks are pending
CI / test (push) Waiting to run
Consistent brace style, spacing, and method expansion throughout domain, infrastructure, and test files. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
81 lines
2.8 KiB
PHP
81 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Tests\Unit\Infrastructure\Admin;
|
|
|
|
use App\Domain\Article\AttributeDefinition;
|
|
use App\Domain\Article\AttributeType;
|
|
use App\Infrastructure\Http\Controller\Admin\AttributeDefinitionCrudController;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Symfony\Component\Form\Extension\Core\Type\EnumType;
|
|
|
|
final class AttributeDefinitionCrudControllerTest extends TestCase
|
|
{
|
|
private AttributeDefinitionCrudController $controller;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->controller = new AttributeDefinitionCrudController();
|
|
}
|
|
|
|
public function testGetEntityFqcn(): void
|
|
{
|
|
self::assertSame(AttributeDefinition::class, AttributeDefinitionCrudController::getEntityFqcn());
|
|
}
|
|
|
|
public function testCreateEntityReturnsAttributeDefinitionWithDefaults(): void
|
|
{
|
|
$entity = $this->controller->createEntity(AttributeDefinition::class);
|
|
|
|
self::assertInstanceOf(AttributeDefinition::class, $entity);
|
|
self::assertSame('', $entity->getName());
|
|
self::assertSame(AttributeType::String, $entity->getType());
|
|
}
|
|
|
|
public function testConfigureFieldsYieldsExpectedFieldNames(): void
|
|
{
|
|
$fields = iterator_to_array($this->controller->configureFields('new'));
|
|
$names = array_map(static fn ($f) => $f->getAsDto()->getProperty(), $fields);
|
|
|
|
self::assertContains('name', $names);
|
|
self::assertContains('type', $names);
|
|
self::assertContains('unit', $names);
|
|
self::assertContains('options', $names);
|
|
}
|
|
|
|
public function testTypeFieldOnIndexUsesChoiceFieldWithFormatValue(): void
|
|
{
|
|
$fields = iterator_to_array($this->controller->configureFields('index'));
|
|
$typeField = null;
|
|
foreach ($fields as $field) {
|
|
if ('type' === $field->getAsDto()->getProperty()) {
|
|
$typeField = $field;
|
|
break;
|
|
}
|
|
}
|
|
|
|
self::assertNotNull($typeField);
|
|
|
|
// Must have formatValue so choice.html.twig can render it safely
|
|
$formatValue = $typeField->getAsDto()->getFormatValueCallable();
|
|
self::assertNotNull($formatValue, 'formatValue must be set so index page can render the enum');
|
|
self::assertSame('select', $formatValue(AttributeType::Select, null));
|
|
self::assertSame('string', $formatValue(AttributeType::String, null));
|
|
}
|
|
|
|
public function testTypeFieldOnFormUsesEnumType(): void
|
|
{
|
|
$fields = iterator_to_array($this->controller->configureFields('new'));
|
|
$typeField = null;
|
|
foreach ($fields as $field) {
|
|
if ('type' === $field->getAsDto()->getProperty()) {
|
|
$typeField = $field;
|
|
break;
|
|
}
|
|
}
|
|
|
|
self::assertNotNull($typeField);
|
|
self::assertSame(EnumType::class, $typeField->getAsDto()->getFormType());
|
|
}
|
|
}
|