@@ -30,9 +30,9 @@ public function setUp()
30
30
/** Test adding and removing a user from a group */
31
31
public function testGroupUserAddRemove ()
32
32
{
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 );
36
36
37
37
$ communityModel = MidasLoader::loadModel ('Community ' );
38
38
$ comm2001 = $ communityModel ->load ('2001 ' );
@@ -48,7 +48,7 @@ public function testGroupUserAddRemove()
48
48
$ invalidGroupId = '-10 ' ;
49
49
$ validUserId = '2 ' ;
50
50
$ invalidUserId = '-10 ' ;
51
-
51
+
52
52
// test all the failure cases
53
53
foreach ($ methods as $ method )
54
54
{
@@ -60,6 +60,22 @@ public function testGroupUserAddRemove()
60
60
$ resp = $ this ->_callJsonApi ();
61
61
$ this ->_assertStatusFail ($ resp , MIDAS_INVALID_POLICY );
62
62
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
+
63
79
// an invalid group
64
80
$ this ->resetAll ();
65
81
$ this ->params ['token ' ] = $ this ->_loginAsUser ($ commAdmin );
@@ -68,7 +84,7 @@ public function testGroupUserAddRemove()
68
84
$ this ->params ['user_id ' ] = $ validUserId ;
69
85
$ resp = $ this ->_callJsonApi ();
70
86
$ this ->_assertStatusFail ($ resp , MIDAS_INVALID_PARAMETER );
71
-
87
+
72
88
// an invalid user
73
89
$ this ->resetAll ();
74
90
$ this ->params ['token ' ] = $ this ->_loginAsUser ($ commAdmin );
@@ -77,7 +93,7 @@ public function testGroupUserAddRemove()
77
93
$ this ->params ['user_id ' ] = $ invalidUserId ;
78
94
$ resp = $ this ->_callJsonApi ();
79
95
$ this ->_assertStatusFail ($ resp , MIDAS_INVALID_PARAMETER );
80
-
96
+
81
97
// as a non admin
82
98
foreach ($ nonAdmins as $ nonAdmin )
83
99
{
@@ -90,35 +106,35 @@ public function testGroupUserAddRemove()
90
106
$ this ->_assertStatusFail ($ resp , MIDAS_INVALID_POLICY );
91
107
}
92
108
}
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 " );
122
138
}
123
139
124
140
0 commit comments