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:
Jan-Niclas Loosen
2026-10-18 21:49:28 +02:00
co-authored by Claude Sonnet 5.5
parent abeb4b0eed
commit 06148fb8c1
33 changed files with 952 additions and 154 deletions
@@ -6,6 +6,7 @@ namespace LIT\MCP\Tests\Unit\Integrations\Media;
use Brain\Monkey\Functions;
use LIT\MCP\Integrations\Media\MediaUsageFinder;
use LIT\MCP\Integrations\Media\MediaUsageSource;
use LIT\MCP\Tests\Unit\TestCase;
use Mockery;
use Mockery\MockInterface;
@@ -21,6 +22,7 @@ final class MediaUsageFinderTest extends TestCase
* @param list<object> $fields
* @param array<string, mixed> $options Option name => value.
* @param array<string, mixed> $themeMods Theme mod name => value.
* @param list<MediaUsageSource> $sources
*/
private function finder(
array $contents = [],
@@ -29,7 +31,8 @@ final class MediaUsageFinderTest extends TestCase
array $options = [],
array $themeMods = [],
array $mediaKeys = [],
string $file = '2026/09/foto-scaled.jpg'
string $file = '2026/09/foto-scaled.jpg',
array $sources = []
): MediaUsageFinder {
Functions\when('get_post_meta')->justReturn($file);
Functions\when('get_option')->alias(static fn (string $name) => $options[$name] ?? false);
@@ -70,7 +73,7 @@ final class MediaUsageFinderTest extends TestCase
return [];
});
return new MediaUsageFinder(static fn (): array => $mediaKeys, $db);
return new MediaUsageFinder(static fn (): array => $mediaKeys, $db, $sources);
}
/** @return array<int|string, string> post_id (or title for site usages) => certainty */
@@ -269,23 +272,78 @@ final class MediaUsageFinderTest extends TestCase
self::assertSame(['header_image', 'background_image', 'widget', 'widget', 'widget', 'widget'], array_column($usages, 'where'));
}
public function testUnreadableEntriesHideTheirTitleAndDiviLogoIsPossible(): void
/**
* @param list<array<string, mixed>> $usages
* @param list<int> $asked Collects the attachment IDs the source is asked about.
*/
private static function source(array $usages, array &$asked = []): MediaUsageSource
{
return new class ($usages, $asked) implements MediaUsageSource {
public function __construct(private array $usages, private array &$asked)
{
}
public function usagesOf(int $attachmentId): array
{
$this->asked[] = $attachmentId;
return $this->usages;
}
};
}
public function testUnreadableEntriesHideTheirTitleAndASourceUsageIsListedAfterTheCoreOnes(): void
{
$logo = MediaUsageFinder::siteUsage('Divi-Logo', 'option', 'divi_logo', MediaUsageFinder::POSSIBLE);
$asked = [];
$usages = $this->finder(
[13 => '<img class="wp-image-33">'],
[self::post(20, 'Geist', 'ghost')],
[],
['et_divi' => ['divi_logo' => 'https://k.de/wp-content/uploads/2026/09/foto.jpg']]
[],
[],
[],
'2026/09/foto-scaled.jpg',
[self::source([$logo], $asked)]
)->usages(33);
self::assertSame(
[
['post_id' => 20, 'title' => '(nicht lesbar)', 'post_type' => 'ghost', 'where' => 'featured', 'certainty' => 'sicher'],
['post_id' => 0, 'title' => 'Divi-Logo', 'post_type' => 'option', 'where' => 'divi_logo', 'certainty' => 'möglicherweise'],
['post_id' => 13, 'title' => '(nicht lesbar)', 'post_type' => 'page', 'where' => 'content', 'certainty' => 'sicher'],
[
'post_id' => 20, 'title' => '(nicht lesbar)', 'post_type' => 'ghost',
'where' => 'featured', 'certainty' => 'sicher',
],
$logo,
[
'post_id' => 13, 'title' => '(nicht lesbar)', 'post_type' => 'page',
'where' => 'content', 'certainty' => 'sicher',
],
],
$usages
);
self::assertSame([33], $asked);
}
public function testASourcePlaceIsReportedOnceAndSourcesAreSkippedOnceTheLimitIsReached(): void
{
$first = MediaUsageFinder::siteUsage('Ort', 'option', 'place', MediaUsageFinder::POSSIBLE);
$second = MediaUsageFinder::siteUsage('Ort neu', 'option', 'place', MediaUsageFinder::CERTAIN);
$asked = [];
$usages = $this->finder([], [], [], [], [], [], '2026/09/foto.jpg', [
self::source([$first]),
self::source([$second]),
])->usages(33);
self::assertSame([$second], $usages);
$finder = $this->finder([], [self::post(5, 'Team')], [], [], [], [], '2026/09/foto.jpg', [
self::source([$first], $asked),
]);
self::assertTrue($finder->isUsed(33));
self::assertSame([], $asked, 'a usage was found before: the sources are not asked');
}
public function testIdReferenceWinsOverAFileMatchInTheSameContent(): void