Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
116 lines
4.8 KiB
PHP
116 lines
4.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Release;
|
|
|
|
use LIT\MCP\Integrations\Divi\Release\Call;
|
|
use LIT\MCP\Integrations\Divi\Release\ConstantRequirement;
|
|
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
|
use LIT\MCP\Integrations\Divi\Release\Manifest;
|
|
use LIT\MCP\Integrations\Divi\Release\Mirror;
|
|
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(
|
|
Manifest::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(
|
|
Manifest::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(Manifest::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(
|
|
Manifest::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(Manifest::PAGES, calls: [$call]))->featuresOf($call));
|
|
}
|
|
}
|