Files

38 lines
2.9 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);
$accounts = $method('accounts');
$as = static function (string $name) use ($module, $accounts): void {
foreach ($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;
}
};
$b = fixtureBuilding();
$b['topology'] = ['locations' => [['id' => 'urbach', 'name' => 'Urbach'], ['id' => 'ulm', 'name' => 'Ulm']],
'branches' => [['id' => 'hq', 'name' => 'Zentrale', 'location_id' => 'urbach'], ['id' => 'south', 'name' => 'Süd', 'location_id' => 'ulm']],
'buildings' => [['id' => 'ras19', 'name' => 'RAS19', 'branch_id' => 'hq'], ['id' => 'ulm1', 'name' => 'RAS19', 'branch_id' => 'south']]];
$b['floors'][0]['building_id'] = 'ras19';
$outside = ['id' => 'garden', 'name' => 'Außen', 'building_id' => null, 'outdoor_location_id' => 'urbach', 'elevation' => 0, 'height' => 2.5,
'rooms' => [], 'openings' => [], 'placements' => [], 'outdoor' => [], 'furniture' => [['id' => 'garden-meter', 'type' => 'wallbox', 'name' => 'Gartengerät', 'entity' => 'sensor.203', 'x' => 1, 'z' => 2]]];
$b['floors'][] = $outside;
$as('admin'); $method('authorizeApi', 'building/save', ['building' => $b]); $method('saveBuilding', $b);
check($method('building')['topology'] === $b['topology'], 'The complete hierarchy persists without changing native links');
$form = $module->GetConfigurationForm();
check(str_contains($form, 'Urbach / Zentrale / RAS19 / Erdgeschoss / Büro 2'), 'Room choices include their complete topology path');
check(str_contains($form, 'Urbach / Außen / Gartengerät'), 'Outdoor device grants belong to the location path');
$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], 'Existing room rights keep their stable key and do not grant outdoor/other-location values');
$visible = $method('visibleBuilding');
check($visible['topology'] === $b['topology'], 'Users retain the complete logical topology, like the building geometry');
check($visible['floors'][1]['furniture'][0]['entity'] === 'none', 'Unapproved outdoor status is still filtered server-side');
$as('empty');
check($method('visibleTree', $method('objectTree'))['variables'] === [], 'Adding topology cannot grant access to an empty account');
echo "OK: persisted five-level topology and location outdoors; complete grant choice paths; unchanged room keys; scoped state and native permissions\n";