id = (int)$id; } static function find_one($w) { return null; } function changes($new) { return $new; } function save($c) { $GLOBALS['saves'][] = $this->id === null ? 'insert' : 'update '.$this->id; if ($this->id === null) $this->id = 50; return true; } function Id() { return $this->id; } function Name() { return 'r'; } } } namespace { $root = isset($argv[1]) ? $argv[1] : __DIR__.'/../..'; $stubdir = sys_get_temp_dir().'/zm_role_missing_stubs_'.getmypid(); @mkdir($stubdir.'/includes', 0700, true); foreach (array('User_Role', 'Role_Group_Permission', 'Role_Monitor_Permission', 'Group', 'Monitor') as $f) file_put_contents($stubdir.'/includes/'.$f.'.php', " array('Name' => 'Viewer')); $action = 'Save'; include $root.'/web/includes/actions/role.php'; return $GLOBALS['saves']; } check('editing an existing role updates it', runRole(array('rid' => '3')), array('update 3')); check('a new role is inserted', runRole(array('rid' => '0')), array('insert')); check('a new role without rid is inserted', runRole(array()), array('insert')); check('a deleted role is not inserted again', runRole(array('rid' => '9')), array()); check('a deleted role reports that it is gone', $error_message, 'Role not found
'); foreach (array('User_Role', 'Role_Group_Permission', 'Role_Monitor_Permission', 'Group', 'Monitor') as $f) @unlink($stubdir.'/includes/'.$f.'.php'); @rmdir($stubdir.'/includes'); @rmdir($stubdir); echo $failures ? "\n$failures failed\n" : "\nall passed\n"; exit($failures ? 1 : 0); }