SuperSeller3000/tests/Unit/Domain/Article/AttributeDefinitionTest.php
Simon Kuehn 838b96eb14 feat: required/optional attribute sections in ArticleType form
Promote article_type_attributes join table to ArticleTypeAttribute entity
with a required boolean flag. ArticleType gains virtual form properties
(requiredAttributeDefs / optionalAttributeDefs) reconciled via
applyAttributeAssignments() on persist/update.

Admin form shows two Tom Select multi-selects; a small JS module
(article-type-attr-sync.js) listens for ea.autocomplete.connect events
and keeps the two lists mutually exclusive in real time.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-17 22:43:42 +00:00

67 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Tests\Unit\Domain\Article;
use App\Domain\Article\AttributeDefinition;
use App\Domain\Article\AttributeType;
use PHPUnit\Framework\TestCase;
final class AttributeDefinitionTest extends TestCase
{
public function testConstructorSetsNameAndType(): void
{
$def = new AttributeDefinition('RAM', AttributeType::Select);
self::assertSame('RAM', $def->getName());
self::assertSame(AttributeType::Select, $def->getType());
self::assertNull($def->getUnit());
self::assertNull($def->getOptions());
}
/**
* @dataProvider allAttributeTypes
*/
public function testSetTypeMutatesType(AttributeType $type): void
{
$def = new AttributeDefinition('Field', AttributeType::String);
$def->setType($type);
self::assertSame($type, $def->getType());
}
/** @return array<string, array{AttributeType}> */
public static function allAttributeTypes(): array
{
return array_combine(
array_map(fn (AttributeType $t) => $t->value, AttributeType::cases()),
array_map(fn (AttributeType $t) => [$t], AttributeType::cases()),
);
}
public function testSetNameAndUnit(): void
{
$def = new AttributeDefinition('Weight', AttributeType::Float);
$def->setName('Mass');
$def->setUnit('kg');
self::assertSame('Mass', $def->getName());
self::assertSame('kg', $def->getUnit());
}
public function testSetOptions(): void
{
$def = new AttributeDefinition('Grade', AttributeType::Select);
$def->setOptions(['A', 'B', 'C']);
self::assertSame(['A', 'B', 'C'], $def->getOptions());
}
public function testToStringReturnsName(): void
{
$def = new AttributeDefinition('CPU', AttributeType::String);
self::assertSame('CPU', (string) $def);
}
}