Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
43 lines
1.6 KiB
PHP
43 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace LIT\MCP\Tests\Unit\Integrations\Divi\Design;
|
|
|
|
use Brain\Monkey\Functions;
|
|
use LIT\MCP\Integrations\Divi\Design\DiviDesignSnapshotsAbility;
|
|
use LIT\MCP\Integrations\Divi\Design\SnapshotStore;
|
|
use LIT\MCP\Tests\Unit\TestCase;
|
|
use Mockery;
|
|
|
|
final class DiviDesignSnapshotsAbilityTest extends TestCase
|
|
{
|
|
public function testListsTheSnapshotsOfAnArea(): void
|
|
{
|
|
Functions\when('current_user_can')->alias(static fn (string $cap): bool => $cap === 'edit_theme_options');
|
|
$store = Mockery::mock(SnapshotStore::class);
|
|
$store->expects('list')->with('presets')->andReturn([
|
|
['id' => 'presets-2', 'created' => '2026-10-16T10:00:00+00:00', 'user_id' => 1,
|
|
'ability' => 'lit/divi-presets-set', 'log_id' => 4, 'size' => 120],
|
|
]);
|
|
$ability = new DiviDesignSnapshotsAbility($store);
|
|
|
|
self::assertTrue($ability->permission([]));
|
|
$result = $ability->execute([]);
|
|
|
|
self::assertSame('presets', $result['area']);
|
|
self::assertSame('presets-2', $result['snapshots'][0]['id']);
|
|
self::assertTrue($ability->annotations()['readonly']);
|
|
}
|
|
|
|
public function testUnknownAreaAndRights(): void
|
|
{
|
|
Functions\when('current_user_can')->justReturn(false);
|
|
$ability = new DiviDesignSnapshotsAbility(Mockery::mock(SnapshotStore::class));
|
|
|
|
self::assertToolError($ability->permission([]), 'forbidden');
|
|
Functions\when('current_user_can')->justReturn(true);
|
|
self::assertToolError($ability->execute(['area' => 'seiten']), 'validation_failed');
|
|
}
|
|
}
|