@@ -114,6 +114,119 @@ public function testGetLandingPages()
114114 $ this ->assertArrayHasKey ('archived ' , $ landingPage );
115115 }
116116
117+ /**
118+ * Test that get_form_subscriptions() returns the expected data
119+ * when a valid Form ID is specified.
120+ *
121+ * @since 1.0.0
122+ *
123+ * @return void
124+ */
125+ public function testGetFormSubscriptions ()
126+ {
127+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ]);
128+
129+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
130+ $ result = get_object_vars ($ result );
131+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
132+ $ this ->assertArrayHasKey ('page ' , $ result );
133+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
134+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
135+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
136+
137+ // Assert sort order is ascending.
138+ $ this ->assertGreaterThanOrEqual (
139+ $ result ['subscriptions ' ][0 ]->created_at ,
140+ $ result ['subscriptions ' ][1 ]->created_at
141+ );
142+ }
143+
144+ /**
145+ * Test that get_form_subscriptions() returns the expected data
146+ * when a valid Form ID is specified and the sort order is descending.
147+ *
148+ * @since 1.0.0
149+ *
150+ * @return void
151+ */
152+ public function testGetFormSubscriptionsWithDescSortOrder ()
153+ {
154+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'desc ' );
155+
156+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
157+ $ result = get_object_vars ($ result );
158+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
159+ $ this ->assertArrayHasKey ('page ' , $ result );
160+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
161+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
162+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
163+
164+ // Assert sort order.
165+ $ this ->assertLessThanOrEqual (
166+ $ result ['subscriptions ' ][0 ]->created_at ,
167+ $ result ['subscriptions ' ][1 ]->created_at
168+ );
169+ }
170+
171+ /**
172+ * Test that get_form_subscriptions() returns the expected data
173+ * when a valid Form ID is specified and the subscription status
174+ * is cancelled.
175+ *
176+ * @since 1.0.0
177+ *
178+ * @return void
179+ */
180+ public function testGetFormSubscriptionsWithCancelledSubscriberState ()
181+ {
182+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'asc ' , 'cancelled ' );
183+
184+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
185+ $ result = get_object_vars ($ result );
186+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
187+ $ this ->assertEquals ($ result ['total_subscriptions ' ], 0 );
188+ $ this ->assertArrayHasKey ('page ' , $ result );
189+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
190+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
191+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
192+ }
193+
194+ /**
195+ * Test that get_form_subscriptions() returns the expected data
196+ * when a valid Form ID is specified and the page is set to 2.
197+ *
198+ * @since 1.0.0
199+ *
200+ * @return void
201+ */
202+ public function testGetFormSubscriptionsWithPage ()
203+ {
204+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'asc ' , 'active ' , 2 );
205+
206+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
207+ $ result = get_object_vars ($ result );
208+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
209+ $ this ->assertArrayHasKey ('page ' , $ result );
210+ $ this ->assertEquals ($ result ['page ' ], 2 );
211+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
212+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
213+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
214+ }
215+
216+ /**
217+ * Test that get_form_subscriptions() returns the expected data
218+ * when a valid Form ID is specified.
219+ *
220+ * @since 1.0.0
221+ *
222+ * @return void
223+ */
224+ public function testGetFormSubscriptionsWithInvalidFormID ()
225+ {
226+ $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
227+ $ result = $ this ->api ->get_form_subscriptions (12345 );
228+ }
229+
117230 /**
118231 * Test that get_sequences() returns the expected data.
119232 *
0 commit comments