41 lines
3.0 KiB
PHP
41 lines
3.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
require __DIR__ . '/support/access-runtime.php';
|
|
$module = new AccessFixtureModule(); initializeAccessFixture($module);
|
|
$method = static fn(string $name, mixed ...$args): mixed => (new ReflectionMethod($module, $name))->invoke($module, ...$args);
|
|
$as = static function (string $name) use ($module, $method): void {
|
|
foreach ($method('accounts') as $id => $a) if ($a['name'] === $name) {
|
|
(new ReflectionProperty(NextFloor::class, 'requestUser'))->setValue($module, [...$a, 'id' => $id, 'session_id' => 'fixture-' . $name, 'csrf' => 'fixture']);
|
|
(new ReflectionProperty(NextFloor::class, 'requestScope'))->setValue($module, null); return;
|
|
}
|
|
};
|
|
$before = $method('building'); $after = $before;
|
|
$source = &$after['floors'][0];
|
|
$target = [...$source, 'id' => 'og', 'name' => 'Obergeschoss', 'elevation' => 3, 'rooms' => [], 'furniture' => [], 'placements' => []];
|
|
$target['rooms'][] = array_shift($source['rooms']);
|
|
$target['furniture'][] = array_shift($source['furniture']);
|
|
$target['placements'][] = array_shift($source['placements']);
|
|
unset($source); $after['floors'][] = $target;
|
|
$as('admin'); $method('saveBuilding', $after);
|
|
$accounts = array_column($method('accounts'), null, 'name');
|
|
check($accounts['office']['rooms'] === [['target' => 'room:og:office2', 'access' => 'control']], 'Room control rights follow the moved room');
|
|
check($accounts['officeview']['rooms'] === [['target' => 'room:og:office2', 'access' => 'view']], 'Readonly room rights stay readonly');
|
|
check($accounts['device']['devices'] === [['target' => 'furniture:og:wallbox', 'access' => 'control']], 'Explicit device rights follow its unique identity');
|
|
check($accounts['empty']['rooms'] === [] && $accounts['empty']['devices'] === [], 'Moving cannot create a new grant');
|
|
$as('office'); $tree = $method('visibleTree', $method('objectTree'));
|
|
$ids = array_column(array_column($tree['variables'], 'attributes'), 'symcon_id'); sort($ids);
|
|
check($ids === [101, 102, 103, 104, 105], 'The moved room still exposes exactly its original native variables');
|
|
$as('device'); $method('authorizeApi', 'variables/action', ['data' => ['entity_id' => 'light.102']]);
|
|
$as('admin'); $method('saveBuilding', $before);
|
|
$accounts = array_column($method('accounts'), null, 'name');
|
|
check($accounts['office']['rooms'][0]['target'] === 'room:eg:office2', 'Undo restores the original grant key');
|
|
check($accounts['device']['devices'][0]['target'] === 'furniture:eg:wallbox', 'Undo also restores the explicit device key');
|
|
|
|
// An ambiguous ID may be a duplicate rather than a move; never guess and widen its grant.
|
|
$ambiguous = $after; $ambiguous['floors'][0]['furniture'][] = $target['furniture'][0];
|
|
$method('saveBuilding', $ambiguous);
|
|
$accounts = array_column($method('accounts'), null, 'name');
|
|
check($accounts['device']['devices'][0]['target'] === 'furniture:eg:wallbox', 'Duplicate identities never trigger automatic grant migration');
|
|
echo "OK: room/device grants follow unique floor moves and undo, preserve view/control levels and native visibility, reject ambiguous identities and create no grants\n";
|