refactor: Kern ohne Divi – Ports BuilderDetector, MediaUsageSource, EnvironmentComponent und ausgeschlossene Post-Typen im ContentSchema; Divi-Implementierungen und Verdrahtung über DiviIntegration/Plugin; CoreIndependenceTest
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
abeb4b0eed
commit
06148fb8c1
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\DiviBuilderDetector;
|
||||
use LIT\MCP\Integrations\WordPress\BuilderDetector;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class DiviBuilderDetectorTest extends TestCase
|
||||
{
|
||||
public function testIsABuilderDetectorThatFollowsDiviFiveBeingLoaded(): void
|
||||
{
|
||||
$detector = new DiviBuilderDetector();
|
||||
|
||||
self::assertInstanceOf(BuilderDetector::class, $detector);
|
||||
self::assertFalse($detector->isAvailable(), 'no Divi classes in unit tests');
|
||||
}
|
||||
|
||||
public function testALayoutIsMarkedByDivisBuilderFlag(): void
|
||||
{
|
||||
Functions\when('get_post_meta')->alias(
|
||||
static fn (int $postId, string $key): string => $postId === 7 && $key === '_et_pb_use_builder' ? 'on' : ''
|
||||
);
|
||||
$detector = new DiviBuilderDetector();
|
||||
|
||||
self::assertTrue($detector->usesBuilder(7));
|
||||
self::assertFalse($detector->usesBuilder(8));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Core\EnvironmentComponent;
|
||||
use LIT\MCP\Integrations\Divi\DiviCompatibility;
|
||||
use LIT\MCP\Integrations\Divi\DiviEnvironmentComponent;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use Mockery;
|
||||
|
||||
final class DiviEnvironmentComponentTest extends TestCase
|
||||
{
|
||||
private function theme(string $template, string $version = '5.2.1'): void
|
||||
{
|
||||
$theme = Mockery::mock();
|
||||
$theme->allows('get_template')->andReturn($template);
|
||||
$theme->allows('parent')->andReturn(false);
|
||||
$theme->allows('get')->with('Version')->andReturn($version);
|
||||
Functions\when('wp_get_theme')->justReturn($theme);
|
||||
}
|
||||
|
||||
public function testIsAnEnvironmentComponent(): void
|
||||
{
|
||||
self::assertInstanceOf(EnvironmentComponent::class, new DiviEnvironmentComponent());
|
||||
}
|
||||
|
||||
public function testCarriesTheCompatibilityFindings(): void
|
||||
{
|
||||
$this->theme('Divi');
|
||||
$component = new DiviEnvironmentComponent(
|
||||
new DiviCompatibility(['GlobalLayout' => static fn (): bool => false])
|
||||
);
|
||||
|
||||
$described = $component->describe();
|
||||
|
||||
self::assertSame('divi', $described['id']);
|
||||
self::assertTrue($described['active']);
|
||||
self::assertSame('5.2.1', $described['version']);
|
||||
self::assertSame(['GlobalLayout'], $described['problems']);
|
||||
}
|
||||
|
||||
public function testCarriesTheReleaseStatus(): void
|
||||
{
|
||||
$this->theme('Divi');
|
||||
|
||||
$described = (new DiviEnvironmentComponent(new DiviCompatibility([])))->describe();
|
||||
|
||||
self::assertSame([], $described['problems']);
|
||||
self::assertSame('released', $described['release']['state'] ?? null);
|
||||
}
|
||||
|
||||
public function testIsInactiveWithoutDiviAndHasNoProblemsOrRelease(): void
|
||||
{
|
||||
$this->theme('twentytwentysix', '1.0');
|
||||
|
||||
$described = (new DiviEnvironmentComponent(
|
||||
new DiviCompatibility(['GlobalLayout' => static fn (): bool => false])
|
||||
))->describe();
|
||||
|
||||
self::assertSame(
|
||||
['id' => 'divi', 'active' => false, 'version' => null, 'problems' => [], 'release' => null],
|
||||
$described
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,14 @@ namespace LIT\MCP\Tests\Unit\Integrations\Divi;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Integrations\Core\EnvironmentComponent;
|
||||
use LIT\MCP\Integrations\Divi\DiviBuilderDetector;
|
||||
use LIT\MCP\Integrations\Divi\DiviEnvironmentComponent;
|
||||
use LIT\MCP\Integrations\Divi\DiviIntegration;
|
||||
use LIT\MCP\Integrations\Divi\DiviLogoUsage;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviContentComposer;
|
||||
use LIT\MCP\Integrations\Media\MediaUsageSource;
|
||||
use LIT\MCP\Integrations\WordPress\BuilderDetector;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use LIT\MCP\Tests\Support\FakeChangeLog;
|
||||
use LIT\MCP\Tests\Support\LibraryFixtures;
|
||||
@@ -58,6 +64,43 @@ final class DiviIntegrationTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
/** Spec §3: the ports the core uses (Plugin wires them) are Divi's own implementations. */
|
||||
public function testProvidesThePortsTheCoreUses(): void
|
||||
{
|
||||
$integration = new DiviIntegration(Mockery::mock(ContentSchema::class), FakeChangeLog::forbidden());
|
||||
|
||||
self::assertInstanceOf(BuilderDetector::class, $integration->builderDetector());
|
||||
self::assertInstanceOf(DiviBuilderDetector::class, $integration->builderDetector());
|
||||
$sources = $integration->mediaUsageSources();
|
||||
self::assertCount(1, $sources);
|
||||
self::assertInstanceOf(MediaUsageSource::class, $sources[0]);
|
||||
self::assertInstanceOf(DiviLogoUsage::class, $sources[0]);
|
||||
self::assertInstanceOf(EnvironmentComponent::class, $integration->environmentComponent());
|
||||
self::assertInstanceOf(DiviEnvironmentComponent::class, $integration->environmentComponent());
|
||||
}
|
||||
|
||||
/** The content tools leave the same post types alone as before the schema stopped knowing Divi. */
|
||||
public function testDiviPostTypesAddedToTheSchemaGiveTheFormerExcludedList(): void
|
||||
{
|
||||
self::assertSame(
|
||||
[
|
||||
'attachment', 'nav_menu_item', 'revision', 'wp_block', 'wp_template', 'wp_template_part',
|
||||
'wp_navigation', 'wp_global_styles', 'wp_font_family', 'wp_font_face', 'et_pb_layout',
|
||||
'et_theme_builder', 'et_template', 'et_header_layout', 'et_body_layout', 'et_footer_layout',
|
||||
'et_pb_canvas', '_et_pb_speculation',
|
||||
],
|
||||
array_merge(ContentSchema::EXCLUDED, DiviIntegration::internalPostTypes())
|
||||
);
|
||||
}
|
||||
|
||||
public function testTheSchemaAsksDiviWhetherTheBuilderIsOnForAPostType(): void
|
||||
{
|
||||
Functions\when('et_builder_enabled_for_post_type')->alias(static fn (string $type): bool => $type === 'page');
|
||||
|
||||
self::assertTrue(DiviIntegration::builderEnabledFor('page'));
|
||||
self::assertFalse(DiviIntegration::builderEnabledFor('post'));
|
||||
}
|
||||
|
||||
public function testProvidesTheLibraryGroup(): void
|
||||
{
|
||||
Functions\when('__')->returnArg();
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\DiviLogoUsage;
|
||||
use LIT\MCP\Integrations\Media\MediaUsageSource;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
|
||||
final class DiviLogoUsageTest extends TestCase
|
||||
{
|
||||
private const POSSIBLE_LOGO = [
|
||||
'post_id' => 0,
|
||||
'title' => 'Divi-Logo',
|
||||
'post_type' => 'option',
|
||||
'where' => 'divi_logo',
|
||||
'certainty' => 'möglicherweise',
|
||||
];
|
||||
|
||||
private function stub(string $logo, string $file = '2026/09/foto-scaled.jpg'): void
|
||||
{
|
||||
Functions\when('get_post_meta')->justReturn($file);
|
||||
Functions\when('get_option')->alias(
|
||||
static fn (string $name): mixed => $name === 'et_divi' ? ['divi_logo' => $logo] : false
|
||||
);
|
||||
}
|
||||
|
||||
public function testIsAMediaUsageSource(): void
|
||||
{
|
||||
self::assertInstanceOf(MediaUsageSource::class, new DiviLogoUsage());
|
||||
}
|
||||
|
||||
public function testTheLogoThatIsTheFileIsAPossibleUsage(): void
|
||||
{
|
||||
$this->stub('https://k.de/wp-content/uploads/2026/09/foto.jpg');
|
||||
|
||||
self::assertSame([self::POSSIBLE_LOGO], (new DiviLogoUsage())->usagesOf(33));
|
||||
}
|
||||
|
||||
public function testAGeneratedSizeOfTheFileCountsToo(): void
|
||||
{
|
||||
$this->stub('https://k.de/wp-content/uploads/2026/09/foto-300x200.jpg');
|
||||
|
||||
self::assertSame([self::POSSIBLE_LOGO], (new DiviLogoUsage())->usagesOf(33));
|
||||
}
|
||||
|
||||
public function testAnotherFileIsNoUsage(): void
|
||||
{
|
||||
$this->stub('https://k.de/wp-content/uploads/2026/09/anderes.jpg');
|
||||
|
||||
self::assertSame([], (new DiviLogoUsage())->usagesOf(33));
|
||||
}
|
||||
|
||||
public function testWithoutALogoOrWithoutAFileThereIsNoUsage(): void
|
||||
{
|
||||
$this->stub('');
|
||||
self::assertSame([], (new DiviLogoUsage())->usagesOf(33));
|
||||
|
||||
$this->stub('https://k.de/wp-content/uploads/2026/09/foto.jpg', '');
|
||||
self::assertSame([], (new DiviLogoUsage())->usagesOf(33));
|
||||
|
||||
Functions\when('get_option')->justReturn(false);
|
||||
self::assertSame([], (new DiviLogoUsage())->usagesOf(33));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user