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>
78 lines
2.8 KiB
PHP
78 lines
2.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use LIT\MCP\Integrations\Divi\Design\CustomCssArea;
|
|
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
|
use LIT\MCP\Tests\Support\FakeCustomCssStore;
|
|
use PHPUnit\Framework\TestCase;
|
|
use RuntimeException;
|
|
|
|
final class CustomCssAreaTest extends TestCase
|
|
{
|
|
public function testNamesTheAreaAndTheDiviFeatureItNeeds(): void
|
|
{
|
|
$area = new CustomCssArea(new FakeCustomCssStore());
|
|
|
|
self::assertSame('custom_css', $area->name());
|
|
self::assertSame('Eigenes CSS', $area->label());
|
|
self::assertSame(DiviFeature::ThemeOptionWrite, $area->feature());
|
|
}
|
|
|
|
public function testRawIsTheStoredTextWithItsTheme(): void
|
|
{
|
|
$area = new CustomCssArea(new FakeCustomCssStore('.x{}', 'Child'));
|
|
|
|
self::assertSame(['stylesheet' => 'Child', 'css' => '.x{}'], $area->raw());
|
|
}
|
|
|
|
public function testTheRevCoversTextAndTheme(): void
|
|
{
|
|
$area = new CustomCssArea(new FakeCustomCssStore());
|
|
$rev = $area->rev(['stylesheet' => 'Divi', 'css' => '.a{}']);
|
|
|
|
self::assertSame($rev, $area->rev(['stylesheet' => 'Divi', 'css' => '.a{}']));
|
|
self::assertNotSame($rev, $area->rev(['stylesheet' => 'Divi', 'css' => '.b{}']));
|
|
self::assertNotSame($rev, $area->rev(['stylesheet' => 'Child', 'css' => '.a{}']), 'a theme switch is a change');
|
|
}
|
|
|
|
public function testWriteReplacesTheTextAndReturnsWhatWasReadBack(): void
|
|
{
|
|
$store = new FakeCustomCssStore('.old{}');
|
|
$area = new CustomCssArea($store);
|
|
|
|
$back = $area->write(['stylesheet' => 'Divi', 'css' => '.new{}'], false);
|
|
|
|
self::assertSame(['.new{}'], $store->writes);
|
|
self::assertSame(['stylesheet' => 'Divi', 'css' => '.new{}'], $back);
|
|
}
|
|
|
|
public function testRestoreWritesTheSnapshotTextBack(): void
|
|
{
|
|
$store = new FakeCustomCssStore('.changed{}');
|
|
|
|
$back = (new CustomCssArea($store))->restore(['stylesheet' => 'Divi', 'css' => '.old{}']);
|
|
|
|
self::assertSame('.old{}', $back['css']);
|
|
self::assertSame(['.old{}'], $store->writes);
|
|
}
|
|
|
|
public function testAFailingWriteThrows(): void
|
|
{
|
|
$this->expectException(RuntimeException::class);
|
|
|
|
(new CustomCssArea(new FakeCustomCssStore(refuse: true)))->write(['css' => '.a{}'], false);
|
|
}
|
|
|
|
public function testVerifyInsistsOnTheExactText(): void
|
|
{
|
|
$area = new CustomCssArea(new FakeCustomCssStore());
|
|
|
|
self::assertTrue($area->verify(['css' => '.a{}'], ['stylesheet' => 'Divi', 'css' => '.a{}']));
|
|
self::assertFalse($area->verify(['css' => '.a>b{}'], ['css' => '.a>b{}']), 'a stripped or escaped text is no success');
|
|
self::assertSame([], $area->differences(['css' => 'a'], ['css' => 'b']));
|
|
}
|
|
}
|