id = 4; } function save($v) { $GLOBALS['saves'][] = $this->id === null ? 'insert' : 'update '.$this->id; if ($this->id === null) $this->id = 60; return true; } function Id() { return $this->id; } function Name() { return 'x'; } function get_last_error() { return ''; } } } namespace { function canEdit($a) { return true; } $root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..'; $stub = sys_get_temp_dir().'/zm_ccmissing_'.getmypid(); @mkdir($stub.'/includes', 0700, true); file_put_contents($stub.'/includes/Control.php', " 'Save', 'Control' => array('Name' => 'Pelco D')); include $root.'/web/includes/actions/controlcap.php'; return array($GLOBALS['saves'], $error_message, $redirect); } list($saves, $err, $redir) = run(array('cid' => '9')); check('a deleted capability is not inserted again', $saves, array()); check('a deleted capability is not audited', $GLOBALS['audits'], array()); check('a deleted capability reports that it is gone', $err, 'Control capability not found.
'); check('a deleted capability does not redirect', $redir, null); list($saves, $err, $redir) = run(array('cid' => '4')); check('an existing capability is updated', $saves, array('update 4')); check('an existing capability reports no error', $err, ''); check('an existing capability goes back to the list', $redir, '?view=options&tab=control'); list($saves, $err, $redir) = run(array()); check('a new capability is inserted', $saves, array('insert')); check('a new capability is audited as a create', $GLOBALS['audits'], array(array('create', 'control', 60)) ); check('a new capability reports no error', $err, ''); @unlink($stub.'/includes/Control.php'); @rmdir($stub.'/includes'); @rmdir($stub); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }