@@ -86,6 +86,131 @@ public function testGetSequences()
8686 $ this ->assertArrayHasKey ('created_at ' , $ sequence );
8787 }
8888
89+ /**
90+ * Test that add_subscriber_to_sequence() returns the expected data.
91+ *
92+ * @since 1.0.0
93+ *
94+ * @return void
95+ */
96+ public function testAddSubscriberToSequence ()
97+ {
98+ $ result = $ this ->api ->add_subscriber_to_sequence (
99+ $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ],
100+ $ this ->generateEmailAddress ()
101+ );
102+ $ this ->assertInstanceOf ('stdClass ' , $ result );
103+ $ this ->assertArrayHasKey ('subscription ' , get_object_vars ($ result ));
104+ }
105+
106+ /**
107+ * Test that add_subscriber_to_sequence() throws a ClientException when an invalid
108+ * sequence is specified.
109+ *
110+ * @since 1.0.0
111+ *
112+ * @return void
113+ */
114+ public function testAddSubscriberToSequenceWithInvalidSequenceID ()
115+ {
116+ $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
117+ $ result = $ this ->api ->add_subscriber_to_sequence (12345 , $ this ->generateEmailAddress ());
118+ }
119+
120+ /**
121+ * Test that add_subscriber_to_sequence() throws a ClientException when an invalid
122+ * email address is specified.
123+ *
124+ * @since 1.0.0
125+ *
126+ * @return void
127+ */
128+ public function testAddSubscriberToSequenceWithInvalidEmailAddress ()
129+ {
130+ $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
131+ $ result = $ this ->api ->add_subscriber_to_sequence ($ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ], 'not-an-email-address ' );
132+ }
133+
134+ /**
135+ * Test that add_subscriber_to_sequence() returns the expected data
136+ * when a first_name parameter is included.
137+ *
138+ * @since 1.0.0
139+ *
140+ * @return void
141+ */
142+ public function testAddSubscriberToSequenceWithFirstName ()
143+ {
144+ $ emailAddress = $ this ->generateEmailAddress ();
145+ $ firstName = 'First Name ' ;
146+ $ result = $ this ->api ->add_subscriber_to_sequence ($ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ], $ emailAddress , $ firstName );
147+
148+ $ this ->assertInstanceOf ('stdClass ' , $ result );
149+ $ this ->assertArrayHasKey ('subscription ' , get_object_vars ($ result ));
150+
151+ // Fetch subscriber from API to confirm the first name was saved.
152+ $ subscriber = $ this ->api ->get_subscriber ($ result ->subscription ->subscriber ->id );
153+ $ this ->assertEquals ($ subscriber ->subscriber ->email_address , $ emailAddress );
154+ $ this ->assertEquals ($ subscriber ->subscriber ->first_name , $ firstName );
155+ }
156+
157+ /**
158+ * Test that add_subscriber_to_sequence() returns the expected data
159+ * when custom field data is included.
160+ *
161+ * @since 1.0.0
162+ *
163+ * @return void
164+ */
165+ public function testAddSubscriberToSequenceWithCustomFields ()
166+ {
167+ $ result = $ this ->api ->add_subscriber_to_sequence (
168+ $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ],
169+ $ this ->generateEmailAddress (),
170+ 'First Name ' ,
171+ [
172+ 'last_name ' => 'Last Name ' ,
173+ ]
174+ );
175+
176+ // Check subscription object returned.
177+ $ this ->assertInstanceOf ('stdClass ' , $ result );
178+ $ this ->assertArrayHasKey ('subscription ' , get_object_vars ($ result ));
179+
180+ // Fetch subscriber from API to confirm the custom fields were saved.
181+ $ subscriber = $ this ->api ->get_subscriber ($ result ->subscription ->subscriber ->id );
182+ $ this ->assertEquals ($ subscriber ->subscriber ->fields ->last_name , 'Last Name ' );
183+ }
184+
185+ /**
186+ * Test that add_subscriber_to_sequence() returns the expected data
187+ * when custom field data is included.
188+ *
189+ * @since 1.0.0
190+ *
191+ * @return void
192+ */
193+ public function testAddSubscriberToSequenceWithTagID ()
194+ {
195+ $ result = $ this ->api ->add_subscriber_to_sequence (
196+ $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ],
197+ $ this ->generateEmailAddress (),
198+ 'First Name ' ,
199+ [],
200+ [
201+ (int ) $ _ENV ['CONVERTKIT_API_TAG_ID ' ]
202+ ]
203+ );
204+
205+ // Check subscription object returned.
206+ $ this ->assertInstanceOf ('stdClass ' , $ result );
207+ $ this ->assertArrayHasKey ('subscription ' , get_object_vars ($ result ));
208+
209+ // Fetch subscriber tags from API to confirm the tag saved.
210+ $ subscriberTags = $ this ->api ->get_subscriber_tags ($ result ->subscription ->subscriber ->id );
211+ // @TODO.
212+ }
213+
89214 /**
90215 * Test that get_sequence_subscriptions() returns the expected data.
91216 *
@@ -143,20 +268,6 @@ public function testGetSequenceSubscriptionsWithDescSortOrder()
143268 );
144269 }
145270
146- /**
147- * Test that get_sequence_subscriptions() throws a ClientException when an invalid
148- * sequence ID is specified.
149- *
150- * @since 1.0.0
151- *
152- * @return void
153- */
154- public function testGetSequenceSubscriptionsWithInvalidSequenceID ()
155- {
156- $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
157- $ result = $ this ->api ->get_sequence_subscriptions (12345 );
158- }
159-
160271 /**
161272 * Test that get_sequence_subscriptions() throws a ClientException when an invalid
162273 * sort order is specified.
@@ -172,48 +283,17 @@ public function testGetSequenceSubscriptionsWithInvalidSortOrder()
172283 }
173284
174285 /**
175- * Test that add_subscriber_to_sequence() returns the expected data.
176- *
177- * @since 1.0.0
178- *
179- * @return void
180- */
181- public function testAddSubscriberToSequence ()
182- {
183- $ result = $ this ->api ->add_subscriber_to_sequence (
184- $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ],
185- $ this ->generateEmailAddress ()
186- );
187- $ this ->assertInstanceOf ('stdClass ' , $ result );
188- $ this ->assertArrayHasKey ('subscription ' , get_object_vars ($ result ));
189- }
190-
191- /**
192- * Test that add_subscriber_to_sequence() throws a ClientException when an invalid
193- * sequence is specified.
194- *
195- * @since 1.0.0
196- *
197- * @return void
198- */
199- public function testAddSubscriberToSequenceWithInvalidSequenceID ()
200- {
201- $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
202- $ result = $ this ->api ->add_subscriber_to_sequence (12345 , $ this ->generateEmailAddress ());
203- }
204-
205- /**
206- * Test that add_subscriber_to_sequence() throws a ClientException when an invalid
207- * email address is specified.
286+ * Test that get_sequence_subscriptions() throws a ClientException when an invalid
287+ * sequence ID is specified.
208288 *
209289 * @since 1.0.0
210290 *
211291 * @return void
212292 */
213- public function testAddSubscriberToSequenceWithInvalidEmailAddress ()
293+ public function testGetSequenceSubscriptionsWithInvalidSequenceID ()
214294 {
215295 $ this ->expectException (GuzzleHttp \Exception \ClientException::class);
216- $ result = $ this ->api ->add_subscriber_to_sequence ( $ _ENV [ ' CONVERTKIT_API_SEQUENCE_ID ' ], ' not-an-email-address ' );
296+ $ result = $ this ->api ->get_sequence_subscriptions ( 12345 );
217297 }
218298
219299 /**
0 commit comments