mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-21 23:43:17 +01:00
Add tests to check changing account's groups
This commit is contained in:
parent
75e1a8bb3f
commit
bf49f67782
@ -2,7 +2,7 @@
|
||||
|
||||
/**
|
||||
* Tests for edit user command
|
||||
*
|
||||
*
|
||||
* It would be good to check to see if the hooks get called, but that's impossible
|
||||
* with static hook calls.
|
||||
*
|
||||
@ -35,6 +35,10 @@ class UserCommandTest extends CommandBase {
|
||||
{
|
||||
$GLOBALS['egw']->accounts->delete($this->account_id);
|
||||
}
|
||||
if($this->group_id)
|
||||
{
|
||||
$GLOBALS['egw']->accounts->delete($this->group_id);
|
||||
}
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
@ -187,4 +191,97 @@ class UserCommandTest extends CommandBase {
|
||||
$post_search = $GLOBALS['egw']->accounts->search(array('type' => 'both'));
|
||||
$this->assertEquals(count($pre_search), count($post_search), 'Should have same number of accounts as before');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that changing the primary group works and does not change any other
|
||||
* fields (such as other groups)
|
||||
*/
|
||||
public function testChangePrimaryGroup()
|
||||
{
|
||||
// Set up
|
||||
$command = new admin_cmd_edit_user(false, $this->account);
|
||||
$command->comment = 'Setup for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
$this->account_id = $command->account;
|
||||
$pre_group = $GLOBALS['egw']->accounts->id2name($this->account_id, 'account_primary_group');
|
||||
$pre_groups = $GLOBALS['egw']->accounts->memberships($this->account_id);
|
||||
|
||||
$group = array(
|
||||
'account_lid' => $this->getName(),
|
||||
'account_members' => array($GLOBALS['egw_info']['user']['account_id'])
|
||||
);
|
||||
if(($account_id = $GLOBALS['egw']->accounts->name2id($group['account_lid'])))
|
||||
{
|
||||
// Delete if there in case something went wrong
|
||||
$GLOBALS['egw']->accounts->delete($account_id);
|
||||
}
|
||||
$command = new admin_cmd_edit_group(false, $group);
|
||||
$command->comment = 'Needed for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
$this->group_id = $command->account;
|
||||
|
||||
$account = $this->account;
|
||||
$account['account_primary_group'] = $this->group_id;
|
||||
|
||||
// Execute
|
||||
$command = new admin_cmd_edit_user($this->account_id, $account);
|
||||
$command->comment = 'Needed for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
|
||||
// Check
|
||||
$post_group = $GLOBALS['egw']->accounts->id2name($this->account_id, 'account_primary_group');
|
||||
$post_groups = $GLOBALS['egw']->accounts->memberships($this->account_id);
|
||||
$this->assertEquals($this->group_id, $post_group);
|
||||
$this->assertNotEquals($pre_group, $post_group);
|
||||
|
||||
// Changing primary group does not remove membership of previous
|
||||
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups);
|
||||
|
||||
$this->assertArraySubset($this->account, $GLOBALS['egw']->accounts->read($this->account_id));
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that changing an accounts group memberships works and does not change any
|
||||
* other fields (such as primary group)
|
||||
*/
|
||||
public function testChangeGroups()
|
||||
{
|
||||
$command = new admin_cmd_edit_user(false, $this->account);
|
||||
$command->comment = 'Setup for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
$this->account_id = $command->account;
|
||||
$pre_group = $GLOBALS['egw']->accounts->id2name($this->account_id, 'account_primary_group');
|
||||
$pre_groups = $GLOBALS['egw']->accounts->memberships($this->account_id);
|
||||
|
||||
$group = array(
|
||||
'account_lid' => $this->getName(),
|
||||
'account_members' => array($GLOBALS['egw_info']['user']['account_id'])
|
||||
);
|
||||
if(($account_id = $GLOBALS['egw']->accounts->name2id($group['account_lid'])))
|
||||
{
|
||||
// Delete if there in case something went wrong
|
||||
$GLOBALS['egw']->accounts->delete($account_id);
|
||||
}
|
||||
$command = new admin_cmd_edit_group(false, $group);
|
||||
$command->comment = 'Needed for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
$this->group_id = $command->account;
|
||||
|
||||
$account = $this->account;
|
||||
$account['account_groups'] = $GLOBALS['egw']->accounts->memberships($this->account_id) +
|
||||
array($this->group_id);
|
||||
|
||||
// Execute
|
||||
$command = new admin_cmd_edit_user($this->account_id, $account);
|
||||
$command->comment = 'Needed for unit test ' . $this->getName();
|
||||
$command->run();
|
||||
|
||||
// Check
|
||||
$post_group = $GLOBALS['egw']->accounts->id2name($this->account_id, 'account_primary_group');
|
||||
$post_groups = $GLOBALS['egw']->accounts->memberships($this->account_id);
|
||||
$this->assertEquals($pre_group, $post_group);
|
||||
$this->assertEquals($pre_groups + array($this->group_id => $group['account_lid']), $post_groups);
|
||||
|
||||
$this->assertArraySubset($this->account, $GLOBALS['egw']->accounts->read($this->account_id));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user