Files
WP-LIT-MCP/tests/Unit/Integrations/Divi/Pages/DiviPagesTest.php
T
Jan-Niclas LoosenandClaude Opus 5.5 b511ef6348 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>
2026-11-06 12:03:30 +01:00

115 lines
4.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
declare(strict_types=1);
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
use Brain\Monkey\Functions;
use LIT\MCP\Integrations\Divi\Pages\DiviPages;
use LIT\MCP\Integrations\Divi\Release\DiviAdapters;
use LIT\MCP\Integrations\Divi\Release\DiviAreas;
use LIT\MCP\Tests\Unit\TestCase;
use RuntimeException;
use WP_Post;
final class DiviPagesTest extends TestCase
{
public function testSetsBothFlagsAndAcceptsAnUnchangedValue(): void
{
$written = [];
// update_post_meta() is false when the value is already "on" – no failure (ruling S11).
Functions\when('update_post_meta')->alias(static function (int $id, string $key, string $value) use (&$written): bool {
$written[] = "$id:$key=$value";
return false;
});
Functions\when('get_post_meta')->alias(
static fn (int $id, string $key): string => $key === '_et_pb_show_page_creation' ? 'off' : 'on'
);
DiviPages::setFlags(7);
// Like Divi's own save (SyncToServerController::update, Mirror vb-sync-flags), incl. the page creation flag.
self::assertSame(
['7:_et_pb_use_divi_5=on', '7:_et_pb_use_builder=on', '7:_et_pb_show_page_creation=off'],
$written
);
}
public function testThrowsWhenAFlagDoesNotReadBack(): void
{
Functions\when('update_post_meta')->justReturn(true);
Functions\when('get_post_meta')->alias(
static fn (int $id, string $key): string => $key === '_et_pb_use_builder' ? 'off' : 'on'
);
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('_et_pb_use_builder');
DiviPages::setFlags(7);
}
public function testThrowsWhenThePageCreationFlagDoesNotReadBack(): void
{
Functions\when('update_post_meta')->justReturn(true);
Functions\when('get_post_meta')->justReturn('on');
$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('_et_pb_show_page_creation');
DiviPages::setFlags(7);
}
public function testIsTheRegisteredPagesAdapterWithTheFlagMirror(): void
{
$manifest = DiviPages::manifest();
self::assertContains(DiviPages::class, DiviAdapters::CLASSES);
self::assertSame(DiviAreas::PAGES, $manifest->area);
self::assertSame(['vb-sync-flags'], array_map(static fn ($mirror): string => $mirror->id, $manifest->mirrors));
self::assertSame('SyncToServerController::update()', $manifest->mirrors[0]->label());
}
public function testUsesBuilderReadsDivisFlag(): void
{
Functions\when('get_post_meta')->alias(
static fn (int $id, string $key): string => $id === 7 && $key === '_et_pb_use_builder' ? 'on' : ''
);
self::assertTrue(DiviPages::usesBuilder(7));
self::assertFalse(DiviPages::usesBuilder(8));
}
public function testBuilderUrlOpensTheVisualBuilder(): void
{
Functions\when('get_permalink')->justReturn('https://k.de/start/');
Functions\when('add_query_arg')->alias(
static fn (string $key, string $value, string $url): string => $url . '?' . $key . '=' . $value
);
self::assertSame('https://k.de/start/?et_fb=1', DiviPages::builderUrl(new WP_Post(['ID' => 7])));
}
public function testClearPageCssRemovesThePagesStaticFiles(): void
{
\ET_Core_PageResource::$removed = [];
DiviPages::clearPageCss(7);
self::assertSame([[7, 'all', true]], \ET_Core_PageResource::$removed);
}
/**
* Own process (Brain Monkey's FunctionStub eval's a real global function the first time a name is
* stubbed – function_exists() would report it as permanently defined for the rest of the run
* otherwise, breaking WpLinkTargetsTest's "without Divi" case).
*
* @runInSeparateProcess
*/
public function testIsLinkableFollowsDivisPublicPostTypes(): void
{
Functions\when('et_builder_get_public_post_types')->justReturn(['page' => 'Seiten', 'post' => 'Beiträge']);
self::assertTrue(DiviPages::isLinkable('page'));
self::assertFalse(DiviPages::isLinkable('product'));
}
}