Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
102 lines
4.2 KiB
PHP
102 lines
4.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\ThemeOptionBook;
|
|
use LIT\MCP\Integrations\Divi\Design\ThemeOptionDiff;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
final class ThemeOptionDiffTest extends TestCase
|
|
{
|
|
public function testNoChangeIsAnEmptyDiffEvenWhenTheOrderOfTheInputDiffers(): void
|
|
{
|
|
$book = ThemeOptionBook::fromDivi(ThemeOptionBookTest::stored());
|
|
$same = ThemeOptionBook::fromDivi(array_reverse(ThemeOptionBookTest::stored(), true));
|
|
|
|
self::assertSame([], ThemeOptionDiff::between($book, $same));
|
|
self::assertSame([], ThemeOptionDiff::between(ThemeOptionBook::fromDivi([]), ThemeOptionBook::fromDivi([])));
|
|
}
|
|
|
|
public function testAddedChangedAndResetInTheOrderOfTheKeys(): void
|
|
{
|
|
$before = ThemeOptionBook::fromDivi(ThemeOptionBookTest::stored());
|
|
$after = $before
|
|
->with('content_width', 1200)
|
|
->with('body_font_size', 18)
|
|
->with('body_font', 'Roboto')
|
|
->without('body_header_style');
|
|
|
|
self::assertSame([
|
|
['key' => 'body_font', 'label' => 'Fließtext-Schrift', 'action' => 'changed',
|
|
'before' => 'Lato', 'after' => 'Roboto'],
|
|
['key' => 'body_font_size', 'label' => 'Fließtext-Schriftgröße', 'action' => 'changed',
|
|
'before' => 16, 'after' => 18],
|
|
['key' => 'body_header_style', 'label' => 'Überschrift-Schriftstil', 'action' => 'reset',
|
|
'before' => 'uppercase', 'after' => null],
|
|
['key' => 'content_width', 'label' => 'Inhaltsbreite', 'action' => 'added',
|
|
'before' => null, 'after' => 1200],
|
|
], ThemeOptionDiff::between($before, $after));
|
|
}
|
|
|
|
public function testFalseIsAValueOfItsOwn(): void
|
|
{
|
|
$unset = ThemeOptionBook::fromDivi([]);
|
|
$default = ThemeOptionBook::fromDivi(['heading_font' => false]);
|
|
$font = ThemeOptionBook::fromDivi(['heading_font' => 'Lato']);
|
|
|
|
self::assertSame(
|
|
[['key' => 'heading_font', 'label' => 'Überschrift-Schrift', 'action' => 'added',
|
|
'before' => null, 'after' => false]],
|
|
ThemeOptionDiff::between($unset, $default)
|
|
);
|
|
self::assertSame(
|
|
[['key' => 'heading_font', 'label' => 'Überschrift-Schrift', 'action' => 'changed',
|
|
'before' => false, 'after' => 'Lato']],
|
|
ThemeOptionDiff::between($default, $font)
|
|
);
|
|
self::assertSame(
|
|
[['key' => 'heading_font', 'label' => 'Überschrift-Schrift', 'action' => 'reset',
|
|
'before' => false, 'after' => null]],
|
|
ThemeOptionDiff::between($default, $unset)
|
|
);
|
|
}
|
|
|
|
public function testATypeChangeCountsAsAChange(): void
|
|
{
|
|
$int = ThemeOptionBook::fromDivi(['gutter_width' => 1, 'body_header_height' => 1]);
|
|
$text = ThemeOptionBook::fromDivi(['gutter_width' => '1', 'body_header_height' => 1.0]);
|
|
|
|
self::assertSame(
|
|
[
|
|
['key' => 'body_header_height', 'label' => 'Überschrift-Zeilenhöhe', 'action' => 'changed',
|
|
'before' => 1, 'after' => 1.0],
|
|
['key' => 'gutter_width', 'label' => 'Spaltenabstand', 'action' => 'changed',
|
|
'before' => 1, 'after' => '1'],
|
|
],
|
|
ThemeOptionDiff::between($int, $text)
|
|
);
|
|
}
|
|
|
|
public function testSummaryCountsPerAction(): void
|
|
{
|
|
$before = ThemeOptionBook::fromDivi(ThemeOptionBookTest::stored());
|
|
$after = $before->with('content_width', 1200)->with('body_font_size', 18)->with('body_font', 'Roboto')
|
|
->without('body_header_style');
|
|
|
|
self::assertSame(
|
|
'Theme-Optionen: 1 gesetzt, 2 geändert, 1 zurückgesetzt.',
|
|
ThemeOptionDiff::summary(ThemeOptionDiff::between($before, $after))
|
|
);
|
|
self::assertSame(
|
|
'Theme-Optionen: 1 gesetzt.',
|
|
ThemeOptionDiff::summary(ThemeOptionDiff::between(
|
|
ThemeOptionBook::fromDivi([]),
|
|
ThemeOptionBook::fromDivi(['content_width' => 1200])
|
|
))
|
|
);
|
|
self::assertSame('Theme-Optionen: keine Änderung.', ThemeOptionDiff::summary([]));
|
|
}
|
|
}
|