feat: Fundstellen aller Module eines Typs, Standard-Gruppen-Presets in der Fundstellensuche (ModuleUsageQuery)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
1f9b50f1a6
commit
763d765660
@@ -10,6 +10,7 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class PresetUsageMatcherTest extends TestCase
|
||||
{
|
||||
private const TEXT = '<!-- wp:divi/section --><!-- wp:divi/text %s /--><!-- /wp:divi/section -->';
|
||||
private const BUTTON = '<!-- wp:divi/section --><!-- wp:divi/row --><!-- wp:divi/column -->'
|
||||
. '<!-- wp:divi/button %s /--><!-- /wp:divi/column --><!-- /wp:divi/row --><!-- /wp:divi/section -->';
|
||||
|
||||
@@ -62,4 +63,58 @@ final class PresetUsageMatcherTest extends TestCase
|
||||
false
|
||||
));
|
||||
}
|
||||
|
||||
private static function groupsOf(string $module): array
|
||||
{
|
||||
return $module === 'divi/text' ? ['content.decoration.bodyFont' => 'divi/font-body'] : [];
|
||||
}
|
||||
|
||||
public function testDefaultGroupPresetReachesModulesWithTheGroup(): void
|
||||
{
|
||||
$matcher = new PresetUsageMatcher(groupsOf: self::groupsOf(...));
|
||||
$group = new PresetScope('group', 'divi/font-body');
|
||||
$own = '{"groupPreset":{"content.decoration.bodyFont":{"presetId":["%s"],"groupName":"divi/font-body"}}}';
|
||||
|
||||
self::assertTrue($matcher->uses(sprintf(self::TEXT, '{}'), $group, 'gggggggggg', true));
|
||||
self::assertTrue(
|
||||
$matcher->uses(sprintf(self::TEXT, sprintf($own, 'default')), $group, 'gggggggggg', true),
|
||||
'an entry with the default ID is no own preset'
|
||||
);
|
||||
self::assertFalse(
|
||||
$matcher->uses(sprintf(self::TEXT, sprintf($own, 'hhhhhhhhhh')), $group, 'gggggggggg', true),
|
||||
'an own group preset replaces the default'
|
||||
);
|
||||
self::assertFalse(
|
||||
$matcher->uses(self::page('{}'), $group, 'gggggggggg', true),
|
||||
'a button has no font-body group'
|
||||
);
|
||||
self::assertFalse(
|
||||
$matcher->uses(sprintf(self::TEXT, '{}'), new PresetScope('group', 'divi/spacing'), 'gggggggggg', true),
|
||||
'the text module has no spacing group in this fixture'
|
||||
);
|
||||
self::assertFalse(
|
||||
$matcher->uses(sprintf(self::TEXT, '{}'), $group, 'gggggggggg', false),
|
||||
'a preset that is not the default needs an explicit entry'
|
||||
);
|
||||
}
|
||||
|
||||
public function testDefaultGroupPresetIsNotDetectedWithoutGroupsOf(): void
|
||||
{
|
||||
self::assertFalse((new PresetUsageMatcher())->uses(
|
||||
sprintf(self::TEXT, '{}'),
|
||||
new PresetScope('group', 'divi/font-body'),
|
||||
'gggggggggg',
|
||||
true
|
||||
));
|
||||
}
|
||||
|
||||
public function testGlobalInstancesDoNotReachADefaultGroupPreset(): void
|
||||
{
|
||||
$matcher = new PresetUsageMatcher(groupsOf: static fn (string $module): array => [
|
||||
'content.decoration.bodyFont' => 'divi/font-body',
|
||||
]);
|
||||
$instance = '<!-- wp:divi/global-layout {"globalModule":"1058","blockName":"divi/text"} /-->';
|
||||
|
||||
self::assertFalse($matcher->uses($instance, new PresetScope('group', 'divi/font-body'), 'gggggggggg', true));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user