feat(css): globales CSS bearbeiten (lit/divi-custom-css-get und -update)
WordPress „Zusätzliches CSS“ (in Divi „Eigenes CSS“) über die Design-Pipeline: Probelauf mit Zeilen-Diff, design_rev, Bestätigung, Snapshot, Rollback und Wiederherstellen (Bereich custom_css). Der Guard lehnt </style, <script, expression(, javascript: und neue @import ab und warnt bei fremden Hosts; nur Neues zählt, Bestehendes blockiert keine Änderung. Erfordert edit_css und die Divi-Rolle Theme-Anpassung. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
96fa58188b
commit
ac333a164c
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
||||
|
||||
use LIT\MCP\Integrations\Divi\Design\CustomCssDiff;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class CustomCssDiffTest extends TestCase
|
||||
{
|
||||
public function testNamesRemovedAndAddedLines(): void
|
||||
{
|
||||
$rows = CustomCssDiff::between(".a { color: red; }\n.b { margin: 0; }", ".a { color: red; }\n.c { margin: 1px; }");
|
||||
|
||||
self::assertSame([
|
||||
['action' => 'removed', 'line' => '.b { margin: 0; }'],
|
||||
['action' => 'added', 'line' => '.c { margin: 1px; }'],
|
||||
], $rows);
|
||||
}
|
||||
|
||||
public function testEqualTextsHaveNoDiff(): void
|
||||
{
|
||||
self::assertSame([], CustomCssDiff::between(".a{}\n.b{}", ".a{}\n.b{}"));
|
||||
self::assertSame([], CustomCssDiff::between('', ''));
|
||||
}
|
||||
|
||||
public function testTheNewlineEndingTheLastLineIsNoLineOfItsOwn(): void
|
||||
{
|
||||
self::assertSame([['action' => 'added', 'line' => '.b{}']], CustomCssDiff::between(".a{}\n", ".a{}\n.b{}"));
|
||||
self::assertSame('changed', CustomCssDiff::between(".a{}", ".a{}\n")[0]['action']);
|
||||
}
|
||||
|
||||
public function testRepeatedLinesCountAsOften(): void
|
||||
{
|
||||
$rows = CustomCssDiff::between("x\nx", "x\nx\nx");
|
||||
|
||||
self::assertSame([['action' => 'added', 'line' => 'x']], $rows);
|
||||
}
|
||||
|
||||
public function testAChangeWithoutAnyDifferingLineIsStillShown(): void
|
||||
{
|
||||
self::assertSame('changed', CustomCssDiff::between("a\nb", "b\na")[0]['action']);
|
||||
self::assertSame('changed', CustomCssDiff::between("a\r\nb", "a\nb")[0]['action']);
|
||||
}
|
||||
|
||||
public function testCutsLongLinesAndLongDiffs(): void
|
||||
{
|
||||
$long = CustomCssDiff::between('', str_repeat('x', 300))[0]['line'];
|
||||
$rows = CustomCssDiff::between('', implode("\n", array_map(static fn (int $i): string => "l$i", range(1, 150))));
|
||||
|
||||
self::assertSame(201, mb_strlen($long));
|
||||
self::assertCount(101, $rows);
|
||||
self::assertSame(['action' => 'more', 'line' => '… und 50 weitere Zeilen'], $rows[100]);
|
||||
}
|
||||
|
||||
public function testSummaryCountsLinesAndBytes(): void
|
||||
{
|
||||
self::assertSame(
|
||||
'Eigenes CSS: 1 Zeilen hinzugefügt, 1 entfernt (3 → 3 Bytes).',
|
||||
CustomCssDiff::summary("a\nb", "a\nc")
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user