refactor(compat): Prüfbausteine nach src/Compatibility, Matrix und ManifestCheck generisch
Requirement, Call, ConstantRequirement, Mirror, Problem, FeatureStatus, CompatibilityMatrix, Manifest, ManifestCheck sowie Fingerprints und LineDiff liegen jetzt im divi-freien Kern. Neu: GlobalRequirement, CompatibilityMatrix::fromProblems(), ManifestCheck-Option signatures, DiviManifestCheck::create() und DiviAreas. Divi-Verhalten unverändert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
9beb55e228
commit
b511ef6348
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Compatibility;
|
||||
|
||||
use LIT\MCP\Compatibility\Call;
|
||||
use LIT\MCP\Compatibility\ConstantRequirement;
|
||||
use LIT\MCP\Compatibility\GlobalRequirement;
|
||||
use LIT\MCP\Compatibility\Manifest;
|
||||
use LIT\MCP\Compatibility\Mirror;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviAreas;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
final class ManifestTest extends TestCase
|
||||
{
|
||||
public function testCallsKnowTheirClassMemberAndLabel(): void
|
||||
{
|
||||
$function = new Call('et_pb_is_allowed', 1);
|
||||
$method = new Call('ET\Builder\Packages\GlobalData\GlobalData::get_global_colors', 0);
|
||||
|
||||
self::assertNull($function->className());
|
||||
self::assertSame('et_pb_is_allowed', $function->member());
|
||||
self::assertSame('et_pb_is_allowed()', $function->label());
|
||||
self::assertSame('ET\Builder\Packages\GlobalData\GlobalData', $method->className());
|
||||
self::assertSame('get_global_colors', $method->member());
|
||||
self::assertSame('GlobalData::get_global_colors()', $method->label());
|
||||
self::assertSame('ET_Core_PageResource', (new Call('\ET_Core_PageResource::remove_static_resources', 3))->className());
|
||||
}
|
||||
|
||||
public function testMirrorLabel(): void
|
||||
{
|
||||
$function = new Mirror('tb-api-save', 'includes/api.php', 'et_theme_builder_api_save', null, 'Vorlagenliste');
|
||||
$method = new Mirror('vb-flags', 'x.php', 'update', 'SyncToServerController', 'Kennzeichen');
|
||||
|
||||
self::assertSame('et_theme_builder_api_save()', $function->label());
|
||||
self::assertSame('SyncToServerController::update()', $method->label());
|
||||
}
|
||||
|
||||
public function testNamesListEveryDeclaredDiviName(): void
|
||||
{
|
||||
$manifest = new Manifest(
|
||||
DiviAreas::LIBRARY,
|
||||
calls: [new Call('et_pb_is_allowed', 1), new Call('ET\Builder\GlobalLayout::is_global_layout_template', 1)],
|
||||
constants: ['ET_BUILDER_PRODUCT_VERSION'],
|
||||
postTypes: ['et_pb_layout'],
|
||||
taxonomies: ['scope'],
|
||||
blockTypes: ['divi/global-layout'],
|
||||
keys: ['_et_pb_module_type']
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
['et_pb_is_allowed', 'ET\Builder\GlobalLayout', 'ET_BUILDER_PRODUCT_VERSION', 'et_pb_layout', 'scope',
|
||||
'_et_pb_module_type'],
|
||||
$manifest->names()
|
||||
);
|
||||
self::assertSame('Bibliothek', $manifest->area);
|
||||
}
|
||||
|
||||
public function testPlainConstantNamesBecomeRequirementsWithALabel(): void
|
||||
{
|
||||
$manifest = new Manifest(
|
||||
DiviAreas::CATALOG,
|
||||
constants: ['ET_BUILDER_PRODUCT_VERSION', new ConstantRequirement('ET_OTHER', [DiviFeature::Roles])]
|
||||
);
|
||||
|
||||
self::assertSame(
|
||||
['ET_BUILDER_PRODUCT_VERSION', 'ET_OTHER'],
|
||||
array_map(static fn (ConstantRequirement $constant): string => $constant->name, $manifest->constants)
|
||||
);
|
||||
self::assertSame('Konstante ET_OTHER', $manifest->constants[1]->label());
|
||||
self::assertSame([], $manifest->constants[0]->features());
|
||||
self::assertSame([DiviFeature::Roles], $manifest->constants[1]->features());
|
||||
self::assertSame(['ET_BUILDER_PRODUCT_VERSION', 'ET_OTHER'], $manifest->names());
|
||||
}
|
||||
|
||||
public function testRequirementsAreCallsConstantsAndMirrorsInThatOrder(): void
|
||||
{
|
||||
$call = new Call('et_pb_is_allowed', 1);
|
||||
$mirror = new Mirror('m', 'a.php', 'a', null, 'Terme');
|
||||
$manifest = new Manifest(DiviAreas::LIBRARY, calls: [$call], constants: ['ET_X'], mirrors: [$mirror]);
|
||||
|
||||
$requirements = $manifest->requirements();
|
||||
|
||||
self::assertCount(3, $requirements);
|
||||
self::assertSame($call, $requirements[0]);
|
||||
self::assertSame('Konstante ET_X', $requirements[1]->label());
|
||||
self::assertSame($mirror, $requirements[2]);
|
||||
}
|
||||
|
||||
public function testFeaturesOfPrefersTheOwnFeaturesOverTheManifestDefault(): void
|
||||
{
|
||||
$own = new Call('et_a', null, [DiviFeature::PageWrite, DiviFeature::ThemeBuilderWrite]);
|
||||
$inherited = new Call('et_b');
|
||||
$mirror = new Mirror('m', 'a.php', 'a', null, 'x', [DiviFeature::LibraryWrite]);
|
||||
$manifest = new Manifest(
|
||||
DiviAreas::PAGES,
|
||||
calls: [$own, $inherited],
|
||||
constants: ['ET_X'],
|
||||
mirrors: [$mirror],
|
||||
features: [DiviFeature::PageRead]
|
||||
);
|
||||
|
||||
self::assertSame([DiviFeature::PageWrite, DiviFeature::ThemeBuilderWrite], $manifest->featuresOf($own));
|
||||
self::assertSame([DiviFeature::PageRead], $manifest->featuresOf($inherited));
|
||||
self::assertSame([DiviFeature::PageRead], $manifest->featuresOf($manifest->constants[0]));
|
||||
self::assertSame([DiviFeature::LibraryWrite], $manifest->featuresOf($mirror));
|
||||
}
|
||||
|
||||
public function testWithoutAnyFeaturesAnEntryHasNone(): void
|
||||
{
|
||||
$call = new Call('et_a');
|
||||
|
||||
self::assertSame([], (new Manifest(DiviAreas::PAGES, calls: [$call]))->featuresOf($call));
|
||||
}
|
||||
|
||||
public function testGlobalsAreRequirementsAndNames(): void
|
||||
{
|
||||
$manifest = new Manifest(DiviAreas::PAGES, globals: [new GlobalRequirement('wp_cache_clear_cache')]);
|
||||
|
||||
self::assertSame('wp_cache_clear_cache', $manifest->names()[0]);
|
||||
self::assertSame('Globale Variable wp_cache_clear_cache', $manifest->requirements()[0]->label());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user