Files
api/services/nginx/app/tests/dynamicimages/DepartmentLanesImageTest.php
T
Jeppe Bundgaard eeccacb2a7 Add unit tests for department lane dynamic image overrides and introduce classes for self-serve signal and virtual hardware management
- Add `DepartmentLaneDynamicImageRouteTest` to verify dynamic image preview handling for studio lanes.
- Introduce `selfserve_machine_signal` class to standardize signal normalization, recording, and gateway signal management workflows.
- Add `selfserve_virtual_hardware` class to handle virtual hardware configurations, including gateway and binding management.
- Enhance structure with auxiliary methods for payload normalization, workspace merging, and validation warnings.
2026-04-29 09:52:51 +02:00

64 lines
3.4 KiB
PHP

<?php
// Lightweight, env-agnostic test for dynamic images construction
// This test avoids requiring full app bootstrap and Imagick composition by
// leveraging exportAsBase64() fallback when no canvas is initialized.
// Minimal stubs to satisfy dependencies when running without full bootstrap
namespace classes { class db {} class object_property { public function __construct(...$a){} public function value(){return null;} public function set($v){} } }
namespace traits { trait db_object_t {} }
namespace {
if (!defined('WD')) { define('WD', dirname(__DIR__, 2)); }
require_once WD . '/modules/dynamicimages/traits/dynamicimages_asset_t.php';
require_once WD . '/modules/dynamicimages/interfaces/dynamicimages_asset_i.php';
require_once WD . '/modules/dynamicimages/classes/dynamicimages_asset.php';
require_once WD . '/modules/dynamicimages/interfaces/dynamicimages_image_i.php';
require_once WD . '/modules/dynamicimages/traits/dynamicimages_image_t.php';
require_once WD . '/modules/dynamicimages/classes/dynamicimages_image.php';
require_once WD . '/modules/dynamicimages/images/machine_1.php';
require_once WD . '/objects/department_selfserve_tasks_o.php';
use dynamicimages\images\machine_1;
use objects\department_selfserve_tasks_o;
function ok($m){ echo "\n\033[32m✔ $m\033[0m\n"; }
function fail($m){ echo "\n\033[31m✖ $m\033[0m\n"; }
echo "\nDepartmentLanesImageTest starting...\n";
// 1) Buttons normalization examples
try {
$arr = department_selfserve_tasks_o::normalizeButtonsInput('reset, 0, 2,3 , 5, start');
if ($arr === ['reset',0,2,3,5,'start']) { ok('CSV mapped buttons normalization works'); } else { fail('CSV normalization mismatch: '.json_encode($arr)); }
} catch (\Exception $e) { fail('CSV normalization threw: '.$e->getMessage()); }
try {
$arr = department_selfserve_tasks_o::normalizeButtonsInput('[1, 1, "2", 4, "START"]');
if ($arr === [1,2,4,'start']) { ok('JSON buttons normalization with de-dup works'); } else { fail('JSON normalization mismatch: '.json_encode($arr)); }
} catch (\Exception $e) { fail('JSON normalization threw: '.$e->getMessage()); }
// 2) Vehicle type normalization examples
try { $v = department_selfserve_tasks_o::normalizeVehicleTypeInput('3'); if ($v===3) ok('Vehicle type numeric string ok'); else fail('Vehicle type mismatch'); } catch (\Exception $e) { fail($e->getMessage()); }
try { $v = department_selfserve_tasks_o::normalizeVehicleTypeInput(null); if ($v===null) ok('Vehicle type null ok'); else fail('Vehicle type null mismatch'); } catch (\Exception $e) { fail($e->getMessage()); }
// 3) Sanity: instantiate machine_1 and export base64 from first asset (no canvas)
try {
$img = new machine_1();
// Set some sample parameters (not used until setup(), which we skip to avoid Imagick requirement)
$img->highlighted_buttons = ['reset',0,2,5,'start'];
$img->current_step = 1;
$dataUri = $img->exportAsBase64();
if (is_string($dataUri) && str_starts_with($dataUri, 'data:image/')) {
ok('machine_1 exportAsBase64 fallback returns a data URI');
} else {
fail('machine_1 exportAsBase64 returned unexpected value');
}
} catch (\Throwable $e) {
fail('machine_1 instantiation/export threw: '.$e->getMessage());
}
echo "\nDepartmentLanesImageTest completed.\n";
}