injectedPermissions = $injectedPermissions; parent::__construct($subuser_id, $customer_number); } // Override to inject permissions instead of querying DB public function loadGrants(): void { // Manually enable nodes on each permission container without hitting the database $reflection = new \ReflectionClass($this); $properties = $reflection->getProperties(); foreach ($properties as $property) { $type = $property->getType(); if ($type && is_a($type->getName(), \modules\subusers\classes\subusers_permission_nodes::class, true)) { if (method_exists($property, 'isInitialized') && !$property->isInitialized($this)) { continue; } $container = $property->getValue($this); if ($container instanceof \modules\subusers\classes\subusers_permission_nodes) { foreach ($this->injectedPermissions as $perm) { $key = is_string($perm) ? $perm : $perm->name; $node = $container->getNodeByKey($key); if ($node) { $node->value = true; } } } } } } } // Scenario: subuser has only SELFSERVE_ADD granted => ADD = true; LIST/EDIT/DELETE = false $grant = new SelfserveTestSubuserGrant(123, 456, [subusers_permission_node_key::SELFSERVE_ADD]); if ($grant->hasNode(subusers_permission_node_key::SELFSERVE_ADD)) { ok('SELFSERVE_ADD is granted as expected'); } else { fail('SELFSERVE_ADD should be granted but was not'); } if (!$grant->hasNode(subusers_permission_node_key::SELFSERVE_LIST)) { ok('SELFSERVE_LIST is not granted as expected'); } else { fail('SELFSERVE_LIST should not be granted'); } if (!$grant->hasNode(subusers_permission_node_key::SELFSERVE_EDIT)) { ok('SELFSERVE_EDIT is not granted as expected'); } else { fail('SELFSERVE_EDIT should not be granted'); } if (!$grant->hasNode(subusers_permission_node_key::SELFSERVE_DELETE)) { ok('SELFSERVE_DELETE is not granted as expected'); } else { fail('SELFSERVE_DELETE should not be granted'); } echo "\nSelfservePermissionInitTest completed.\n";