1717 */
1818final class OAuth2SummitNotificationsApiControllerTest extends ProtectedApiTestCase
1919{
20- /**
21- * @param int $summit_id
22- * @return mixed
23- */
24- public function testGetApprovedSummitNotifications ($ summit_id = 27 )
20+ use InsertSummitTestData;
21+
22+ protected function setUp (): void
23+ {
24+ parent ::setUp ();
25+ self ::insertSummitTestData ();
26+ }
27+
28+ protected function tearDown (): void
29+ {
30+ self ::clearSummitTestData ();
31+ parent ::tearDown ();
32+ }
33+
34+ public function testGetApprovedSummitNotifications ()
2535 {
2636 $ params = [
27- 'id ' => $ summit_id ,
37+ 'id ' => self :: $ summit -> getId () ,
2838 'page ' => 1 ,
2939 'per_page ' => 15 ,
3040 'order ' => '+sent_date ' ,
@@ -35,13 +45,11 @@ public function testGetApprovedSummitNotifications($summit_id = 27)
3545 ];
3646
3747 $ headers = [
38-
3948 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
4049 "CONTENT_TYPE " => "application/json "
4150 ];
4251
43- $ response = $ this ->action
44- (
52+ $ response = $ this ->action (
4553 "GET " ,
4654 "OAuth2SummitNotificationsApiController@getAll " ,
4755 $ params ,
@@ -60,29 +68,21 @@ public function testGetApprovedSummitNotifications($summit_id = 27)
6068 return $ notifications ;
6169 }
6270
63- /**
64- * @param int $summit_id
65- * @return mixed
66- */
67- public function testGetSentSummitNotifications ($ summit_id = 27 )
71+ public function testGetSentSummitNotifications ()
6872 {
6973 $ params = [
70- 'id ' => $ summit_id ,
74+ 'id ' => self :: $ summit -> getId () ,
7175 'page ' => 1 ,
7276 'per_page ' => 15 ,
7377 'order ' => '+sent_date ' ,
74- // 'filter' => 'message=@Shanghai',
75- //'expand' => 'owner,approved_by',
7678 ];
7779
7880 $ headers = [
79-
8081 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
8182 "CONTENT_TYPE " => "application/json "
8283 ];
8384
84- $ response = $ this ->action
85- (
85+ $ response = $ this ->action (
8686 "GET " ,
8787 "OAuth2SummitNotificationsApiController@getAllApprovedByUser " ,
8888 $ params ,
@@ -101,93 +101,79 @@ public function testGetSentSummitNotifications($summit_id = 27)
101101 return $ notifications ;
102102 }
103103
104- /**
105- * @param int $summit_id
106- * @return mixed
107- */
108- public function testGetPushNotificationById ($ summit_id = 24 ){
109- $ notifications_response = $ this ->testGetApprovedSummitNotifications ($ summit_id );
104+ public function testAddPushNotificationEveryone (){
110105
111106 $ params = [
112- 'id ' => $ summit_id ,
113- 'notification_id ' => $ notifications_response ->data [0 ]->id
107+ 'id ' => self ::$ summit ->getId (),
114108 ];
115109
116- $ headers = [
110+ $ message = str_random (16 ).'_message ' ;
111+
112+ $ data = [
113+ 'message ' => $ message ,
114+ 'channel ' => \models \summit \SummitPushNotificationChannel::Everyone,
115+ 'platform ' => \models \summit \SummitPushNotification::PlatformMobile,
116+ ];
117117
118+ $ headers = [
118119 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
119- "CONTENT_TYPE " => "application/json "
120+ "CONTENT_TYPE " => "application/json "
120121 ];
121122
122- $ response = $ this ->action
123- (
124- "GET " ,
125- "OAuth2SummitNotificationsApiController@getById " ,
123+ $ response = $ this ->action (
124+ "POST " ,
125+ "OAuth2SummitNotificationsApiController@addPushNotification " ,
126126 $ params ,
127127 [],
128128 [],
129129 [],
130- $ headers
130+ $ headers ,
131+ json_encode ($ data )
131132 );
132133
133134 $ content = $ response ->getContent ();
134- $ this ->assertResponseStatus (200 );
135-
135+ $ this ->assertResponseStatus (201 );
136136 $ notification = json_decode ($ content );
137137 $ this ->assertTrue (!is_null ($ notification ));
138-
139138 return $ notification ;
140139 }
141140
142- /**
143- * @param int $summit_id
144- * @return mixed
145- */
146- public function testAddPushNotificationEveryone ($ summit_id = 24 ){
141+ public function testGetPushNotificationById (){
142+ $ notification = $ this ->testAddPushNotificationEveryone ();
147143
148144 $ params = [
149- 'id ' => $ summit_id ,
150- ];
151-
152- $ message = str_random (16 ).'_message ' ;
153-
154- $ data = [
155- 'message ' => $ message ,
156- 'channel ' => \models \summit \SummitPushNotificationChannel::Everyone,
157- 'platform ' => \models \summit \SummitPushNotification::PlatformMobile,
145+ 'id ' => self ::$ summit ->getId (),
146+ 'notification_id ' => $ notification ->id
158147 ];
159148
160149 $ headers = [
161150 "HTTP_Authorization " => " Bearer " . $ this ->access_token ,
162- "CONTENT_TYPE " => "application/json "
151+ "CONTENT_TYPE " => "application/json "
163152 ];
164153
165154 $ response = $ this ->action (
166- "POST " ,
167- "OAuth2SummitNotificationsApiController@addPushNotification " ,
155+ "GET " ,
156+ "OAuth2SummitNotificationsApiController@getById " ,
168157 $ params ,
169158 [],
170159 [],
171160 [],
172- $ headers ,
173- json_encode ($ data )
161+ $ headers
174162 );
175163
176164 $ content = $ response ->getContent ();
177- $ this ->assertResponseStatus (201 );
165+ $ this ->assertResponseStatus (200 );
166+
178167 $ notification = json_decode ($ content );
179168 $ this ->assertTrue (!is_null ($ notification ));
169+
180170 return $ notification ;
181171 }
182172
183- /**
184- * @param int $summit_id
185- * @return mixed
186- */
187- public function testAddPushNotificationMembersFail ($ summit_id = 24 ){
173+ public function testAddPushNotificationMembersFail (){
188174
189175 $ params = [
190- 'id ' => $ summit_id ,
176+ 'id ' => self :: $ summit -> getId () ,
191177 ];
192178
193179 $ message = str_random (16 ).'_message ' ;
@@ -218,14 +204,10 @@ public function testAddPushNotificationMembersFail($summit_id = 24){
218204 $ this ->assertResponseStatus (412 );
219205 }
220206
221- /**
222- * @param int $summit_id
223- * @return mixed
224- */
225- public function testAddPushNotificationMembers ($ summit_id = 24 ){
207+ public function testAddPushNotificationMembers (){
226208
227209 $ params = [
228- 'id ' => $ summit_id ,
210+ 'id ' => self :: $ summit -> getId () ,
229211 ];
230212
231213 $ message = str_random (16 ).'_message ' ;
@@ -234,7 +216,7 @@ public function testAddPushNotificationMembers($summit_id = 24){
234216 'message ' => $ message ,
235217 'channel ' => \models \summit \SummitPushNotificationChannel::Members,
236218 'platform ' => \models \summit \SummitPushNotification::PlatformMobile,
237- 'recipient_ids ' => [13867 ]
219+ 'recipient_ids ' => [self :: $ member -> getId () ]
238220 ];
239221
240222 $ headers = [
@@ -259,4 +241,4 @@ public function testAddPushNotificationMembers($summit_id = 24){
259241 $ this ->assertTrue (!is_null ($ notification ));
260242 return $ notification ;
261243 }
262- }
244+ }
0 commit comments