Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
136 lines
5.4 KiB
PHP
136 lines
5.4 KiB
PHP
<?php
|
||
|
||
declare(strict_types=1);
|
||
|
||
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Release;
|
||
|
||
use LIT\MCP\Integrations\Divi\Release\CompatibilityMatrix;
|
||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||
use LIT\MCP\Integrations\Divi\Release\ReleaseState;
|
||
use LIT\MCP\Integrations\Divi\Release\ReleaseStatus;
|
||
use LIT\MCP\Tests\Support\ReleaseMatrices;
|
||
use LIT\MCP\Tests\Unit\TestCase;
|
||
use LogicException;
|
||
|
||
final class ReleaseStatusTest extends TestCase
|
||
{
|
||
public function testOnlyAReleasedVersionIsWritable(): void
|
||
{
|
||
self::assertTrue(ReleaseStatus::released('5.2.1')->writable());
|
||
self::assertFalse((new ReleaseStatus(ReleaseState::Untested, '5.3.0'))->writable());
|
||
self::assertFalse((new ReleaseStatus(ReleaseState::Incompatible, '5.3.0', null, ['x']))->writable());
|
||
}
|
||
|
||
public function testUntestedRefusalNamesTheVersionAndTheWayOut(): void
|
||
{
|
||
$payload = self::assertToolError(
|
||
(new ReleaseStatus(ReleaseState::Untested, '5.3.0'))->refusal(),
|
||
'divi_untested'
|
||
);
|
||
|
||
self::assertSame(
|
||
'Achtung: Divi 5.3.0 ist auf dieser Website noch nicht für LIT MCP freigegeben. Schreibende '
|
||
. 'Divi-Werkzeuge sind gesperrt, bis ein Administrator unter Einstellungen → LIT MCP → Divi die '
|
||
. 'Prüfung ausführt und die Version freigibt. Es wurde nichts geändert.',
|
||
$payload['message']
|
||
);
|
||
self::assertStringContainsString('lesende Divi-Werkzeuge funktionieren weiter', $payload['hint']);
|
||
}
|
||
|
||
public function testIncompatibleRefusalListsTheProblems(): void
|
||
{
|
||
$status = new ReleaseStatus(ReleaseState::Incompatible, '5.3.0', null, ['Theme Builder: Nachbau von x()']);
|
||
$payload = self::assertToolError($status->refusal(), 'divi_incompatible');
|
||
|
||
self::assertSame(
|
||
'Divi 5.3.0 hat Stellen geändert, die LIT MCP nutzt. Schreibende Divi-Werkzeuge sind gesperrt, bis '
|
||
. 'LIT MCP aktualisiert wurde. Es wurde nichts geändert.',
|
||
$payload['message']
|
||
);
|
||
self::assertSame(['Theme Builder: Nachbau von x()'], $payload['problems']);
|
||
}
|
||
|
||
public function testNoticesForReadingTools(): void
|
||
{
|
||
self::assertSame(
|
||
'Achtung: Divi 5.3.0 ist für LIT MCP ungetestet; Lesen funktioniert, Schreiben ist gesperrt.',
|
||
(new ReleaseStatus(ReleaseState::Untested, '5.3.0'))->notice()
|
||
);
|
||
self::assertSame(
|
||
'Achtung: Divi (Version unbekannt) ist für LIT MCP inkompatibel; Lesen funktioniert, Schreiben ist '
|
||
. 'gesperrt.',
|
||
(new ReleaseStatus(ReleaseState::Incompatible, ''))->notice()
|
||
);
|
||
}
|
||
|
||
public function testAReleasedStatusHasNoRefusal(): void
|
||
{
|
||
$this->expectException(LogicException::class);
|
||
|
||
ReleaseStatus::released('5.2.1')->refusal();
|
||
}
|
||
|
||
public function testToArrayForSiteStatus(): void
|
||
{
|
||
$status = new ReleaseStatus(
|
||
ReleaseState::Released,
|
||
'5.3.0',
|
||
ReleaseStatus::SOURCE_DATABASE,
|
||
[],
|
||
['released_at' => '2026-10-01T08:00:00+00:00', 'user_id' => 1]
|
||
);
|
||
|
||
self::assertSame(
|
||
['state' => 'released', 'version' => '5.3.0', 'source' => 'database',
|
||
'released_at' => '2026-10-01T08:00:00+00:00', 'released_by' => 1, 'problems' => []],
|
||
$status->toArray()
|
||
);
|
||
}
|
||
|
||
public function testWithoutMatrixEveryFeatureIsInTheGivenState(): void
|
||
{
|
||
$untested = new ReleaseStatus(ReleaseState::Untested, '5.3.0');
|
||
$broken = new ReleaseStatus(ReleaseState::Incompatible, '5.3.0', null, ['x']);
|
||
$released = ReleaseStatus::released('5.2.1', ReleaseStatus::SOURCE_DATABASE);
|
||
|
||
foreach (DiviFeature::cases() as $feature) {
|
||
self::assertSame(ReleaseState::Untested, $untested->matrix->of($feature)->state);
|
||
self::assertSame(['x'], $broken->matrix->of($feature)->problems);
|
||
self::assertSame('database', $released->matrix->of($feature)->source);
|
||
}
|
||
}
|
||
|
||
public function testOfTakesStateSourceAndProblemsFromTheMatrix(): void
|
||
{
|
||
$status = ReleaseStatus::of(
|
||
'5.99.0',
|
||
ReleaseMatrices::matrix([DiviFeature::Catalog], ReleaseState::Incompatible),
|
||
['user_id' => 1]
|
||
);
|
||
|
||
self::assertSame(ReleaseState::Incompatible, $status->state);
|
||
self::assertNull($status->source);
|
||
self::assertSame(['Seiten: et_x() – Signatur geändert'], $status->problems);
|
||
self::assertSame(['user_id' => 1], $status->release);
|
||
self::assertSame('auto', ReleaseStatus::of('5.99.0', CompatibilityMatrix::allReleased('auto'))->source);
|
||
}
|
||
|
||
public function testWritableAsksOnlyTheWritingFeatures(): void
|
||
{
|
||
$readLocked = ReleaseMatrices::status([DiviFeature::Catalog, DiviFeature::PageRead]);
|
||
self::assertSame(ReleaseState::Untested, $readLocked->state);
|
||
self::assertTrue($readLocked->writable());
|
||
|
||
foreach (CompatibilityMatrix::writeFeatures() as $feature) {
|
||
self::assertFalse(ReleaseMatrices::status([$feature])->writable(), $feature->value);
|
||
}
|
||
}
|
||
|
||
public function testAMatrixInAnotherStateThanTheStatusIsRefused(): void
|
||
{
|
||
$this->expectException(LogicException::class);
|
||
|
||
new ReleaseStatus(ReleaseState::Released, '5.2.1', 'code', [], null, CompatibilityMatrix::allIncompatible('x'));
|
||
}
|
||
}
|