pointing at * image.php, even when the event has no objdetect.gif or objdetect.jpg. For a * local event that answers 404, so the modal showed a broken image and nothing * else. It should say so instead. * * Run: php tests/php/test_objdetect_modal_missing_image.php [root] */ namespace ZM { class EventServer { public function Id() { return 1; } } class Event { public static $dirs = array(); public static $hidden = array(); private $path; public function __construct($path) { $this->path = $path; } public static function find_one(array $criteria) { $id = isset($criteria['Id']) ? $criteria['Id'] : null; if (!isset(self::$dirs[$id])) return null; return new Event(self::$dirs[$id]); } public function canView() { return !in_array($this->path, self::$hidden, true); } public function Path() { return $this->path; } public function Server() { return new EventServer(); } } function Error($message) {} } namespace { $root = isset($argv[1]) && $argv[1] !== '' ? $argv[1] : realpath(__DIR__.'/../..'); function validInt($value) { return preg_replace('/[^\-\d]/', '', $value); } function translate($text) { return $text; } $tests = 0; $failures = 0; function check($label, $cond) { global $tests, $failures; $tests++; if ($cond) { echo "ok - $label\n"; } else { $failures++; echo "FAIL - $label\n"; } } function render_modal($eid) { $_REQUEST = array('eid' => $eid); ob_start(); include $GLOBALS['root'].'/web/ajax/modals/objdetect.php'; return ob_get_clean(); } $base = sys_get_temp_dir().'/zm_objdetect_modal_test_'.getmypid(); $dirs = array('a' => $base.'/a', 'b' => $base.'/b', 'c' => $base.'/c'); foreach ($dirs as $dir) { if (!is_dir($dir)) mkdir($dir, 0700, true); } file_put_contents($dirs['b'].'/objdetect.jpg', 'jpg'); file_put_contents($dirs['c'].'/objdetect.gif', 'gif'); \ZM\Event::$dirs = array(1 => $dirs['a'], 2 => $dirs['b'], 3 => $dirs['c']); $empty = render_modal(1); check('an event with no detection image says so', strpos($empty, 'No object detection image') !== false); check('and renders no img', strpos($empty, '