'delete', 'cids' => $cids); try { include $root.'/web/ajax/controlcaps.php'; } catch (Done $e) { } $ids = array(); foreach ($GLOBALS['queries'] as $q) { if (strpos($q[0], 'DELETE FROM Controls') === 0) $ids[] = $q[1][0]; } return $ids; } $failures = 0; function check($n, $got, $want) { global $failures; if ($got === $want) echo "ok - $n\n"; else { $failures++; echo "FAIL - $n (got ".var_export($got, true).", want ".var_export($want, true).")\n"; } } check('a negative id deletes nothing', deleted(array('-3')), array()); check('a decimal id deletes nothing', deleted(array('1.5')), array()); check('an exponent id deletes nothing', deleted(array('1e1')), array()); check('a signed id deletes nothing', deleted(array('+3')), array()); check('an id with spaces deletes nothing', deleted(array(' 3')), array()); check('plain ids are deleted', deleted(array('3', '12')), array('3', '12')); check('an integer id is deleted', deleted(array(7)), array('7')); check('a single id given as a string is deleted', deleted('5'), array('5')); check('zero is still passed through', deleted(array('0')), array('0')); check('empty and list entries are skipped', deleted(array('', array('4'), '8')), array('8')); check('a bad id beside a good one leaves the good one', deleted(array('-3', '9')), array('9')); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0);