id = $id; } public function Id() { return $this->id; } public function Deleted() { return false; } public function Type() { return 'Ffmpeg'; } public function ViewWidth() { return 640; } public function ViewHeight() { return 480; } public function Controllable() { return false; } public function zmcControl($m) {} public function sendControlCommand($m) {} } } namespace { $dir = sys_get_temp_dir().'/zm_test_zone_missing_'.getmypid(); mkdir($dir.'/includes', 0755, true); foreach (array('Zone', 'ZonePreset') as $f) { file_put_contents("$dir/includes/$f.php", " 5, 'Name' => 'Old', 'Type' => 'Active'); return false; } function dbQuery($sql, $args = array()) { ZM\Rec::$queries[] = array($sql, $args); return true; } function coordsToPoints($c) { return array(); } function pointsToCoords($p) { return ''; } function getPolyArea($p) { return 10000; } function localRedirectUrl($referer, $default) { return $default; } function daemonCheck() { return false; } function translate($s) { return $s; } $passes = 0; $failures = 0; function check($name, $actual, $expected) { global $passes, $failures; if ($actual === $expected) { $passes++; echo "ok - $name\n"; } else { $failures++; echo "FAIL - $name: expected ".var_export($expected, true).', got '.var_export($actual, true)."\n"; } } function saveZone($zid) { global $action, $error_message, $redirect; ZM\Rec::$queries = array(); ZM\Rec::$audits = array(); $_REQUEST = array( 'mid' => '8', 'action' => 'zone', 'zid' => (string)$zid, 'newZone' => array('Name' => 'New', 'Type' => 'Active'), ); $action = 'zone'; $error_message = ''; $redirect = null; $warnings = array(); set_error_handler(function($no, $str) use (&$warnings) { $warnings[] = $str; return true; }); ob_start(); include __DIR__.'/../../web/includes/actions/zone.php'; ob_end_clean(); restore_error_handler(); return array($error_message, $warnings); } list($error, $warnings) = saveZone(9); check('saving a zone that is not found writes nothing', ZM\Rec::$queries, array()); check('saving a zone that is not found is not audited', ZM\Rec::$audits, array()); check('saving a zone that is not found reports an error', $error !== '', true); check('saving a zone that is not found raises no PHP warning', $warnings, array()); list($error, $warnings) = saveZone(5); check('saving an existing zone updates it', count(ZM\Rec::$queries), 1); check('saving an existing zone reports no error', $error, ''); system('rm -rf '.escapeshellarg($dir)); echo "\n$passes passed, $failures failed\n"; exit($failures ? 1 : 0); }