@@ -65,6 +65,119 @@ public function testGetAccount()
6565 $ this ->assertArrayHasKey ('primary_email_address ' , $ result );
6666 }
6767
68+ /**
69+ * Test that get_form_subscriptions() returns the expected data
70+ * when a valid Form ID is specified.
71+ *
72+ * @since 1.0.0
73+ *
74+ * @return void
75+ */
76+ public function testGetFormSubscriptions ()
77+ {
78+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ]);
79+
80+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
81+ $ result = get_object_vars ($ result );
82+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
83+ $ this ->assertArrayHasKey ('page ' , $ result );
84+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
85+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
86+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
87+
88+ // Assert sort order is ascending.
89+ $ this ->assertGreaterThanOrEqual (
90+ $ result ['subscriptions ' ][0 ]->created_at ,
91+ $ result ['subscriptions ' ][1 ]->created_at
92+ );
93+ }
94+
95+ /**
96+ * Test that get_form_subscriptions() returns the expected data
97+ * when a valid Form ID is specified and the sort order is descending.
98+ *
99+ * @since 1.0.0
100+ *
101+ * @return void
102+ */
103+ public function testGetFormSubscriptionsWithDescSortOrder ()
104+ {
105+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'desc ' );
106+
107+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
108+ $ result = get_object_vars ($ result );
109+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
110+ $ this ->assertArrayHasKey ('page ' , $ result );
111+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
112+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
113+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
114+
115+ // Assert sort order.
116+ $ this ->assertLessThanOrEqual (
117+ $ result ['subscriptions ' ][0 ]->created_at ,
118+ $ result ['subscriptions ' ][1 ]->created_at
119+ );
120+ }
121+
122+ /**
123+ * Test that get_form_subscriptions() returns the expected data
124+ * when a valid Form ID is specified and the subscription status
125+ * is cancelled.
126+ *
127+ * @since 1.0.0
128+ *
129+ * @return void
130+ */
131+ public function testGetFormSubscriptionsWithCancelledSubscriberState ()
132+ {
133+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'asc ' , 'cancelled ' );
134+
135+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
136+ $ result = get_object_vars ($ result );
137+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
138+ $ this ->assertEquals ($ result ['total_subscriptions ' ], 0 );
139+ $ this ->assertArrayHasKey ('page ' , $ result );
140+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
141+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
142+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
143+ }
144+
145+ /**
146+ * Test that get_form_subscriptions() returns the expected data
147+ * when a valid Form ID is specified and the page is set to 2.
148+ *
149+ * @since 1.0.0
150+ *
151+ * @return void
152+ */
153+ public function testGetFormSubscriptionsWithPage ()
154+ {
155+ $ result = $ this ->api ->get_form_subscriptions ((int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], 'asc ' , 'active ' , 2 );
156+
157+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
158+ $ result = get_object_vars ($ result );
159+ $ this ->assertArrayHasKey ('total_subscriptions ' , $ result );
160+ $ this ->assertArrayHasKey ('page ' , $ result );
161+ $ this ->assertEquals ($ result ['page ' ], 2 );
162+ $ this ->assertArrayHasKey ('total_pages ' , $ result );
163+ $ this ->assertArrayHasKey ('subscriptions ' , $ result );
164+ $ this ->assertIsArray ($ result ['subscriptions ' ]);
165+ }
166+
167+ /**
168+ * Test that get_form_subscriptions() returns the expected data
169+ * when a valid Form ID is specified.
170+ *
171+ * @since 1.0.0
172+ *
173+ * @return void
174+ */
175+ public function testGetFormSubscriptionsWithInvalidFormID ()
176+ {
177+ $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
178+ $ result = $ this ->api ->get_form_subscriptions (12345 );
179+ }
180+
68181 /**
69182 * Test that get_sequences() returns the expected data.
70183 *
0 commit comments