row = $idOrRow; else if (isset(self::$known[$idOrRow])) $this->row = self::$known[$idOrRow]; } public static function find_one($params = array()) { return isset(self::$known[$params['Id']]) ? new Monitor($params['Id']) : null; } public function Id() { return isset($this->row['Id']) ? $this->row['Id'] : null; } } } namespace { $passed = 0; $failed = 0; function check($label, $got, $want) { global $passed, $failed; if ($got === $want) { $passed++; echo " ok $label\n"; } else { $failed++; echo " FAIL $label\n"; echo " got: ".var_export($got, true)."\n"; echo " want: ".var_export($want, true)."\n"; } } function canView($a, $id = null) { return true; } function visibleMonitor($mid) { return true; } function translate($s) { return $s; } function buildMonitorsFilters() { return array('filterBar' => '', 'displayMonitors' => $GLOBALS['displayMonitors']); } // The view includes the monitor filter bar and requires includes/Monitor.php and // includes/MonitorAction.php, which // pull in the real database layer; give it stubs from a temporary include path. $stubDir = sys_get_temp_dir().'/zm-watch-view-'.getmypid(); @mkdir($stubDir.'/includes', 0700, true); file_put_contents($stubDir.'/includes/Monitor.php', " $mid); $view = 'watch'; try { require __DIR__.'/../../web/skins/classic/views/watch.php'; } catch (Throwable $e) { // Past the guard the view needs the whole web layer; reaching it is the failure. } return $view; } $displayMonitors = array(array('Id' => 3, 'Capturing' => 'Always', 'Width' => 640, 'Height' => 480)); ZM\Monitor::$known = array(3 => array('Id' => 3)); check('a mid that is not a monitor shows the error view', run_view('99'), 'error'); $displayMonitors = array(); ZM\Monitor::$known = array(); check('a mid that is not a monitor, with no monitors, shows the error view', run_view('99'), 'error'); // The empty install keeps its own page: the guard only applies when a mid was asked for. check('no mid and no monitor does not show the error view', run_view(null), 'watch'); echo "\n$passed passed, $failed failed\n"; exit($failed ? 1 : 0); }