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

Commit 22f19ec

Browse files
author
Michael Grauer
committed
ENH: refs #953. Added two more test cases and cleaned up test style.
1 parent 63baf30 commit 22f19ec

File tree

1 file changed

+51
-35
lines changed

1 file changed

+51
-35
lines changed

modules/api/tests/controllers/ApiCallGroupMethodsTest.php

Lines changed: 51 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function setUp()
3030
/** Test adding and removing a user from a group */
3131
public function testGroupUserAddRemove()
3232
{
33-
$addMethod = "midas.group.add.user";
34-
$removeMethod = "midas.group.remove.user";
35-
$methods = array($addMethod, $removeMethod);
33+
$addMethod = "midas.group.add.user";
34+
$removeMethod = "midas.group.remove.user";
35+
$methods = array($addMethod, $removeMethod);
3636

3737
$communityModel = MidasLoader::loadModel('Community');
3838
$comm2001 = $communityModel->load('2001');
@@ -48,7 +48,7 @@ public function testGroupUserAddRemove()
4848
$invalidGroupId = '-10';
4949
$validUserId = '2';
5050
$invalidUserId = '-10';
51-
51+
5252
// test all the failure cases
5353
foreach($methods as $method)
5454
{
@@ -60,6 +60,22 @@ public function testGroupUserAddRemove()
6060
$resp = $this->_callJsonApi();
6161
$this->_assertStatusFail($resp, MIDAS_INVALID_POLICY);
6262

63+
// missing group_id
64+
$this->resetAll();
65+
$this->params['token'] = $this->_loginAsUser($commAdmin);
66+
$this->params['method'] = $method;
67+
$this->params['user_id'] = $validUserId;
68+
$resp = $this->_callJsonApi();
69+
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);
70+
71+
// missing user_id
72+
$this->resetAll();
73+
$this->params['token'] = $this->_loginAsUser($commAdmin);
74+
$this->params['method'] = $method;
75+
$this->params['group_id'] = $validGroupId;
76+
$resp = $this->_callJsonApi();
77+
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);
78+
6379
// an invalid group
6480
$this->resetAll();
6581
$this->params['token'] = $this->_loginAsUser($commAdmin);
@@ -68,7 +84,7 @@ public function testGroupUserAddRemove()
6884
$this->params['user_id'] = $validUserId;
6985
$resp = $this->_callJsonApi();
7086
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);
71-
87+
7288
// an invalid user
7389
$this->resetAll();
7490
$this->params['token'] = $this->_loginAsUser($commAdmin);
@@ -77,7 +93,7 @@ public function testGroupUserAddRemove()
7793
$this->params['user_id'] = $invalidUserId;
7894
$resp = $this->_callJsonApi();
7995
$this->_assertStatusFail($resp, MIDAS_INVALID_PARAMETER);
80-
96+
8197
// as a non admin
8298
foreach($nonAdmins as $nonAdmin)
8399
{
@@ -90,35 +106,35 @@ public function testGroupUserAddRemove()
90106
$this->_assertStatusFail($resp, MIDAS_INVALID_POLICY);
91107
}
92108
}
93-
94-
// ensure the user isn't already in the group
95-
$groupModel = MidasLoader::loadModel('Group');
96-
$changedUser = $userModel->load($validUserId);
97-
$group = $groupModel->load($validGroupId);
98-
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
99-
100-
// add the user to the group
101-
$this->resetAll();
102-
$this->params['token'] = $this->_loginAsUser($commAdmin);
103-
$this->params['method'] = $addMethod;
104-
$this->params['group_id'] = $validGroupId;
105-
$this->params['user_id'] = $validUserId;
106-
$resp = $this->_callJsonApi();
107-
$this->_assertStatusOk($resp);
108-
109-
// ensure the user is now in the group
110-
$this->assertTrue($groupModel->userInGroup($changedUser, $group), "This user is expected to be in the group");
111-
112-
// remove the user from the group
113-
$this->resetAll();
114-
$this->params['token'] = $this->_loginAsUser($commAdmin);
115-
$this->params['method'] = $removeMethod;
116-
$this->params['group_id'] = $validGroupId;
117-
$this->params['user_id'] = $validUserId;
118-
$resp = $this->_callJsonApi();
119-
$this->_assertStatusOk($resp);
120-
121-
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
109+
110+
// ensure the user isn't already in the group
111+
$groupModel = MidasLoader::loadModel('Group');
112+
$changedUser = $userModel->load($validUserId);
113+
$group = $groupModel->load($validGroupId);
114+
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
115+
116+
// add the user to the group
117+
$this->resetAll();
118+
$this->params['token'] = $this->_loginAsUser($commAdmin);
119+
$this->params['method'] = $addMethod;
120+
$this->params['group_id'] = $validGroupId;
121+
$this->params['user_id'] = $validUserId;
122+
$resp = $this->_callJsonApi();
123+
$this->_assertStatusOk($resp);
124+
125+
// ensure the user is now in the group
126+
$this->assertTrue($groupModel->userInGroup($changedUser, $group), "This user is expected to be in the group");
127+
128+
// remove the user from the group
129+
$this->resetAll();
130+
$this->params['token'] = $this->_loginAsUser($commAdmin);
131+
$this->params['method'] = $removeMethod;
132+
$this->params['group_id'] = $validGroupId;
133+
$this->params['user_id'] = $validUserId;
134+
$resp = $this->_callJsonApi();
135+
$this->_assertStatusOk($resp);
136+
137+
$this->assertFalse($groupModel->userInGroup($changedUser, $group), "This user is not expected to be in the group");
122138
}
123139

124140

0 commit comments

Comments
 (0)