Adds the new /customer/default-driver-template CRUD endpoint so the kundeportal 'tilladelser' tab can store and read the customer's preferred default driver access template. The endpoint reuses the existing subuser_permission_templates_service for validation and falls back to the caller's own customer number when the customer_number parameter is omitted.
72 lines
3.9 KiB
PHP
72 lines
3.9 KiB
PHP
<?php
|
|
|
|
if (!defined('WD')) {
|
|
define('WD', dirname(__DIR__, 2));
|
|
}
|
|
|
|
function ok($message): void { echo "\n\033[32m✔ $message\033[0m\n"; }
|
|
function fail($message): void { echo "\n\033[31m✖ $message\033[0m\n"; exit(1); }
|
|
|
|
$requiredFiles = [
|
|
WD . '/routes/customerDefaultDriverTemplateRoute.php',
|
|
WD . '/objects/customer_default_driver_template_o.php',
|
|
];
|
|
|
|
foreach ($requiredFiles as $requiredFile) {
|
|
if (!file_exists($requiredFile)) {
|
|
fail('Required file missing: ' . $requiredFile);
|
|
}
|
|
}
|
|
|
|
$routeCode = file_get_contents(WD . '/routes/customerDefaultDriverTemplateRoute.php');
|
|
$objectCode = file_get_contents(WD . '/objects/customer_default_driver_template_o.php');
|
|
|
|
if ($routeCode === false || $objectCode === false) {
|
|
fail('Unable to read new customer default driver template source files');
|
|
}
|
|
|
|
$assertContains = static function (string $haystack, string $needle, string $message): void {
|
|
if (strpos($haystack, $needle) === false) {
|
|
fail($message);
|
|
}
|
|
};
|
|
|
|
$assertContains($routeCode, "'/customer/default-driver-template'", 'Route should register the /customer/default-driver-template endpoint');
|
|
$assertContains($routeCode, "requirePermission('get_customer_default_driver_template')", 'GET endpoint should require get_customer_default_driver_template permission');
|
|
$assertContains($routeCode, "requirePermission('edit_customer_default_driver_template')", 'PUT endpoint should require edit_customer_default_driver_template permission');
|
|
$assertContains($routeCode, "requirePermission('delete_customer_default_driver_template')", 'DELETE endpoint should require delete_customer_default_driver_template permission');
|
|
$assertContains($routeCode, 'subuser_permission_templates_service', 'Route should reuse the existing template service for validation');
|
|
$assertContains($routeCode, 'TEMPLATE_CUSTOM', 'Route should reject custom template keys to avoid bypassing template logic');
|
|
|
|
$assertContains($objectCode, "setTable('customer_default_driver_template')", 'Object should map to customer_default_driver_template table');
|
|
$assertContains($objectCode, 'customer_number', 'Object should expose customer_number property');
|
|
$assertContains($objectCode, 'template_key', 'Object should expose template_key property');
|
|
$assertContains($objectCode, 'doesUserHaveDefaultTemplate', 'Object should provide doesUserHaveDefaultTemplate helper');
|
|
$assertContains($objectCode, 'getDefaultTemplate', 'Object should provide getDefaultTemplate helper');
|
|
$assertContains($objectCode, 'update(', 'Object should provide an update() method for upserts');
|
|
$assertContains($objectCode, 'selectByCustomerNumber', 'Object should provide selectByCustomerNumber helper');
|
|
$assertContains($objectCode, 'delete(', 'Object should provide a delete() method for removal');
|
|
|
|
// Sanity: the route must surface 5 main permission groups in the access model
|
|
// (TRU-89 requests 5 toggles in the customer portal "tilladelser" tab).
|
|
$templateServiceFile = WD . '/classes/subuser_permission_templates_service.php';
|
|
if (!file_exists($templateServiceFile)) {
|
|
fail('subuser_permission_templates_service.php not found');
|
|
}
|
|
$templateServiceCode = preg_replace('/\s+/', ' ', file_get_contents($templateServiceFile));
|
|
$expectedGroups = ['vehicles', 'selfserve', 'bookings', 'orders', 'driver_management'];
|
|
foreach ($expectedGroups as $expectedGroup) {
|
|
if (strpos($templateServiceCode, "'$expectedGroup'") === false) {
|
|
fail('Expected permission group missing from template service: ' . $expectedGroup);
|
|
}
|
|
}
|
|
if (strpos($templateServiceCode, "GROUP_ORDER") === false) {
|
|
fail('Template service is missing the GROUP_ORDER definition');
|
|
}
|
|
|
|
ok('Customer default driver template route registers all CRUD endpoints and validates templates');
|
|
ok('Object exposes the required persistence helpers and maps to the right table');
|
|
ok('Template service still defines the 5 permission groups required for the kunde portal "tilladelser" tab');
|
|
|
|
echo "\nCustomerDefaultDriverTemplateRouteTest completed.\n";
|