null); } $thing = new FakeThing(); $thing->Id(7); $GLOBALS['fail'] = false; check('ZM_Object::delete() returns true when the DELETE works', $thing->delete(), true); $GLOBALS['fail'] = true; check('ZM_Object::delete() returns false when the DELETE fails', $thing->delete(), false); // actions/zones.php with stub zones and monitors. eval('namespace ZM { class FakeMonitor { public $restarts = 0; function canEdit() { return true; } function Id() { return 1; } function Name() { return "Door"; } function Type() { return "Ffmpeg"; } function zmcControl($m) { $this->restarts++; } } class Zone { static $monitor; private $id; function __construct($id) { $this->id = $id; } function Id() { return $this->id; } function Monitor() { return self::$monitor; } function delete() { return !$GLOBALS["fail"]; } } function AuditAction() { $GLOBALS["audits"]++; } }'); function validCardinal($v) { return is_scalar($v) ? preg_replace('/\D/', '', $v) : ''; } function daemonCheck() { return true; } $zones_dir = sys_get_temp_dir().'/zm_zones_del_inc_'.getmypid(); @mkdir($zones_dir.'/includes', 0700, true); file_put_contents($zones_dir.'/includes/Zone.php', " 'delete', 'markZids' => array('3'), 'mids' => array('1')); include $root.'/web/includes/actions/zones.php'; return array($error_message, $redirect, ZM\Zone::$monitor->restarts, $GLOBALS['audits']); } list($err, $redir, $restarts, $audits) = run_delete(false); check('a delete that works redirects back to the zones', $redir, '?view=zones&mids[]=1'); check('a delete that works restarts the monitor', $restarts, 1); list($err, $redir, $restarts, $audits) = run_delete(true); check('a failed delete is reported', strpos($err, 'Error deleting zone 3') !== false, true); check('a failed delete does not redirect', $redir, null); check('a failed delete does not restart the monitor', $restarts, 0); check('a failed delete is not audited', $audits, 0); @unlink($zones_dir.'/includes/Zone.php'); @rmdir($zones_dir.'/includes'); @rmdir($zones_dir); @unlink($stub_dir.'/database.php'); @rmdir($stub_dir); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0);