diff --git a/src/Integrations/WordPress/Content/ContentCreateAbility.php b/src/Integrations/WordPress/Content/ContentCreateAbility.php index f33eeb7..5637890 100644 --- a/src/Integrations/WordPress/Content/ContentCreateAbility.php +++ b/src/Integrations/WordPress/Content/ContentCreateAbility.php @@ -112,11 +112,17 @@ final class ContentCreateAbility implements Ability, DeclaresRequirements /** * Without divi the call stays in WordPress and needs nothing; with divi it needs what the ContentComposer says it - * needs (the Divi integration names its capabilities), so the guard refuses before a draft is inserted. + * needs (the Divi integration names its capabilities), so the guard refuses before a draft is inserted. Without an + * available composer (Divi 5 not active) nothing is required either: execute() then answers with the precise + * unsupported error instead of the guard reporting locked capabilities. */ public function requirements(array $input): array { - return array_key_exists('divi', $input) && $this->divi !== null ? $this->divi->requirements() : []; + if (! array_key_exists('divi', $input) || $this->divi === null || ! $this->divi->available()) { + return []; + } + + return $this->divi->requirements(); } public function execute(array $input): mixed diff --git a/tests/Unit/Integrations/Divi/Release/DiviFeatureGateTest.php b/tests/Unit/Integrations/Divi/Release/DiviFeatureGateTest.php index 44c5d7c..8e66b36 100644 --- a/tests/Unit/Integrations/Divi/Release/DiviFeatureGateTest.php +++ b/tests/Unit/Integrations/Divi/Release/DiviFeatureGateTest.php @@ -208,6 +208,7 @@ final class DiviFeatureGateTest extends TestCase private function composerNeeding(string ...$ids): ContentComposer { $composer = Mockery::mock(ContentComposer::class); + $composer->allows('available')->andReturn(true); $composer->allows('requirements')->andReturn(array_values($ids)); return $composer; @@ -237,6 +238,20 @@ final class DiviFeatureGateTest extends TestCase self::assertSame('lit/content-create', $log->records[0]['ability']); } + public function testContentCreateWithDiviOnASiteWithoutDiviIsLeftToTheToolItself(): void + { + DiviFeatureFixtures::lock(DiviFeature::PageWrite, ReleaseState::Incompatible); + $composer = Mockery::mock(ContentComposer::class); + $composer->allows('available')->andReturn(false); + $composer->shouldNotReceive('requirements'); + $tool = $this->contentCreate($composer); + + self::assertNull( + $this->gate(FakeChangeLog::forbidden())->refusal($tool, ['post_type' => 'page', 'divi' => [[]]]), + 'no divi_incompatible and no refused entry: execute() answers "Divi 5 ist nicht aktiv"' + ); + } + public function testContentCreateWithDiviRunsWhenOnlyOtherFeaturesAreLocked(): void { DiviFeatureFixtures::useStates([ diff --git a/tests/Unit/Integrations/Divi/Release/DiviToolFeaturesTest.php b/tests/Unit/Integrations/Divi/Release/DiviToolFeaturesTest.php index 09486d5..735aadc 100644 --- a/tests/Unit/Integrations/Divi/Release/DiviToolFeaturesTest.php +++ b/tests/Unit/Integrations/Divi/Release/DiviToolFeaturesTest.php @@ -216,6 +216,7 @@ final class DiviToolFeaturesTest extends TestCase { $divi = new DiviIntegration(Mockery::mock(ContentSchema::class), FakeChangeLog::forbidden()); $composer = Mockery::mock(ContentComposer::class); + $composer->allows('available')->andReturn(true); $composer->allows('requirements')->andReturn(self::COMPOSE); $wordPress = new WordPressIntegration( Mockery::mock(ContentSchema::class), diff --git a/tests/Unit/Integrations/WordPress/Content/ContentCreateDiviTest.php b/tests/Unit/Integrations/WordPress/Content/ContentCreateDiviTest.php index a75539c..57297c4 100644 --- a/tests/Unit/Integrations/WordPress/Content/ContentCreateDiviTest.php +++ b/tests/Unit/Integrations/WordPress/Content/ContentCreateDiviTest.php @@ -103,6 +103,18 @@ final class ContentCreateDiviTest extends TestCase self::assertSame([], $this->ability(null)->requirements(self::INPUT), 'no composer: the call is refused anyway'); } + public function testRequirementsAreEmptyWhenTheComposerIsUnavailable(): void + { + $composer = $this->composer(available: false); + $composer->shouldNotReceive('requirements'); + + self::assertSame( + [], + $this->ability($composer)->requirements(self::INPUT), + 'Divi inactive: execute() answers unsupported ("Divi 5 ist nicht aktiv"), the gate must not refuse first' + ); + } + public function testRequirementsWithDiviAreThoseOfTheComposer(): void { $composer = $this->composer();