Files

63 lines
2.6 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
use LIT\MCP\Integrations\Divi\Design\PresetBook;
use LIT\MCP\Integrations\Divi\Design\PresetDiff;
use LIT\MCP\Integrations\Divi\Design\PresetScope;
use PHPUnit\Framework\TestCase;
final class PresetDiffTest extends TestCase
{
public function testNoChangeIsAnEmptyDiff(): void
{
$book = PresetBook::fromDivi(PresetBookTest::stored());
self::assertSame([], PresetDiff::between($book, PresetBook::fromDivi(PresetBookTest::stored())));
}
public function testAddedChangedRemovedAndDefaults(): void
{
$before = PresetBook::fromDivi(PresetBookTest::stored());
$button = new PresetScope('module', 'divi/button');
$text = new PresetScope('module', 'divi/text');
$changed = $before->items($button)['aaaaaaaaaa'];
$changed['attrs'] = ['button' => ['x' => 2]];
$changed['updated'] = 99;
$changed['styleAttrs'] = ['ignored' => true];
$after = $before
->with($button, $changed)
->with($button, ['id' => 'eeeeeeeeee', 'name' => 'Neu', 'attrs' => []])
->withDefault($button, 'eeeeeeeeee')
->without($button, 'bbbbbbbbbb')
->withDefault($text, '');
self::assertSame([
['kind' => 'module', 'scope' => 'divi/button', 'id' => 'aaaaaaaaaa', 'name' => 'CTA primär',
'action' => 'changed', 'fields' => ['attrs']],
['kind' => 'module', 'scope' => 'divi/button', 'id' => 'bbbbbbbbbb', 'name' => 'Doppelt',
'action' => 'removed'],
['kind' => 'module', 'scope' => 'divi/button', 'id' => 'eeeeeeeeee', 'name' => 'Neu', 'action' => 'added'],
['kind' => 'module', 'scope' => 'divi/button', 'id' => 'eeeeeeeeee', 'name' => 'Neu',
'action' => 'default_set'],
['kind' => 'module', 'scope' => 'divi/text', 'id' => 'dddddddddd', 'name' => 'Fließtext',
'action' => 'default_cleared'],
], PresetDiff::between($before, $after));
}
public function testSummaryCountsTheActions(): void
{
self::assertSame(
'Presets: 1 angelegt, 1 geändert, 1 gelöscht, Standard 1× gesetzt, 1× entfernt.',
PresetDiff::summary([
['action' => 'added'], ['action' => 'changed'], ['action' => 'removed'],
['action' => 'default_set'], ['action' => 'default_cleared'],
])
);
self::assertSame('Presets: 2 angelegt.', PresetDiff::summary([['action' => 'added'], ['action' => 'added']]));
self::assertSame('Presets: keine Änderung.', PresetDiff::summary([]));
}
}