@@ -3791,7 +3791,102 @@ public function testDestroyBroadcastWithInvalidBroadcastID()
37913791 }
37923792
37933793 /**
3794- * Test that create_webhook() and destroy_webhook() works.
3794+ * Test that get_webhooks() returns the expected data.
3795+ *
3796+ * @since 2.0.0
3797+ *
3798+ * @return void
3799+ */
3800+ public function testGetWebhooks ()
3801+ {
3802+ $ result = $ this ->api ->get_webhooks ();
3803+
3804+ // Assert webhooks and pagination exist.
3805+ $ this ->assertDataExists ($ result , 'webhooks ' );
3806+ $ this ->assertPaginationExists ($ result );
3807+ }
3808+
3809+ /**
3810+ * Test that get_webhooks() returns the expected data
3811+ * when the total count is included.
3812+ *
3813+ * @since 2.0.0
3814+ *
3815+ * @return void
3816+ */
3817+ public function testGetWebhooksWithTotalCount ()
3818+ {
3819+ $ result = $ this ->api ->get_webhooks (
3820+ include_total_count: true
3821+ );
3822+
3823+ // Assert webhooks and pagination exist.
3824+ $ this ->assertDataExists ($ result , 'webhooks ' );
3825+ $ this ->assertPaginationExists ($ result );
3826+
3827+ // Assert total count is included.
3828+ $ this ->assertArrayHasKey ('total_count ' , get_object_vars ($ result ->pagination ));
3829+ $ this ->assertGreaterThan (0 , $ result ->pagination ->total_count );
3830+ }
3831+
3832+ /**
3833+ * Test that get_webhooks() returns the expected data
3834+ * when pagination parameters and per_page limits are specified.
3835+ *
3836+ * @since 2.0.0
3837+ *
3838+ * @return void
3839+ */
3840+ public function testGetWebhooksPagination ()
3841+ {
3842+ $ result = $ this ->api ->get_webhooks (
3843+ per_page: 1
3844+ );
3845+
3846+ // Assert webhooks and pagination exist.
3847+ $ this ->assertDataExists ($ result , 'webhooks ' );
3848+ $ this ->assertPaginationExists ($ result );
3849+
3850+ // Assert a single webhook was returned.
3851+ $ this ->assertCount (1 , $ result ->webhooks );
3852+
3853+ // Assert has_previous_page and has_next_page are correct.
3854+ $ this ->assertFalse ($ result ->pagination ->has_previous_page );
3855+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
3856+
3857+ // Use pagination to fetch next page.
3858+ $ result = $ this ->api ->get_webhooks (
3859+ per_page: 1 ,
3860+ after_cursor: $ result ->pagination ->end_cursor
3861+ );
3862+
3863+ // Assert webhooks and pagination exist.
3864+ $ this ->assertDataExists ($ result , 'webhooks ' );
3865+ $ this ->assertPaginationExists ($ result );
3866+
3867+ // Assert a single webhook was returned.
3868+ $ this ->assertCount (1 , $ result ->webhooks );
3869+
3870+ // Assert has_previous_page and has_next_page are correct.
3871+ $ this ->assertTrue ($ result ->pagination ->has_previous_page );
3872+ $ this ->assertTrue ($ result ->pagination ->has_next_page );
3873+
3874+ // Use pagination to fetch previous page.
3875+ $ result = $ this ->api ->get_webhooks (
3876+ per_page: 1 ,
3877+ before_cursor: $ result ->pagination ->start_cursor
3878+ );
3879+
3880+ // Assert webhooks and pagination exist.
3881+ $ this ->assertDataExists ($ result , 'webhooks ' );
3882+ $ this ->assertPaginationExists ($ result );
3883+
3884+ // Assert a single webhook was returned.
3885+ $ this ->assertCount (1 , $ result ->webhooks );
3886+ }
3887+
3888+ /**
3889+ * Test that create_webhook() and delete_webhook() works.
37953890 *
37963891 * We do both, so we don't end up with unnecessary webhooks remaining
37973892 * on the ConvertKit account when running tests.
@@ -3800,24 +3895,22 @@ public function testDestroyBroadcastWithInvalidBroadcastID()
38003895 *
38013896 * @return void
38023897 */
3803- public function testCreateAndDestroyWebhook ()
3898+ public function testCreateAndDeleteWebhook ()
38043899 {
3805- $ this ->markTestIncomplete ();
3806-
38073900 // Create a webhook first.
38083901 $ result = $ this ->api ->create_webhook (
38093902 url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
38103903 event: 'subscriber.subscriber_activate ' ,
38113904 );
38123905 $ ruleID = $ result ->rule ->id ;
38133906
3814- // Destroy the webhook.
3815- $ result = $ this ->api ->destroy_webhook ($ ruleID );
3907+ // Delete the webhook.
3908+ $ result = $ this ->api ->delete_webhook ($ ruleID );
38163909 $ this ->assertEquals ($ result ->success , true );
38173910 }
38183911
38193912 /**
3820- * Test that create_webhook() and destroy_webhook () works with an event parameter.
3913+ * Test that create_webhook() and delete_webhook () works with an event parameter.
38213914 *
38223915 * We do both, so we don't end up with unnecessary webhooks remaining
38233916 * on the ConvertKit account when running tests.
@@ -3826,10 +3919,8 @@ public function testCreateAndDestroyWebhook()
38263919 *
38273920 * @return void
38283921 */
3829- public function testCreateAndDestroyWebhookWithEventParameter ()
3922+ public function testCreateAndDeleteWebhookWithEventParameter ()
38303923 {
3831- $ this ->markTestIncomplete ();
3832-
38333924 // Create a webhook first.
38343925 $ result = $ this ->api ->create_webhook (
38353926 url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
@@ -3838,8 +3929,8 @@ public function testCreateAndDestroyWebhookWithEventParameter()
38383929 );
38393930 $ ruleID = $ result ->rule ->id ;
38403931
3841- // Destroy the webhook.
3842- $ result = $ this ->api ->destroy_webhook ($ ruleID );
3932+ // Delete the webhook.
3933+ $ result = $ this ->api ->delete_webhook ($ ruleID );
38433934 $ this ->assertEquals ($ result ->success , true );
38443935 }
38453936
@@ -3853,8 +3944,6 @@ public function testCreateAndDestroyWebhookWithEventParameter()
38533944 */
38543945 public function testCreateWebhookWithInvalidEvent ()
38553946 {
3856- $ this ->markTestIncomplete ();
3857-
38583947 $ this ->expectException (InvalidArgumentException::class);
38593948 $ this ->api ->create_webhook (
38603949 url: 'https://webhook.site/9c731823-7e61-44c8-af39-43b11f700ecb ' ,
@@ -3863,19 +3952,17 @@ public function testCreateWebhookWithInvalidEvent()
38633952 }
38643953
38653954 /**
3866- * Test that destroy_webhook () throws a ClientException when an invalid
3955+ * Test that delete_webhook () throws a ClientException when an invalid
38673956 * rule ID is specified.
38683957 *
38693958 * @since 1.0.0
38703959 *
38713960 * @return void
38723961 */
3873- public function testDestroyWebhookWithInvalidRuleID ()
3962+ public function testsDeleteWebhookWithInvalidRuleID ()
38743963 {
3875- $ this ->markTestIncomplete ();
3876-
38773964 $ this ->expectException (ClientException::class);
3878- $ this ->api ->destroy_webhook (12345 );
3965+ $ this ->api ->delete_webhook (12345 );
38793966 }
38803967
38813968 /**
0 commit comments