fix: GlobalUsages finds every reference Divi renders, fail closed (F1, ruling P23)

Candidates come from one ID/status/type query: content with globalModule,
global_module or a JSON-escaped letter. Their content is read in chunks of
50 and parsed by UsageMatcher: Divi 5 openers are json-decoded (escaped keys
and values, leading zeros, any depth), and Divi 4 global_module attributes
are read in any quoting. An undecodable escaped opener counts as a possible
reference. Beyond 5000 candidates the rest count unread. The guide names
the formats and the wp_block parity. Also fixes the grammar of the
blocked-hidden count.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-27 04:42:46 +02:00
co-authored by Claude Opus 5.5
parent f1937ca6ff
commit fec5d9da7b
7 changed files with 299 additions and 34 deletions
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Library;
use LIT\MCP\Integrations\Divi\Library\UsageMatcher;
use PHPUnit\Framework\TestCase;
/**
* Ruling P23 (re-review F1): every reference Divi renders counts – Divi 5 openers in any JSON
* spelling, Divi 4 shortcodes in any quoting; an escaped opener that cannot be decoded counts as a
* possible reference (fail closed). Escape bytes are built with chr(92), never written inline.
*/
final class UsageMatcherTest extends TestCase
{
private static function u(string $hex): string
{
return chr(92) . 'u' . $hex;
}
/** @return array<string, array{string, bool}> Content => whether it shows entry 123. */
public static function contents(): array
{
$escapedKey = '"' . self::u('0067') . 'lobalModule"';
return [
'divi 5 canonical' => ['<!-- wp:divi/global-layout {"globalModule":"123","blockName":"divi/text"} /-->', true],
'divi 5 leading zeros' => ['<!-- wp:divi/global-layout {"globalModule":"0123","blockName":"divi/text"} /-->', true],
'divi 5 escaped key' => ['<!-- wp:divi/global-layout {' . $escapedKey . ':"123","blockName":"divi/text"} /-->', true],
'divi 5 escaped value' => [
'<!-- wp:divi/global-layout {"globalModule":"' . self::u('0031') . '23","blockName":"divi/text"} /-->',
true,
],
'divi 5 escaped key with leading zeros' => [
'<!-- wp:divi/global-layout {' . $escapedKey . ':"00123"} /-->',
true,
],
'divi 5 another entry' => ['<!-- wp:divi/global-layout {"globalModule":"1234","blockName":"divi/text"} /-->', false],
'divi 5 escaped key, another entry' => ['<!-- wp:divi/global-layout {' . $escapedKey . ':"124"} /-->', false],
'divi 5 id in local attributes' => [
'<!-- wp:divi/global-layout {"globalModule":"5","localAttrs":{"x":{"globalModule":"123"}}} /-->',
true,
],
'divi 4 double quotes' => ['[et_pb_section global_module="123"][/et_pb_section]', true],
'divi 4 single quotes and zeros' => ["[et_pb_text global_module='0123']x[/et_pb_text]", true],
'divi 4 unquoted' => ['[et_pb_row global_module=123 admin_label="x"][/et_pb_row]', true],
'divi 4 typographic quotes' => ['[et_pb_row global_module=' . "\u{201D}" . '123' . "\u{201D}" . '][/et_pb_row]', true],
'divi 4 another entry' => ['[et_pb_section global_module="1230"][/et_pb_section]', false],
'undecodable escaped opener' => [
'<!-- wp:divi/global-layout {' . $escapedKey . ':"123",} /-->',
true,
],
'undecodable escaped opener naming nothing readable' => [
'<!-- wp:divi/text {' . self::u('0067') . 'kaputt} /-->',
true,
],
'escaped markup only' => [
'<!-- wp:divi/text {"content":{"innerContent":{"desktop":{"value":"' . self::u('003c') . 'p'
. self::u('003e') . 'x"}}}} /-->',
false,
],
'plain page' => ['<!-- wp:divi/section --><!-- /wp:divi/section -->', false],
];
}
/** @dataProvider contents */
public function testFindsEveryReferenceDiviRenders(string $content, bool $shows): void
{
self::assertSame($shows, UsageMatcher::shows($content, 123));
}
public function testTheEscapeBytesAreReal(): void
{
self::assertSame(6, strlen(self::u('0067')));
self::assertSame(92, ord(self::u('0067')[0]));
}
}