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"; }