'x'); } function save($c) { $GLOBALS['done'][] = 'save'; return true; } } } namespace { $root = isset($argv[1]) ? rtrim($argv[1], '/') : __DIR__.'/../../web'; $stubdir = sys_get_temp_dir().'/zm_snapshot_save_stubs_'.getmypid(); @mkdir($stubdir.'/includes', 0700, true); foreach (array('Snapshot', 'Monitor') as $f) file_put_contents($stubdir.'/includes/'.$f.'.php', " 'snapshot', 'action' => 'save', 'id' => '5', 'snapshot' => array('Name' => 'x')); $action = 'save'; $redirect = null; include $root.'/includes/actions/snapshot.php'; return array($GLOBALS['done'], $redirect, $error_message !== null && $error_message !== ''); } // The snapshot was created by user 9, the current user is 2. check('Snapshots edit only, not the creator: refused with a message', save(array('Snapshots' => 'Edit')), array(array(), null, true)); check('Events edit: saved, no message', save(array('Events' => 'Edit')), array(array('save'), '?view=snapshots', false)); $view = file_get_contents($root.'/skins/classic/views/snapshot.php'); check('snapshot view disables Save for users who cannot save', (bool)preg_match('/id="saveBtn".*canEdit\(\'Events\'\).*disabled/', $view), true); @unlink($stubdir.'/includes/Snapshot.php'); @unlink($stubdir.'/includes/Monitor.php'); @rmdir($stubdir.'/includes'); @rmdir($stubdir); exit($failures ? 1 : 0); }