refactor: Divi pages adapter replaces DiviFlags
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -133,7 +133,7 @@ final class GlobalEditsTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
public function testPlainLibraryItemIsSavedWithoutConfirmAndWithoutDiviFlags(): void
|
||||
public function testPlainLibraryItemIsSavedWithoutConfirmAndWithoutPageFlags(): void
|
||||
{
|
||||
LibraryFixtures::given([LibraryFixtures::item(1057)]);
|
||||
|
||||
@@ -563,7 +563,7 @@ final class GlobalEditsTest extends TestCase
|
||||
}
|
||||
|
||||
/** Ruling P1: lit-divi-replace-text saves library entries through DiviWriter::commit(). */
|
||||
public function testReplaceTextSavesAPlainLibraryItemWithoutDiviFlags(): void
|
||||
public function testReplaceTextSavesAPlainLibraryItemWithoutPageFlags(): void
|
||||
{
|
||||
LibraryFixtures::given([LibraryFixtures::item(1057)]);
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Pages;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviFlags;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use RuntimeException;
|
||||
|
||||
final class DiviFlagsTest 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'
|
||||
);
|
||||
|
||||
DiviFlags::set(7);
|
||||
|
||||
// Like Divi's own save (SyncToServerController.php:382-387), incl. the page creation flow 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');
|
||||
DiviFlags::set(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');
|
||||
DiviFlags::set(7);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,114 @@
|
||||
<?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\Manifest;
|
||||
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(Manifest::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'));
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ final class DiviSaverTest extends TestCase
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
public function testSavesWithoutKsesForFilteredUsersAndSetsDiviFlags(): void
|
||||
public function testSavesWithoutKsesForFilteredUsersAndSetsThePageFlags(): void
|
||||
{
|
||||
Functions\when('current_user_can')->justReturn(false);
|
||||
Functions\when('has_filter')->justReturn(10);
|
||||
@@ -269,7 +269,7 @@ final class DiviSaverTest extends TestCase
|
||||
(new DiviSaver())->saveNew(42, 'NEU');
|
||||
}
|
||||
|
||||
public function testLibraryItemsGetNoDiviFlagsAndGlobalOnesClearEveryPage(): void
|
||||
public function testLibraryItemsGetNoPageFlagsAndGlobalOnesClearEveryPage(): void
|
||||
{
|
||||
\ET_Core_PageResource::$removed = [];
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
|
||||
@@ -30,13 +30,8 @@ final class DiviBoundaryTest extends TestCase
|
||||
'Integrations/Divi/Library/DiviRoles.php',
|
||||
'Integrations/Divi/Library/LibraryItemSpec.php',
|
||||
'Integrations/Divi/Library/NewLibraryEntry.php',
|
||||
'Integrations/Divi/Pages/DiviFlags.php',
|
||||
'Integrations/Divi/Pages/DiviPage.php',
|
||||
'Integrations/Divi/Pages/DiviSaver.php',
|
||||
'Integrations/Divi/Pages/WpLinkTargets.php',
|
||||
'Integrations/Divi/ThemeBuilder/DiviThemeBuilder.php',
|
||||
'Integrations/Media/MediaUsageFinder.php',
|
||||
'Integrations/WordPress/Content/PostPresenter.php',
|
||||
];
|
||||
|
||||
public function testOnlyAdaptersTouchDivi(): void
|
||||
|
||||
Reference in New Issue
Block a user