(new ReflectionMethod($module, $name))->invoke($module, ...$args); // Like a native List variable, this object is iterable/array-accessible but does not JSON-encode its rows. final class NativeFormList implements IteratorAggregate, ArrayAccess { public function __construct(private array $rows) {} public function getIterator(): Traversable { foreach ($this->rows as $row) yield new ArrayObject($row); } public function offsetExists(mixed $offset): bool { return isset($this->rows[$offset]); } public function offsetGet(mixed $offset): mixed { return $this->rows[$offset] ?? null; } public function offsetSet(mixed $offset, mixed $value): void { throw new LogicException('Readonly fixture'); } public function offsetUnset(mixed $offset): void { throw new LogicException('Readonly fixture'); } } function NFSC_SaveAccessUser(int $id, string $user, string $name, string $role, bool $enabled, bool $view, bool $control, string $rooms, string $devices, string $objects, string $password): string { global $module; return $module->SaveAccessUser($user, $name, $role, $enabled, $view, $control, $rooms, $devices, $objects, $password); } function NFSC_SelectAccessUser(int $id, string $user): void { global $module; $module->SelectAccessUser($user); } function formItems(): array { global $module; $form = json_decode($module->GetConfigurationForm(), true, 512, JSON_THROW_ON_ERROR); return array_values(array_filter($form['actions'], static fn(array $a): bool => ($a['type'] ?? '') === 'ExpansionPanel'))[0]['items']; } function clickSave(string $script, array $fields): string { extract($fields); $id = 12345; ob_start(); try { eval($script); return (string) ob_get_contents(); } finally { ob_end_clean(); } } $items = formItems(); $names = array_column($items, 'name'); check(array_search('AccountPassword', $names, true) === array_search('AccountName', $names, true) + 1, 'Password belongs directly below the user name'); $save = array_values(array_filter($items, static fn(array $item): bool => ($item['caption'] ?? '') === 'Benutzer speichern'))[0]['onClick']; $script = is_array($save) ? implode("\n", $save) : $save; $fields = ['AccountSelect' => '', 'AccountName' => 'form-empty', 'AccountRole' => 'user', 'AccountEnabled' => true, 'AccountViewAll' => true, 'AccountControlAll' => false, 'AccountPassword' => 'form-test-password', 'AccountRooms' => new NativeFormList([]), 'AccountDevices' => new NativeFormList([]), 'AccountObjects' => new NativeFormList([])]; check(json_encode($fields['AccountRooms']) === '{}', 'Fixture reproduces the unsupported direct List serialization'); check(str_starts_with(clickSave($script, $fields), 'Benutzer gespeichert.'), 'The actual save button accepts empty native form lists'); $emptyID = $module->fields['AccountSelect']['value']; $empty = $method('accounts')[$emptyID]; check($empty['rooms'] === [] && $empty['devices'] === [] && $empty['objects'] === [], 'Empty tables remain empty'); $rooms = [['target' => 'room:eg:office2', 'access' => 'view'], ['target' => 'room:old:removed', 'access' => 'control']]; $devices = [['target' => 'furniture:eg:wallbox', 'access' => 'control']]; $objects = [['target' => 900, 'access' => 'view'], ['target' => 104, 'access' => 'view']]; $fields = [...$fields, 'AccountName' => 'form-scoped', 'AccountViewAll' => false, 'AccountRooms' => new NativeFormList($rooms), 'AccountDevices' => new NativeFormList($devices), 'AccountObjects' => new NativeFormList($objects)]; check(str_starts_with(clickSave($script, $fields), 'Benutzer gespeichert.'), 'The actual save button serializes every row, including rows that are not selected'); $scopedID = $module->fields['AccountSelect']['value']; $scoped = $method('accounts')[$scopedID]; check($scoped['rooms'] === $rooms && $scoped['devices'] === $devices && $scoped['objects'] === $objects, 'All three grant tables retain exact per-user rights'); $change = array_values(array_filter($items, static fn(array $item): bool => ($item['name'] ?? '') === 'AccountSelect'))[0]['onChange']; $select = static function (string $selected) use ($change): void { $id = 12345; $AccountSelect = $selected; eval($change); }; $select($emptyID); foreach (['AccountRooms', 'AccountDevices', 'AccountObjects'] as $name) check(json_decode($module->fields[$name]['values'], true) === [], 'Switching to an unrestricted reader clears the previous grants'); check($module->fields['AccountName']['value'] === 'form-empty' && $module->fields['AccountPassword']['value'] === '', 'User changes load the right name and clear the password field'); check(!in_array('room:old:removed', array_column(json_decode($module->fields['AccountRooms']['columns'], true)[0]['edit']['options'], 'value'), true), 'Stale target choices do not leak into another user'); $select($scopedID); foreach (['AccountRooms' => $rooms, 'AccountDevices' => $devices, 'AccountObjects' => $objects] as $name => $expected) check(json_decode($module->fields[$name]['values'], true) === $expected, 'Each table restores the selected user'); check(in_array('room:old:removed', array_column(json_decode($module->fields['AccountRooms']['columns'], true)[0]['edit']['options'], 'value'), true), 'Previously linked missing plan targets remain visible when switching users'); $fields = [...$fields, 'AccountSelect' => $scopedID, 'AccountPassword' => '']; check(str_starts_with(clickSave($script, $fields), 'Benutzer gespeichert.'), 'Saving an existing user permits an empty password'); check(password_verify('form-test-password', $method('accounts')[$scopedID]['password']), 'Empty password preserves the previous hash'); check(str_starts_with(clickSave($script, [...$fields, 'AccountSelect' => '', 'AccountName' => 'no-password']), 'Für neue Benutzer'), 'New accounts still require a password'); $select(''); foreach (['AccountRooms', 'AccountDevices', 'AccountObjects'] as $name) check(json_decode($module->fields[$name]['values'], true) === [], 'New user selection resets every grant table'); check(!$module->fields['AccountReset']['enabled'] && !$module->fields['AccountDelete']['enabled'], 'New user selection disables existing-account operations'); check($module->SaveAccessUser($emptyID, 'form-empty', 'user', true, true, false, '{"target":"room:eg:office2","access":"control"}', '[]', '[]', '') === 'Ungültige Freigabeliste.', 'A selected row cannot be mistaken for the complete grants list'); $form = json_decode($module->GetConfigurationForm(), true); check($form['actions'][1]['caption'] === 'Designer im Browser öffnen' && $form['actions'][1]['link'] === true, 'The browser link does not promise a native Pro Console tab'); echo "OK: real form save with opaque iterable Lists; empty/multiple grants; user-switch reload/reset and missing-target choices; password position and preservation; honest browser action\n";