test: ReferenceUsageQueryTest prüft Parser und Baumdurchlauf ohne Klartext-ID

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-19 14:05:46 +02:00
co-authored by Claude Sonnet 5.5
parent 653169a133
commit e269fcb1f8
@@ -12,8 +12,8 @@ use Mockery;
final class ReferenceUsageQueryTest extends TestCase final class ReferenceUsageQueryTest extends TestCase
{ {
/** A color reference as post_content holds it: quotes JSON-escaped (formats §2). */ /** A color reference as post_content holds it: quotes JSON-escaped (formats §2). */
private const COLOR_REF = '$variable({"type":"color","value":{"name":' private const COLOR_REF = '$variable({\u0022type\u0022:\u0022color\u0022,\u0022value\u0022:{\u0022name\u0022:'
. '"gcid-holz000001","settings":{}}})$'; . '\u0022gcid-holz000001\u0022,\u0022settings\u0022:{}}})$';
public function testCandidatesContainAnIdAnEscapedHyphenOrAnEscapedLetter(): void public function testCandidatesContainAnIdAnEscapedHyphenOrAnEscapedLetter(): void
{ {
@@ -58,10 +58,15 @@ final class ReferenceUsageQueryTest extends TestCase
{ {
$query = new ReferenceUsageQuery(['gcid-holz000001']); $query = new ReferenceUsageQuery(['gcid-holz000001']);
self::assertTrue($query->matches('<!-- wp:divi/text {"x":"gcid-holz000001"} /-->')); self::assertTrue($query->matches('<!-- wp:divi/text {"x":"gcid\u002dholz000001"} /-->'));
self::assertTrue($query->matches('<!-- wp:divi/section {"globalModule":"12"} -->' self::assertTrue($query->matches('<!-- wp:divi/section {"globalModule":"12"} -->'
. '<!-- wp:divi/text {"x":"gcid-holz000001"} /--><!-- /wp:divi/section -->')); . '<!-- wp:divi/text {"x":"gcid\u002dholz000001"} /--><!-- /wp:divi/section -->'));
self::assertFalse($query->matches('<!-- wp:divi/text {"x":"gcid-anders0001"} /-->')); self::assertFalse($query->matches('<!-- wp:divi/text {"x":"gcid\u002danders0001"} /-->'));
// Escaped letter, nested two levels deep inside a global module: only decoded attributes reveal the ID.
$nested = '<!-- wp:divi/section {"globalModule":"12"} --><!-- wp:divi/row --><!-- wp:divi/text '
. '{"x":"\u0067cid-holz000001"} /--><!-- /wp:divi/row --><!-- /wp:divi/section -->';
self::assertStringNotContainsString('gcid-holz000001', $nested);
self::assertTrue($query->matches($nested));
} }
public function testUnreadableMarkupAndDivi4ContentCount(): void public function testUnreadableMarkupAndDivi4ContentCount(): void
@@ -69,7 +74,8 @@ final class ReferenceUsageQueryTest extends TestCase
$query = new ReferenceUsageQuery(['gcid-holz000001']); $query = new ReferenceUsageQuery(['gcid-holz000001']);
self::assertTrue($query->matches('<!-- wp:divi/section --><!-- wp:divi/text {"x":1} /-->'), 'never closed'); self::assertTrue($query->matches('<!-- wp:divi/section --><!-- wp:divi/text {"x":1} /-->'), 'never closed');
self::assertTrue($query->matches('<!-- wp:divi/text {"x":"gcid-holz000001",} /-->'), 'attrs no JSON'); self::assertTrue($query->matches('<!-- wp:divi/text {"x":"gcid\u002dholz000001",} /-->'), 'attrs no JSON');
self::assertTrue($query->matches('<!-- wp:divi/text {"x":"\u0067cid-holz000001",} /-->'), 'no JSON, no raw ID');
self::assertTrue($query->matches('[et_pb_text background_color="gcid-holz000001"]x[/et_pb_text]'), 'Divi 4'); self::assertTrue($query->matches('[et_pb_text background_color="gcid-holz000001"]x[/et_pb_text]'), 'Divi 4');
} }