Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
ENH: refs #953. Added two more test cases and cleaned up test style.
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Grauer committed Feb 23, 2013
1 parent 63baf30 commit 22f19ec
Showing 1 changed file with 51 additions and 35 deletions.
86 changes: 51 additions & 35 deletions modules/api/tests/controllers/ApiCallGroupMethodsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ public function setUp()
/** Test adding and removing a user from a group */
public function testGroupUserAddRemove()
{
$addMethod = "midas.group.add.user";
$removeMethod = "midas.group.remove.user";
$methods = array($addMethod, $removeMethod);
$addMethod = "midas.group.add.user";
$removeMethod = "midas.group.remove.user";
$methods = array($addMethod, $removeMethod);

$communityModel = MidasLoader::loadModel('Community');
$comm2001 = $communityModel->load('2001');
Expand All @@ -48,7 +48,7 @@ public function testGroupUserAddRemove()
$invalidGroupId = '-10';
$validUserId = '2';
$invalidUserId = '-10';

// test all the failure cases
foreach($methods as $method)
{
Expand All @@ -60,6 +60,22 @@ public function testGroupUserAddRemove()
$resp = $this->_callJsonApi();
$this->_assertStatusFail($resp, MIDAS_INVALID_POLICY);

// missing group_id
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $method;
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);

// missing user_id
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $method;
$this->params['group_id'] = $validGroupId;
$resp = $this->_callJsonApi();
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);

// an invalid group
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
Expand All @@ -68,7 +84,7 @@ public function testGroupUserAddRemove()
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);

// an invalid user
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
Expand All @@ -77,7 +93,7 @@ public function testGroupUserAddRemove()
$this->params['user_id'] = $invalidUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);

// as a non admin
foreach($nonAdmins as $nonAdmin)
{
Expand All @@ -90,35 +106,35 @@ public function testGroupUserAddRemove()
$this->_assertStatusFail($resp, MIDAS_INVALID_POLICY);
}
}
// ensure the user isn't already in the group
$groupModel = MidasLoader::loadModel('Group');
$changedUser = $userModel->load($validUserId);
$group = $groupModel->load($validGroupId);
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
// add the user to the group
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $addMethod;
$this->params['group_id'] = $validGroupId;
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusOk($resp);
// ensure the user is now in the group
$this->assertTrue($groupModel->userInGroup($changedUser, $group), "This user is expected to be in the group");
// remove the user from the group
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $removeMethod;
$this->params['group_id'] = $validGroupId;
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusOk($resp);
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");

// ensure the user isn't already in the group
$groupModel = MidasLoader::loadModel('Group');
$changedUser = $userModel->load($validUserId);
$group = $groupModel->load($validGroupId);
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");

// add the user to the group
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $addMethod;
$this->params['group_id'] = $validGroupId;
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusOk($resp);

// ensure the user is now in the group
$this->assertTrue($groupModel->userInGroup($changedUser, $group), "This user is expected to be in the group");

// remove the user from the group
$this->resetAll();
$this->params['token'] = $this->_loginAsUser($commAdmin);
$this->params['method'] = $removeMethod;
$this->params['group_id'] = $validGroupId;
$this->params['user_id'] = $validUserId;
$resp = $this->_callJsonApi();
$this->_assertStatusOk($resp);

$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
}


Expand Down

0 comments on commit 22f19ec

Please sign in to comment.