@@ -17,6 +17,16 @@ class ListControllerTest extends AbstractControllerTest
1717 */
1818 const LISTS_TABLE_NAME = 'phplist_list ' ;
1919
20+ /**
21+ * @var string
22+ */
23+ const SUBSCRIBER_TABLE_NAME = 'phplist_user_user ' ;
24+
25+ /**
26+ * @var string
27+ */
28+ const SUBSCRIPTION_TABLE_NAME = 'phplist_listuser ' ;
29+
2030 /**
2131 * @test
2232 */
@@ -100,4 +110,99 @@ public function getListsWithCurrentSessionKeyReturnsListData()
100110 ]
101111 );
102112 }
113+
114+ /**
115+ * @test
116+ */
117+ public function getListMembersWithoutSessionKeyReturnsForbiddenStatus ()
118+ {
119+ $ this ->client ->request ('get ' , '/api/v2/lists/1/members ' );
120+
121+ $ this ->assertHttpForbidden ();
122+ }
123+
124+ /**
125+ * @test
126+ */
127+ public function getListMembersWithExpiredSessionKeyReturnsForbiddenStatus ()
128+ {
129+ $ this ->getDataSet ()->addTable (self ::ADMINISTRATOR_TABLE_NAME , __DIR__ . '/Fixtures/Administrator.csv ' );
130+ $ this ->getDataSet ()->addTable (self ::TOKEN_TABLE_NAME , __DIR__ . '/Fixtures/AdministratorToken.csv ' );
131+ $ this ->applyDatabaseChanges ();
132+
133+ $ this ->client ->request (
134+ 'get ' ,
135+ '/api/v2/lists/1/members ' ,
136+ [],
137+ [],
138+ ['PHP_AUTH_USER ' => 'unused ' , 'PHP_AUTH_PW ' => 'cfdf64eecbbf336628b0f3071adba763 ' ]
139+ );
140+
141+ $ this ->assertHttpForbidden ();
142+ }
143+
144+ /**
145+ * @test
146+ */
147+ public function getListMembersWithCurrentSessionKeyForInexistentListReturnsNotFoundStatus ()
148+ {
149+ $ this ->authenticatedJsonRequest ('get ' , '/api/v2/lists/999/members ' );
150+
151+ $ this ->assertHttpNotFound ();
152+ }
153+
154+ /**
155+ * @test
156+ */
157+ public function getListMembersWithCurrentSessionKeyForExistingListReturnsOkayStatus ()
158+ {
159+ $ this ->getDataSet ()->addTable (self ::LISTS_TABLE_NAME , __DIR__ . '/Fixtures/SubscriberList.csv ' );
160+ $ this ->applyDatabaseChanges ();
161+
162+ $ this ->authenticatedJsonRequest ('get ' , '/api/v2/lists/1/members ' );
163+
164+ $ this ->assertHttpOkay ();
165+ }
166+
167+ /**
168+ * @test
169+ */
170+ public function getListMembersWithCurrentSessionKeyForExistingListWithoutSubscribersReturnsEmptyArray ()
171+ {
172+ $ this ->getDataSet ()->addTable (self ::LISTS_TABLE_NAME , __DIR__ . '/Fixtures/SubscriberList.csv ' );
173+ $ this ->applyDatabaseChanges ();
174+
175+ $ this ->authenticatedJsonRequest ('get ' , '/api/v2/lists/1/members ' );
176+
177+ $ this ->assertJsonResponseContentEquals ([]);
178+ }
179+
180+ /**
181+ * @test
182+ */
183+ public function getListMembersWithCurrentSessionKeyForExistingListWithSubscribersReturnsSubscribers ()
184+ {
185+ $ this ->getDataSet ()->addTable (self ::LISTS_TABLE_NAME , __DIR__ . '/Fixtures/SubscriberList.csv ' );
186+ $ this ->getDataSet ()->addTable (self ::SUBSCRIBER_TABLE_NAME , __DIR__ . '/Fixtures/Subscriber.csv ' );
187+ $ this ->getDataSet ()->addTable (self ::SUBSCRIPTION_TABLE_NAME , __DIR__ . '/Fixtures/Subscription.csv ' );
188+ $ this ->applyDatabaseChanges ();
189+
190+ $ this ->authenticatedJsonRequest ('get ' , '/api/v2/lists/2/members ' );
191+
192+ $ this ->assertJsonResponseContentEquals (
193+ [
194+ [
195+ 'creation_date ' => '2016-07-22T15:01:17+00:00 ' ,
196+ 'email ' => 'oliver@example.com ' ,
197+ 'confirmed ' => true ,
198+ 'blacklisted ' => true ,
199+ 'bounce_count ' => 17 ,
200+ 'unique_id ' => '95feb7fe7e06e6c11ca8d0c48cb46e89 ' ,
201+ 'html_email ' => true ,
202+ 'disabled ' => true ,
203+ 'id ' => 1 ,
204+ ]
205+ ]
206+ );
207+ }
103208}
0 commit comments