- 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.
94 lines
3.1 KiB
PHP
94 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace classes {
|
|
// Minimal stubs to satisfy class loading without full app bootstrap
|
|
class db {}
|
|
class object_property {
|
|
public function __construct(...$args) {}
|
|
public function value() { return null; }
|
|
public function set($v) {}
|
|
}
|
|
}
|
|
|
|
namespace traits {
|
|
trait db_object_t {}
|
|
}
|
|
|
|
namespace {
|
|
// Lightweight bootstrap for CLI execution without full index.php
|
|
if (!defined('WD')) {
|
|
define('WD', __DIR__ . '/../../');
|
|
}
|
|
|
|
require_once WD . 'objects/department_selfserve_tasks_o.php';
|
|
|
|
use objects\department_selfserve_tasks_o;
|
|
|
|
function ok($message): void { echo "\n\033[32m✔ $message\033[0m\n"; }
|
|
function fail($message): void { echo "\n\033[31m✖ $message\033[0m\n"; }
|
|
|
|
echo "\nButtonsNormalizationTest starting...\n";
|
|
|
|
// 1) Array input with ints and numeric strings
|
|
try {
|
|
$result = department_selfserve_tasks_o::normalizeButtonsInput([1, '2', 3]);
|
|
if ($result === [1, 2, 3]) {
|
|
ok('Array input normalized correctly');
|
|
} else {
|
|
fail('Array input normalization mismatch: ' . json_encode($result));
|
|
}
|
|
} catch (\Exception $e) {
|
|
fail('Array input threw unexpectedly: ' . $e->getMessage());
|
|
}
|
|
|
|
// 2) JSON string input with duplicates and zero
|
|
try {
|
|
$result = department_selfserve_tasks_o::normalizeButtonsInput('[4,5,5,0]');
|
|
if ($result === [4,5,0]) {
|
|
ok('JSON input normalized with duplicates removed');
|
|
} else {
|
|
fail('JSON input normalization mismatch: ' . json_encode($result));
|
|
}
|
|
} catch (\Exception $e) {
|
|
fail('JSON input threw unexpectedly: ' . $e->getMessage());
|
|
}
|
|
|
|
// 3) CSV string input with mapped reset/start buttons
|
|
try {
|
|
$result = department_selfserve_tasks_o::normalizeButtonsInput('reset, 6, 7 ,8, start');
|
|
if ($result === ['reset',6,7,8,'start']) {
|
|
ok('CSV input normalized mapped buttons correctly');
|
|
} else {
|
|
fail('CSV input normalization mismatch: ' . json_encode($result));
|
|
}
|
|
} catch (\Exception $e) {
|
|
fail('CSV input threw unexpectedly: ' . $e->getMessage());
|
|
}
|
|
|
|
// 4) JSON string input preserves reset/start and removes duplicates
|
|
try {
|
|
$result = department_selfserve_tasks_o::normalizeButtonsInput('["RESET", 1, "start", "reset"]');
|
|
if ($result === ['reset',1,'start']) {
|
|
ok('JSON mapped buttons normalized with duplicates removed');
|
|
} else {
|
|
fail('JSON mapped button normalization mismatch: ' . json_encode($result));
|
|
}
|
|
} catch (\Exception $e) {
|
|
fail('JSON mapped button input threw unexpectedly: ' . $e->getMessage());
|
|
}
|
|
|
|
// 5) Invalid input should throw
|
|
$thrown = false;
|
|
try {
|
|
department_selfserve_tasks_o::normalizeButtonsInput('["a", 2]');
|
|
} catch (\Exception $e) {
|
|
$thrown = true;
|
|
ok('Invalid input correctly threw exception: ' . $e->getMessage());
|
|
}
|
|
if (!$thrown) {
|
|
fail('Expected exception for invalid input, but none was thrown');
|
|
}
|
|
|
|
echo "\nButtonsNormalizationTest completed.\n";
|
|
}
|