7, 'Name' => 'Old', 'Hostname' => 'old') : false; } function dbQuery($sql, $args = array()) { $GLOBALS['queries'][] = $sql; return true; } function dbInsertId() { return 55; } function dbLastError() { return ''; } $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"; } } function run($request) { global $root, $action, $error_message, $redirect, $refreshParent, $view; $GLOBALS['queries'] = array(); $GLOBALS['audits'] = array(); $action = 'save'; $error_message = ''; $redirect = null; $refreshParent = false; $view = 'server'; $_REQUEST = $request + array('newServer' => array('Name' => 'New', 'Hostname' => 'new')); include $root.'/web/includes/actions/server.php'; return array($error_message, $redirect, $refreshParent); } list($err, $redir, $refresh) = run(array('id' => '9')); check('a deleted server runs no query', $GLOBALS['queries'], array()); check('a deleted server is not audited', $GLOBALS['audits'], array()); check('a deleted server reports that it is gone', $err, 'Server not found
'); check('a deleted server does not redirect', $redir, null); check('a deleted server does not refresh the parent', $refresh, false); list($err, $redir, $refresh) = run(array('id' => '7')); check('an existing server is updated', count($GLOBALS['queries']), 1); check('an existing server is audited as an update', $GLOBALS['audits'], array(array('update', 'server', '7'))); check('an existing server reports no error', $err, ''); check('an existing server goes back to the list', $redir, '?view=options&tab=servers'); list($err, $redir, $refresh) = run(array()); check('a new server is inserted', count($GLOBALS['queries']), 1); check('a new server is audited as a create', $GLOBALS['audits'], array(array('create', 'server', 55))); check('a new server reports no error', $err, ''); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }