@@ -65,6 +65,168 @@ public function testGetAccount()
6565 $ this ->assertArrayHasKey ('primary_email_address ' , $ result );
6666 }
6767
68+ /**
69+ * Test that get_forms() returns the expected data.
70+ *
71+ * @since 1.0.0
72+ *
73+ * @return void
74+ */
75+ public function testGetForms ()
76+ {
77+ $ result = $ this ->api ->get_forms ();
78+ $ this ->assertIsArray ($ result );
79+
80+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
81+ $ form = get_object_vars ($ result [0 ]);
82+ $ this ->assertArrayHasKey ('id ' , $ form );
83+ $ this ->assertArrayHasKey ('name ' , $ form );
84+ $ this ->assertArrayHasKey ('created_at ' , $ form );
85+ $ this ->assertArrayHasKey ('type ' , $ form );
86+ $ this ->assertArrayHasKey ('format ' , $ form );
87+ $ this ->assertArrayHasKey ('embed_js ' , $ form );
88+ $ this ->assertArrayHasKey ('embed_url ' , $ form );
89+ $ this ->assertArrayHasKey ('archived ' , $ form );
90+ }
91+
92+ /**
93+ * Test that get_landing_pages() returns the expected data.
94+ *
95+ * @since 1.0.0
96+ *
97+ * @return void
98+ */
99+ public function testGetLandingPages ()
100+ {
101+ $ result = $ this ->api ->get_landing_pages ();
102+ $ this ->assertIsArray ($ result );
103+
104+ // Convert to array to check for keys, as assertObjectHasAttribute() will be deprecated in PHPUnit 10.
105+ $ landingPage = get_object_vars ($ result [0 ]);
106+ $ this ->assertArrayHasKey ('id ' , $ landingPage );
107+ $ this ->assertArrayHasKey ('name ' , $ landingPage );
108+ $ this ->assertArrayHasKey ('created_at ' , $ landingPage );
109+ $ this ->assertArrayHasKey ('type ' , $ landingPage );
110+ $ this ->assertEquals ('hosted ' , $ landingPage ['type ' ]);
111+ $ this ->assertArrayHasKey ('format ' , $ landingPage );
112+ $ this ->assertArrayHasKey ('embed_js ' , $ landingPage );
113+ $ this ->assertArrayHasKey ('embed_url ' , $ landingPage );
114+ $ this ->assertArrayHasKey ('archived ' , $ landingPage );
115+ }
116+
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+
68230 /**
69231 * Test that get_sequences() returns the expected data.
70232 *
0 commit comments