$v) $this->$k = $v; } public static function find_one($params = array(), $options = array()) { global $frameRows; foreach ($frameRows as $row) { $ok = true; foreach ($params as $k => $v) { if (!isset($row[$k]) or $row[$k] != $v) $ok = false; } if ($ok) return new Frame($row); } return null; } } class Storage { public function __construct($id = null) {} public static function find_one($params = array()) { return new Storage(); } public function Path() { return ''; } public function Scheme($s = null) { return 'Medium'; } } require_once $eventFile; class TestEvent extends Event { public $dir = ''; public function Path() { return $this->dir; } public function Storage($new = null) { return new Storage(); } public function DefaultVideo() { return ''; } public function find_virtual_frame($fid) { return null; } } $dir = sys_get_temp_dir().'/zm_event_image_src_'.getmypid(); @mkdir($dir, 0700, true); // The bytes do not matter: getImageSrc() only checks existence and size. file_put_contents($dir.'/00005-analyse.jpg', 'not-really-a-jpeg'); file_put_contents($dir.'/00009-analyse.jpg', 'not-really-a-jpeg'); function run_get_image_src($dir, $frameId, $row, $captureOnly = false) { global $frameRows, $errors; $frameRows = $row === null ? array() : array($row); $errors = array(); $event = new TestEvent(); $event->dir = $dir; $imageData = $event->getImageSrc($frameId, SCALE_BASE, $captureOnly); return array('data' => $imageData, 'errors' => $errors); } function errors_mentioning($errors, $needle) { $found = array(); foreach ($errors as $e) { if (stripos($e, $needle) !== false) $found[] = $e; } return $found; } echo "case A: alarm frame saved with an analysis JPEG only\n"; $r = run_get_image_src($dir, 5, array('Id' => 5, 'EventId' => 7, 'FrameId' => 5, 'Type' => 'Alarm', 'Delta' => 0.5)); check('image path is the analysis jpeg', $r['data']['imagePath'], $dir.'/00005-analyse.jpg'); check('image file is the analysis jpeg', $r['data']['imageFile'], $dir.'/00005-analyse.jpg'); check('analysis jpeg is detected', $r['data']['hasAnalysisImage'], true); check('reported as an analysis image', $r['data']['isAnalysisImage'], true); check('no "Capture file does not exist" error', errors_mentioning($r['errors'], 'Capture file does not exist'), array()); check('no errors at all', $r['errors'], array()); echo "case A2: normal frame saved with an analysis JPEG only\n"; $r = run_get_image_src($dir, 5, array('Id' => 5, 'EventId' => 7, 'FrameId' => 5, 'Type' => 'Normal', 'Delta' => 0.5)); check('capture fallback is the analysis jpeg', $r['data']['imagePath'], $dir.'/00005-analyse.jpg'); check('no "Capture file does not exist" error', errors_mentioning($r['errors'], 'Capture file does not exist'), array()); echo "case B: no Frame row and no virtual frame\n"; $r = run_get_image_src($dir, 9, null); check('requested FrameId is kept', $r['data']['FrameId'], 9); check('image path uses the requested FrameId', $r['data']['imagePath'], $dir.'/00009-analyse.jpg'); echo "\n$passes passed, $failures failed\n"; array_map('unlink', glob($dir.'/*')); @rmdir($dir); array_map('unlink', glob($stubdir.'/*')); @rmdir($stubdir); exit($failures ? 1 : 0);