- DiviFixtures: markup(), givenPost(), schema(), designSystem(), catalog(), dynamicContentRegistry(), maliciousRefs() - moved verbatim out of DiviPageLoaderTest, DesignSystemTest, ModuleCatalogTest, DynamicContentMapTest and VariableRefTest (its malicious() provider now returns maliciousRefs()). - ComposeFixture moves to tests/Support. - DiviWriterFixture: modules(), designReader(), composition(), a recording saver(), log() and writer(&$saved, &$failures, unfiltered, loader) for the five tests that wired the Divi write stack by hand. No test cases or assertions changed (1397 / 5834). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
78 lines
3.5 KiB
PHP
78 lines
3.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\DesignSystem;
|
|
use LIT\MCP\Tests\Support\DiviFixtures;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class DesignSystemTest extends TestCase
|
|
{
|
|
public function testReadsColorsVariablesFontsSizesAndPresets(): void
|
|
{
|
|
$design = DiviFixtures::designSystem();
|
|
|
|
self::assertSame(
|
|
['id' => 'gcid-a1b2', 'label' => 'Nachtblau', 'value' => '#0b3d59'],
|
|
$design->colors()[2]
|
|
);
|
|
self::assertCount(3, $design->colors());
|
|
self::assertSame(['heading' => 'Open Sans', 'body' => 'Lato'], $design->fonts());
|
|
self::assertSame(
|
|
[['id' => 'gvid-r1', 'type' => 'numbers', 'label' => 'Radius', 'value' => '8px'],
|
|
['id' => 'gvid-s1', 'type' => 'strings', 'label' => 'Telefon', 'value' => '0221 123']],
|
|
$design->variables()
|
|
);
|
|
self::assertSame('16', $design->sizes()['body_font_size']);
|
|
self::assertSame('30', $design->sizes()['body_header_size']);
|
|
self::assertSame(
|
|
['kind' => 'module', 'module' => 'divi/button', 'id' => 'p-1', 'name' => 'Standard', 'default' => true],
|
|
$design->presets()[0]
|
|
);
|
|
self::assertSame(['p-1' => 'Standard', 'p-2' => 'CTA primär', 'g-1' => 'Fließtext groß'], $design->presetNames());
|
|
}
|
|
|
|
public function testLooksUpByAliasLabelOrId(): void
|
|
{
|
|
$design = DiviFixtures::designSystem();
|
|
|
|
self::assertSame('gcid-primary-color', $design->colorId('primary'));
|
|
self::assertSame('gcid-a1b2', $design->colorId('nachtblau'));
|
|
self::assertSame('gcid-a1b2', $design->colorId('gcid-a1b2'));
|
|
self::assertNull($design->colorId('secondary'));
|
|
self::assertNull($design->colorId('Alt'));
|
|
self::assertSame('gvid-s1', $design->variable('telefon')['id'] ?? null);
|
|
self::assertSame('p-2', $design->modulePresetId('divi/button', 'cta PRIMÄR'));
|
|
self::assertNull($design->modulePresetId('divi/text', 'Standard'));
|
|
self::assertSame(['Standard', 'CTA primär'], $design->modulePresetNames('divi/button'));
|
|
self::assertSame('{{color:primary}}', DesignSystem::colorPlaceholder('gcid-primary-color', 'Primärfarbe'));
|
|
self::assertSame('{{color:Nachtblau}}', DesignSystem::colorPlaceholder('gcid-a1b2', 'Nachtblau'));
|
|
}
|
|
|
|
/** Ruling S13a/S34: a preset name several presets of the module share fails with their ids. */
|
|
public function testAmbiguousPresetNamesFail(): void
|
|
{
|
|
$design = DesignSystem::fromDivi([], [], ['module' => ['divi/button' => ['default' => 'p-1', 'items' => [
|
|
'p-1' => ['id' => 'p-1', 'name' => 'Standard', 'moduleName' => 'divi/button'],
|
|
'p-3' => ['id' => 'p-3', 'name' => 'standard', 'moduleName' => 'divi/button'],
|
|
]]]], []);
|
|
|
|
self::assertSame('p-3', $design->modulePresetId('divi/button', 'p-3'));
|
|
$this->expectException(\InvalidArgumentException::class);
|
|
$this->expectExceptionMessage('p-1, p-3');
|
|
$design->modulePresetId('divi/button', 'STANDARD');
|
|
}
|
|
|
|
public function testToleratesEmptyOrOddInput(): void
|
|
{
|
|
$design = DesignSystem::fromDivi([], ['fonts' => 'x'], ['module' => 'y'], []);
|
|
|
|
self::assertSame([], $design->colors());
|
|
self::assertSame(['heading' => '', 'body' => ''], $design->fonts());
|
|
self::assertSame([], $design->presets());
|
|
self::assertSame('14', $design->sizes()['body_font_size']);
|
|
}
|
|
}
|