$argv[2], 'eid' => '7', 'fid' => 'alarm', 'path' => 'images/all/event_7_frame_alarm.jpg'); try { include $file; } catch (Done $e) {} exit(0); } function setup($locked) { $d = ZM_TRAINING_DATA_DIR; exec('chmod -R u+w '.escapeshellarg($d).' 2>/dev/null; rm -rf '.escapeshellarg($d)); mkdir($d.'/images/all', 0700, true); mkdir($d.'/labels/all', 0700, true); file_put_contents($d.'/images/all/event_7_frame_alarm.jpg', 'x'); file_put_contents($d.'/labels/all/event_7_frame_alarm.txt', "0 0.5 0.5 0.2 0.2\n"); if ($locked) { chmod($d.'/images/all', 0500); chmod($d.'/labels/all', 0500); } } function run($action) { global $root, $argv; return trim(shell_exec(escapeshellarg(PHP_BINARY).' '.escapeshellarg($argv[0]).' '.escapeshellarg($root).' '. escapeshellarg($action).' 2>/dev/null')); } $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"; } } foreach (array('delete', 'delete_all', 'browse_delete') as $action) { setup(true); check("$action reports an error when files cannot be removed", run($action), 'error'); } setup(false); check('delete succeeds on removable files', substr(run('delete'), 0, 7), 'ok:true'); setup(false); check('delete_all succeeds on removable files', run('delete_all'), 'ok:2'); setup(false); check('browse_delete succeeds on removable files', run('browse_delete'), 'ok:["images\/all\/event_7_frame_alarm.jpg","labels\/all\/event_7_frame_alarm.txt"]'); exec('chmod -R u+w '.escapeshellarg($tmp).'; rm -rf '.escapeshellarg($tmp)); exit($failures ? 1 : 0); }