Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
105 lines
4.5 KiB
PHP
105 lines
4.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\VariableBook;
|
|
use LIT\MCP\Integrations\Divi\Design\VariableDiff;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class VariableDiffTest extends TestCase
|
|
{
|
|
public function testNoChangeIsAnEmptyDiffEvenWhenOnlyLastUpdatedDiffers(): void
|
|
{
|
|
$book = VariableBook::fromDivi(VariableBookTest::stored());
|
|
$touched = $book->with('numbers', 'gvid-f6yq6mayfy', [
|
|
'label' => 'Eckenradius', 'value' => '8px', 'order' => '1', 'lastUpdated' => '2030-01-01T00:00:00.000Z',
|
|
]);
|
|
|
|
self::assertSame([], VariableDiff::between($book, VariableBook::fromDivi(VariableBookTest::stored())));
|
|
self::assertSame([], VariableDiff::between($book, $touched));
|
|
}
|
|
|
|
public function testAddedChangedArchivedAndActivated(): void
|
|
{
|
|
$before = VariableBook::fromDivi(VariableBookTest::stored());
|
|
$after = $before
|
|
->with('fonts', 'gvid-new0000001', ['label' => 'Neu', 'value' => 'Lato', 'order' => '2'])
|
|
->with('numbers', 'gvid-f6yq6mayfy', ['label' => 'Radius', 'value' => '12px', 'order' => '1'])
|
|
->with('numbers', 'gvid-5dec72fwsc', ['label' => 'Abstand Karte', 'value' => '2rem', 'order' => '2',
|
|
'status' => 'archived'])
|
|
->with('numbers', 'gvid-old0000001', ['label' => 'Alt', 'value' => '1px', 'order' => '3']);
|
|
|
|
self::assertSame([
|
|
['type' => 'fonts', 'id' => 'gvid-new0000001', 'name' => 'Neu', 'action' => 'added'],
|
|
['type' => 'numbers', 'id' => 'gvid-5dec72fwsc', 'name' => 'Abstand Karte', 'action' => 'archived'],
|
|
['type' => 'numbers', 'id' => 'gvid-f6yq6mayfy', 'name' => 'Radius', 'action' => 'changed',
|
|
'fields' => ['label', 'value']],
|
|
['type' => 'numbers', 'id' => 'gvid-old0000001', 'name' => 'Alt', 'action' => 'activated'],
|
|
], VariableDiff::between($before, $after));
|
|
}
|
|
|
|
public function testArchivingClearsTheOrderWithoutAFieldEntryButLabelAndValueChangesShow(): void
|
|
{
|
|
$before = VariableBook::fromDivi(VariableBookTest::stored());
|
|
$archived = $before->with('numbers', 'gvid-5dec72fwsc', [
|
|
'label' => 'Abstand Karte', 'value' => '2rem', 'order' => '', 'status' => 'archived',
|
|
]);
|
|
$archivedAndRenamed = $before->with('numbers', 'gvid-5dec72fwsc', [
|
|
'label' => 'Abstand', 'value' => '2rem', 'order' => '', 'status' => 'archived',
|
|
]);
|
|
|
|
self::assertSame(
|
|
[['type' => 'numbers', 'id' => 'gvid-5dec72fwsc', 'name' => 'Abstand Karte', 'action' => 'archived']],
|
|
VariableDiff::between($before, $archived)
|
|
);
|
|
self::assertSame(
|
|
[['type' => 'numbers', 'id' => 'gvid-5dec72fwsc', 'name' => 'Abstand', 'action' => 'archived',
|
|
'fields' => ['label']]],
|
|
VariableDiff::between($before, $archivedAndRenamed)
|
|
);
|
|
}
|
|
|
|
public function testReorderIsAChangeOfTheOrder(): void
|
|
{
|
|
$before = VariableBook::fromDivi(VariableBookTest::stored());
|
|
$after = $before->with('numbers', 'gvid-5dec72fwsc', [
|
|
'label' => 'Abstand Karte', 'value' => '2rem', 'order' => '1',
|
|
]);
|
|
|
|
self::assertSame(
|
|
[['type' => 'numbers', 'id' => 'gvid-5dec72fwsc', 'name' => 'Abstand Karte', 'action' => 'changed',
|
|
'fields' => ['order']]],
|
|
VariableDiff::between($before, $after)
|
|
);
|
|
}
|
|
|
|
public function testGradientsAreComparedLikeEveryOtherType(): void
|
|
{
|
|
$before = VariableBook::fromDivi(VariableBookTest::stored());
|
|
$after = $before->with('gradients', 'gvid-grad000001', [
|
|
'label' => 'Verlauf', 'value' => 'linear-gradient(blue, red)', 'order' => '1',
|
|
]);
|
|
|
|
self::assertSame(
|
|
[['type' => 'gradients', 'id' => 'gvid-grad000001', 'name' => 'Verlauf', 'action' => 'changed',
|
|
'fields' => ['value']]],
|
|
VariableDiff::between($before, $after)
|
|
);
|
|
}
|
|
|
|
public function testSummaryCountsTheActions(): void
|
|
{
|
|
self::assertSame(
|
|
'Variablen: 1 angelegt, 1 geändert, 1 archiviert.',
|
|
VariableDiff::summary([['action' => 'added'], ['action' => 'changed'], ['action' => 'archived']])
|
|
);
|
|
self::assertSame(
|
|
'Variablen: 2 geändert, 1 aktiviert.',
|
|
VariableDiff::summary([['action' => 'activated'], ['action' => 'changed'], ['action' => 'changed']])
|
|
);
|
|
self::assertSame('Variablen: keine Änderung.', VariableDiff::summary([]));
|
|
}
|
|
}
|