feat: adapter-level Divi release lock, content-create and site status
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -26,4 +26,22 @@ final class EnvironmentProbeTest extends TestCase
|
||||
self::assertSame(['GlobalLayout'], $components['divi']['problems']);
|
||||
self::assertSame([], $components['pods']['problems']);
|
||||
}
|
||||
|
||||
public function testDiviComponentCarriesTheReleaseStatus(): void
|
||||
{
|
||||
$theme = Mockery::mock();
|
||||
$theme->allows('get_template')->andReturn('Divi');
|
||||
$theme->allows('parent')->andReturn(false);
|
||||
$theme->allows('get')->with('Version')->andReturn('5.2.1');
|
||||
Functions\when('wp_get_theme')->justReturn($theme);
|
||||
|
||||
$components = array_column(
|
||||
(new EnvironmentProbe(new DiviCompatibility([])))->components(),
|
||||
null,
|
||||
'id'
|
||||
);
|
||||
|
||||
self::assertSame('released', $components['divi']['release']['state'] ?? null);
|
||||
self::assertNull($components['pods']['release'] ?? null);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Release;
|
||||
|
||||
use Brain\Monkey\Functions;
|
||||
use LIT\MCP\Integrations\Divi\Library\DiviLibraryStore;
|
||||
use LIT\MCP\Integrations\Divi\Library\LibraryItemSpec;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviLocked;
|
||||
use LIT\MCP\Integrations\Divi\Release\ReleaseGate;
|
||||
use LIT\MCP\Integrations\Divi\Release\ReleaseState;
|
||||
use LIT\MCP\Integrations\Divi\Release\ReleaseStatus;
|
||||
use LIT\MCP\Integrations\Divi\ThemeBuilder\DiviThemeBuilder;
|
||||
use LIT\MCP\Integrations\WordPress\Content\NewDraft;
|
||||
use LIT\MCP\Tests\Support\FakeChangeLog;
|
||||
use LIT\MCP\Tests\Unit\TestCase;
|
||||
use WP_Post;
|
||||
|
||||
/** Spec §5.5: every writing adapter method refuses before its first write while Divi is not released. */
|
||||
final class ReleaseGuardsTest extends TestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
ReleaseGate::useResolver(static fn (): ReleaseStatus => new ReleaseStatus(ReleaseState::Untested, '5.3.0'));
|
||||
// Nothing may be written: every write function WordPress offers fails the test.
|
||||
foreach (['wp_update_post', 'wp_insert_post', 'update_post_meta', 'add_post_meta', 'delete_post_meta',
|
||||
'update_option', 'delete_option', 'wp_set_object_terms'] as $write) {
|
||||
Functions\when($write)->alias(static function () use ($write): never {
|
||||
self::fail($write . ' ran although Divi is locked');
|
||||
});
|
||||
}
|
||||
Functions\when('current_user_can')->justReturn(true);
|
||||
}
|
||||
|
||||
/** @return iterable<string, array{callable(): mixed}> */
|
||||
public static function writes(): iterable
|
||||
{
|
||||
$post = new WP_Post(['ID' => 7, 'post_content' => '', 'post_type' => 'page']);
|
||||
$spec = new LibraryItemSpec('Hero', 'section', false, 'regular', null, 'page');
|
||||
|
||||
yield 'save' => [static fn () => (new DiviSaver())->save($post, '<!-- wp:divi/section /-->')];
|
||||
yield 'saveNew' => [static fn () => (new DiviSaver())->saveNew(7, '<!-- wp:divi/section /-->')];
|
||||
yield 'library create' => [static fn () => (new DiviLibraryStore())->create(
|
||||
$spec,
|
||||
new NewDraft(null, FakeChangeLog::forbidden(), 'lit/library-save', 'et_pb_layout', 'Bibliothekseintrag')
|
||||
)];
|
||||
yield 'tb insertLayout' => [static fn () => (new DiviThemeBuilder())->insertLayout('header', 'Kopf')];
|
||||
yield 'tb storeTemplate' => [static fn () => (new DiviThemeBuilder())->storeTemplate(3, [
|
||||
'title' => 'V', 'layouts' => [], 'use_on' => [], 'exclude_from' => [],
|
||||
])];
|
||||
yield 'tb attach' => [static fn () => (new DiviThemeBuilder())->attach(3, 9)];
|
||||
yield 'tb detach' => [static fn () => (new DiviThemeBuilder())->detach(3, 9)];
|
||||
yield 'tb setConditions' => [static fn () => (new DiviThemeBuilder())->setConditions(9, ['singular'], [])];
|
||||
yield 'tb setEnabled' => [static fn () => (new DiviThemeBuilder())->setEnabled(9, true)];
|
||||
yield 'tb unmarkUnused' => [static fn () => (new DiviThemeBuilder())->unmarkUnused(9)];
|
||||
}
|
||||
|
||||
/** @dataProvider writes */
|
||||
public function testRefusesBeforeTheFirstWrite(callable $write): void
|
||||
{
|
||||
$this->expectException(DiviLocked::class);
|
||||
|
||||
$write();
|
||||
}
|
||||
|
||||
public function testTheCheckPageMayBeWrittenWhileProbing(): void
|
||||
{
|
||||
Functions\when('wp_update_post')->justReturn(41);
|
||||
Functions\when('update_post_meta')->justReturn(true);
|
||||
Functions\when('get_post_meta')->alias(
|
||||
static fn (int $id, string $key): string => $key === '_et_pb_show_page_creation' ? 'off' : 'on'
|
||||
);
|
||||
Functions\when('get_post')->justReturn(new WP_Post(['ID' => 41, 'post_content' => 'x']));
|
||||
Functions\when('has_filter')->justReturn(false);
|
||||
|
||||
$warnings = ReleaseGate::whileProbing(41, static fn () => (new DiviSaver())->saveNew(41, 'x'));
|
||||
|
||||
self::assertSame([], $warnings);
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,8 @@ use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviContentComposer;
|
||||
use LIT\MCP\Integrations\Divi\Pages\DiviSaver;
|
||||
use LIT\MCP\Integrations\Divi\Release\ReleaseState;
|
||||
use LIT\MCP\Integrations\Divi\Release\ReleaseStatus;
|
||||
use LIT\MCP\Integrations\WordPress\Content\ContentComposer;
|
||||
use LIT\MCP\Integrations\WordPress\Content\ContentCreateAbility;
|
||||
use LIT\MCP\Integrations\WordPress\Content\NewDraft;
|
||||
@@ -56,11 +58,12 @@ final class ContentCreateDiviTest extends TestCase
|
||||
}
|
||||
|
||||
/** @return ContentComposer&MockInterface */
|
||||
private function composer(bool $available = true, bool $writable = true): ContentComposer
|
||||
private function composer(bool $available = true, bool $writable = true, ?WP_Error $refusal = null): ContentComposer
|
||||
{
|
||||
$composer = Mockery::mock(ContentComposer::class);
|
||||
$composer->allows('available')->andReturn($available);
|
||||
$composer->allows('writable')->andReturn($writable);
|
||||
$composer->allows('refusal')->andReturn($refusal);
|
||||
$composer->allows('check')->with('page', self::SECTIONS)->andReturn(null);
|
||||
|
||||
return $composer;
|
||||
@@ -194,6 +197,16 @@ final class ContentCreateDiviTest extends TestCase
|
||||
* Security M2: with the Divi group disabled or "nur lesen", or lit/divi-insert disabled, the
|
||||
* divi input is refused before anything is created; content-create without divi keeps working.
|
||||
*/
|
||||
public function testLockedDiviRefusesBeforeTheDraftExists(): void
|
||||
{
|
||||
$refusal = (new ReleaseStatus(ReleaseState::Untested, '5.3.0'))->refusal();
|
||||
Functions\expect('wp_insert_post')->never();
|
||||
|
||||
$result = $this->ability($this->composer(true, true, $refusal))->execute(self::INPUT);
|
||||
|
||||
self::assertToolError($result, 'divi_untested');
|
||||
}
|
||||
|
||||
public function testDiviIsRefusedWhenDiviWritesAreSwitchedOff(): void
|
||||
{
|
||||
Functions\expect('wp_insert_post')->never();
|
||||
@@ -224,6 +237,7 @@ final class ContentCreateDiviTest extends TestCase
|
||||
$composer = Mockery::mock(ContentComposer::class);
|
||||
$composer->allows('available')->andReturn(true);
|
||||
$composer->allows('writable')->andReturn(true);
|
||||
$composer->allows('refusal')->andReturn(null);
|
||||
$composer->allows('check')->andReturn(Errors::invalidAttrPath(['divi[0].attrs.x' => 'unbekannt']));
|
||||
$writer = Mockery::mock(PostWriter::class);
|
||||
$writer->allows('prepare')->andReturn(Errors::invalidInput('ungültig', ['fields.role' => 'Pflichtfeld fehlt.']));
|
||||
@@ -323,6 +337,11 @@ final class ContentCreateDiviTest extends TestCase
|
||||
return true;
|
||||
}
|
||||
|
||||
public function refusal(): ?WP_Error
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public function check(string $postType, array $sections): ?WP_Error
|
||||
{
|
||||
return $this->real->check($postType, $sections);
|
||||
|
||||
Reference in New Issue
Block a user