@@ -604,6 +604,38 @@ public function testGetAccessTokenByInvalidAPIKeyAndSecret()
604604 $ this ->assertEquals ('Authorization Failed: API Secret not valid ' , $ result ->get_error_message ());
605605 }
606606
607+ /**
608+ * Test that fetching an Access Token using an invalid client ID returns a WP_Error.
609+ *
610+ * @since 2.0.7
611+ */
612+ public function testGetAccessTokenByAPIKeyAndSecretWithInvalidClientID ()
613+ {
614+ $ api = new ConvertKit_API_V4 ( 'invalidClientID ' , $ _ENV ['CONVERTKIT_OAUTH_REDIRECT_URI ' ] );
615+ $ result = $ api ->get_access_token_by_api_key_and_secret (
616+ $ _ENV ['CONVERTKIT_API_KEY ' ],
617+ $ _ENV ['CONVERTKIT_API_SECRET ' ]
618+ );
619+ $ this ->assertInstanceOf (WP_Error::class, $ result );
620+ $ this ->assertEquals ($ result ->get_error_code (), $ this ->errorCode );
621+ }
622+
623+ /**
624+ * Test that fetching an Access Token using a blank client ID returns a WP_Error.
625+ *
626+ * @since 2.0.7
627+ */
628+ public function testGetAccessTokenByAPIKeyAndSecretWithBlankClientID ()
629+ {
630+ $ api = new ConvertKit_API_V4 ( '' , $ _ENV ['CONVERTKIT_OAUTH_REDIRECT_URI ' ] );
631+ $ result = $ api ->get_access_token_by_api_key_and_secret (
632+ $ _ENV ['CONVERTKIT_API_KEY ' ],
633+ $ _ENV ['CONVERTKIT_API_SECRET ' ]
634+ );
635+ $ this ->assertInstanceOf (WP_Error::class, $ result );
636+ $ this ->assertEquals ($ result ->get_error_code (), $ this ->errorCode );
637+ }
638+
607639 /**
608640 * Test that supplying valid API credentials to the API class returns the expected account information.
609641 *
@@ -756,8 +788,9 @@ public function testGetGrowthStatsWithStartDate()
756788 $ this ->assertArrayHasKey ('ending ' , $ result ['stats ' ]);
757789
758790 // Assert start and end dates were honored.
759- $ this ->assertEquals ($ result ['stats ' ]['starting ' ], $ starting ->format ('Y-m-d ' ) . 'T00:00:00-05:00 ' );
760- $ this ->assertEquals ($ result ['stats ' ]['ending ' ], $ ending ->format ('Y-m-d ' ) . 'T23:59:59-05:00 ' );
791+ $ timezone = ( new DateTime () )->setTimezone (new DateTimeZone ('America/New_York ' ))->format ('P ' ); // Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
792+ $ this ->assertEquals ($ result ['stats ' ]['starting ' ], $ starting ->format ('Y-m-d ' ) . 'T00:00:00 ' . $ timezone );
793+ $ this ->assertEquals ($ result ['stats ' ]['ending ' ], $ ending ->format ('Y-m-d ' ) . 'T23:59:59 ' . $ timezone );
761794 }
762795
763796 /**
@@ -790,8 +823,9 @@ public function testGetGrowthStatsWithEndDate()
790823 $ this ->assertArrayHasKey ('ending ' , $ result ['stats ' ]);
791824
792825 // Assert start and end dates were honored.
793- $ this ->assertEquals ($ result ['stats ' ]['starting ' ], $ starting ->format ('Y-m-d ' ) . 'T00:00:00-05:00 ' );
794- $ this ->assertEquals ($ result ['stats ' ]['ending ' ], $ ending ->format ('Y-m-d ' ) . 'T23:59:59-05:00 ' );
826+ $ timezone = ( new DateTime () )->setTimezone (new DateTimeZone ('America/New_York ' ))->format ('P ' ); // Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
827+ $ this ->assertEquals ($ result ['stats ' ]['starting ' ], $ starting ->format ('Y-m-d ' ) . 'T00:00:00 ' . $ timezone );
828+ $ this ->assertEquals ($ result ['stats ' ]['ending ' ], $ ending ->format ('Y-m-d ' ) . 'T23:59:59 ' . $ timezone );
795829 }
796830
797831 /**
@@ -1249,7 +1283,7 @@ public function testGetFormSubscriptionsWithBouncedSubscriberState()
12491283 */
12501284 public function testGetFormSubscriptionsWithAddedAfterParam ()
12511285 {
1252- $ date = new \DateTime ('2024 -01-01 ' );
1286+ $ date = new \DateTime ('2022 -01-01 ' );
12531287 $ result = $ this ->api ->get_form_subscriptions (
12541288 (int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], // Form ID.
12551289 'active ' , // Subscriber state.
@@ -1312,7 +1346,7 @@ public function testGetFormSubscriptionsWithAddedBeforeParam()
13121346 */
13131347 public function testGetFormSubscriptionsWithCreatedAfterParam ()
13141348 {
1315- $ date = new \DateTime ('2024 -01-01 ' );
1349+ $ date = new \DateTime ('2022 -01-01 ' );
13161350 $ result = $ this ->api ->get_form_subscriptions (
13171351 (int ) $ _ENV ['CONVERTKIT_API_FORM_ID ' ], // Form ID.
13181352 'active ' , // Subscriber state.
@@ -2272,7 +2306,7 @@ public function testGetSequenceSubscriptionsWithBouncedSubscriberState()
22722306 */
22732307 public function testGetSequenceSubscriptionsWithAddedAfterParam ()
22742308 {
2275- $ date = new \DateTime ('2024 -01-01 ' );
2309+ $ date = new \DateTime ('2022 -01-01 ' );
22762310 $ result = $ this ->api ->get_sequence_subscriptions (
22772311 $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ], // Sequence ID.
22782312 'active ' , // Subscriber state.
@@ -2335,7 +2369,7 @@ public function testGetSequenceSubscriptionsWithAddedBeforeParam()
23352369 */
23362370 public function testGetSequenceSubscriptionsWithCreatedAfterParam ()
23372371 {
2338- $ date = new \DateTime ('2024 -01-01 ' );
2372+ $ date = new \DateTime ('2022 -01-01 ' );
23392373 $ result = $ this ->api ->get_sequence_subscriptions (
23402374 $ _ENV ['CONVERTKIT_API_SEQUENCE_ID ' ], // Sequence ID.
23412375 'active ' , // Subscriber state.
@@ -2441,7 +2475,7 @@ public function testGetSequenceSubscriptionsPagination()
24412475
24422476 // Assert has_previous_page and has_next_page are correct.
24432477 $ this ->assertTrue ($ result ['pagination ' ]['has_previous_page ' ]);
2444- $ this ->assertTrue ($ result ['pagination ' ]['has_next_page ' ]);
2478+ $ this ->assertFalse ($ result ['pagination ' ]['has_next_page ' ]);
24452479
24462480 // Use pagination to fetch previous page.
24472481 $ result = $ this ->api ->get_sequence_subscriptions (
@@ -2654,7 +2688,7 @@ public function testCreateTagBlank()
26542688 }
26552689
26562690 /**
2657- * Test that create_tag() returns a WP_Error when creating
2691+ * Test that create_tag() returns the expected data when creating
26582692 * a tag that already exists.
26592693 *
26602694 * @since 1.0.0
@@ -2664,8 +2698,12 @@ public function testCreateTagBlank()
26642698 public function testCreateTagThatExists ()
26652699 {
26662700 $ result = $ this ->api ->create_tag ($ _ENV ['CONVERTKIT_API_TAG_NAME ' ]);
2667- $ this ->assertInstanceOf (WP_Error::class, $ result );
2668- $ this ->assertEquals ($ result ->get_error_code (), $ this ->errorCode );
2701+
2702+ // Assert response contains correct data.
2703+ $ this ->assertArrayHasKey ('id ' , $ result ['tag ' ]);
2704+ $ this ->assertArrayHasKey ('name ' , $ result ['tag ' ]);
2705+ $ this ->assertArrayHasKey ('created_at ' , $ result ['tag ' ]);
2706+ $ this ->assertEquals ($ result ['tag ' ]['name ' ], $ _ENV ['CONVERTKIT_API_TAG_NAME ' ]);
26692707 }
26702708
26712709 /**
@@ -2734,8 +2772,8 @@ public function testCreateTagsBlank()
27342772 }
27352773
27362774 /**
2737- * Test that create_tags() returns a WP_Error when creating
2738- * tags that already exists .
2775+ * Test that create_tags() returns the expected data when creating
2776+ * tags that already exist .
27392777 *
27402778 * @since 2.0.0
27412779 *
@@ -2750,8 +2788,10 @@ public function testCreateTagsThatExist()
27502788 ]
27512789 );
27522790
2753- // Assert failures.
2754- $ this ->assertCount (2 , $ result ['failures ' ]);
2791+ // Assert existing tags are returned.
2792+ $ this ->assertCount (2 , $ result ['tags ' ]);
2793+ $ this ->assertEquals ($ result ['tags ' ][1 ]['name ' ], $ _ENV ['CONVERTKIT_API_TAG_NAME ' ]);
2794+ $ this ->assertEquals ($ result ['tags ' ][0 ]['name ' ], $ _ENV ['CONVERTKIT_API_TAG_NAME_2 ' ]);
27552795 }
27562796
27572797 /**
@@ -3127,7 +3167,7 @@ public function testGetTagSubscriptionsWithBouncedSubscriberState()
31273167 */
31283168 public function testGetTagSubscriptionsWithTaggedAfterParam ()
31293169 {
3130- $ date = new \DateTime ('2024 -01-01 ' );
3170+ $ date = new \DateTime ('2022 -01-01 ' );
31313171 $ result = $ this ->api ->get_tag_subscriptions (
31323172 (int ) $ _ENV ['CONVERTKIT_API_TAG_ID ' ], // Tag ID.
31333173 'active ' , // Subscriber state.
@@ -3190,7 +3230,7 @@ public function testGetTagSubscriptionsWithTaggedBeforeParam()
31903230 */
31913231 public function testGetTagSubscriptionsWithCreatedAfterParam ()
31923232 {
3193- $ date = new \DateTime ('2024 -01-01 ' );
3233+ $ date = new \DateTime ('2022 -01-01 ' );
31943234 $ result = $ this ->api ->get_tag_subscriptions (
31953235 (int ) $ _ENV ['CONVERTKIT_API_TAG_ID ' ], // Tag ID.
31963236 'active ' , // Subscriber state.
@@ -3450,7 +3490,7 @@ public function testGetSubscribersWithBouncedSubscriberState()
34503490 */
34513491 public function testGetSubscribersWithCreatedAfterParam ()
34523492 {
3453- $ date = new \DateTime ('2024 -01-01 ' );
3493+ $ date = new \DateTime ('2022 -01-01 ' );
34543494 $ result = $ this ->api ->get_subscribers (
34553495 'active ' , // Subscriber state.
34563496 '' , // Email address.
@@ -3507,7 +3547,7 @@ public function testGetSubscribersWithCreatedBeforeParam()
35073547 */
35083548 public function testGetSubscribersWithUpdatedAfterParam ()
35093549 {
3510- $ date = new \DateTime ('2024 -01-01 ' );
3550+ $ date = new \DateTime ('2022 -01-01 ' );
35113551 $ result = $ this ->api ->get_subscribers (
35123552 'active ' , // Subscriber state.
35133553 '' , // Email address.
0 commit comments