null, 'Deleted' => 0); } // A save that the database rejects. $GLOBALS['fail'] = true; $thing = new FakeThing(); $thing->Id(7); $ok = $thing->save(array('Deleted' => true)); check('a rejected save reports failure', $ok === false); check('and keeps the driver message for the caller', strpos((string)$thing->get_last_error(), 'Importance') !== false, 'got: '.var_export($thing->get_last_error(), true)); // And the normal path still works. $GLOBALS['fail'] = false; $thing2 = new FakeThing(); $thing2->Id(8); check('a good save still reports success', $thing2->save(array('Deleted' => true)) === true); @unlink($stub_dir.'/database.php'); @rmdir($stub_dir); // Monitor::delete() must hand that result back rather than swallow it. $monitor_src = file_get_contents($root.'/web/includes/Monitor.php'); check('Monitor::delete returns the result of the save', (bool)preg_match('/return \$this->save\(\[\'Deleted\'=>true\]\);/', $monitor_src)); // And the console action has to surface it, and not audit a delete that failed. $console_src = file_get_contents($root.'/web/includes/actions/console.php'); check('the console action checks the result', (bool)preg_match('/if \(\$monitor->delete\(\)\)/', $console_src)); check('it tells the user what the database said', strpos($console_src, 'get_last_error()') !== false); check('and only audits a delete that happened', strpos($console_src, "AuditAction('delete', 'monitor'") < strpos($console_src, "\$error_message .= 'Error deleting monitor ")); print $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0);