id = ($id == 7) ? 7 : null; } function Id() { return $this->id; } function FilterId() { return null; } function Name() { return 'r'; } function StartDateTime() { return ''; } function EndDateTime() { return ''; } function Interval() { return ''; } function canEdit() { return true; } } class Filter { function __construct($id = null) {} static function find() { return array(); } } } namespace { $root = isset($argv[1]) ? $argv[1] : __DIR__.'/../../web'; $failures = 0; function check($name, $got, $want) { global $failures; if ($got === $want) echo "ok - $name\n"; else { $failures++; echo "FAIL - $name (got ".var_export($got, true).", want ".var_export($want, true).")\n"; } } $stub = sys_get_temp_dir().'/zm_report_missing_'.getmypid(); mkdir($stub.'/includes', 0777, true); foreach (array('Event', 'Filter', 'Report') as $f) file_put_contents($stub."/includes/$f.php", " '999')); check('an id that matches no report shows the error page', $v, 'error'); check('an id that matches no report prints no form', strpos($out, 'reportForm'), false); list($v, $out) = render(array('id' => '7')); check('an existing report keeps the view', $v, 'report'); check('an existing report prints its form', strpos($out, 'reportForm') !== false, true); list($v, $out) = render(array()); check('no id is a new report and keeps the view', $v, 'report'); check('a new report prints its form', strpos($out, 'reportForm') !== false, true); system('rm -rf '.escapeshellarg($stub)); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }