Files
WP-LIT-MCP/tests/Unit/Integrations/Divi/Compose/ValueKindTest.php
T
janniclas.loosenandClaude Opus 5.5 570c1e6142 refactor: ValueKind enum instead of kind string literals (L1)
enum ValueKind: string { Html, Code, Url, Text } with strictness() and
tightens(self $routed) (the S33a rule formerly AttrWriter/ValueCleaner::tightens
over STRICTNESS). ValueCleaner::clean() takes ?ValueKind, kindOf()/kind()/
unknownKind() return it, the sanitizer match is exhaustive over the four cases;
the "Feldart" message prints ->value, so its text is unchanged. ShortformWriter
drops the identity map CLEAN_KIND for ValueKind::tryFrom($spec['kind']) ??
ValueKind::Text; Composer and ShortformWriter pass ValueKind::Text/Url.
The installed PHPCompatibility sniffs do not know enums: two sniffs are disabled
in ValueKind.php only, with the reason.
Tests: ValueCleanerTest passes/asserts ValueKind cases instead of strings;
+ValueKindTest (full tightens matrix, case values).

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
2026-09-26 18:13:23 +02:00

38 lines
1.2 KiB
PHP
Raw 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\Compose;
use LIT\MCP\Integrations\Divi\Compose\ValueKind;
use PHPUnit\Framework\TestCase;
/** Ruling S33a: an override may only tighten – code < html < text; url only to url. */
final class ValueKindTest extends TestCase
{
public function testTightensMatrix(): void
{
$allowed = [
'code' => ['code'],
'html' => ['code', 'html'],
'text' => ['code', 'html', 'text'],
'url' => ['url'],
];
foreach (ValueKind::cases() as $override) {
foreach (ValueKind::cases() as $routed) {
self::assertSame(
in_array($routed->value, $allowed[$override->value], true),
$override->tightens($routed),
$override->value . ' over ' . $routed->value
);
}
}
}
public function testValuesAreTheCuratedKindNames(): void
{
self::assertSame(['html', 'code', 'url', 'text'], array_map(static fn (ValueKind $kind): string => $kind->value, ValueKind::cases()));
self::assertNull(ValueKind::tryFrom('richtext'));
}
}