Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
238 changes: 36 additions & 202 deletions tests/ConvertKitAPIKeyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -357,164 +357,55 @@ public function testAddSubscribersToForms()
}

/**
* Test that add_subscribers_to_forms() returns a ClientException
* when a referrer URL is specified, as this is only supported
* using OAuth.
* Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testAddSubscribersToFormsWithReferrer()
{
// Create subscriber.
$emailAddress = $this->generateEmailAddress();
$subscriber = $this->api->create_subscriber(
email_address: $emailAddress
);

// Set subscriber_id to ensure subscriber is unsubscribed after test.
$this->subscriber_ids[] = $subscriber->subscriber->id;

$this->expectException(ClientException::class);

// Add subscribers to forms.
$result = $this->api->add_subscribers_to_forms(
forms_subscribers_ids: [
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'],
'subscriber_id' => $subscriber->subscriber->id,
'referrer' => 'https://mywebsite.com/bfpromo/',
],
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'],
'subscriber_id' => $subscriber->subscriber->id,
'referrer' => 'https://mywebsite.com/bfpromo/',
],
]
);
$this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.');
}

/**
* Test that add_subscribers_to_forms() returns a ClientException
* when a referrer URL with UTM parameters is specified, as this is only
* supported using OAuth.
* Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testAddSubscribersToFormsWithReferrerUTMParams()
{
// Define referrer.
$referrerUTMParams = [
'utm_source' => 'facebook',
'utm_medium' => 'cpc',
'utm_campaign' => 'black_friday',
'utm_term' => 'car_owners',
'utm_content' => 'get_10_off',
];
$referrer = 'https://mywebsite.com/bfpromo/?' . http_build_query($referrerUTMParams);

// Create subscriber.
$emailAddress = $this->generateEmailAddress();
$subscriber = $this->api->create_subscriber(
email_address: $emailAddress
);

// Set subscriber_id to ensure subscriber is unsubscribed after test.
$this->subscriber_ids[] = $subscriber->subscriber->id;

$this->expectException(ClientException::class);

// Add subscribers to forms.
$result = $this->api->add_subscribers_to_forms(
forms_subscribers_ids: [
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'],
'subscriber_id' => $subscriber->subscriber->id,
'referrer' => $referrer,
],
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'],
'subscriber_id' => $subscriber->subscriber->id,
'referrer' => $referrer,
],
]
);
$this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.');
}

/**
* Test that add_subscribers_to_forms() returns a ClientException
* when invalid Form IDs are specified, as this is only supported
* using OAuth.
* Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testAddSubscribersToFormsWithInvalidFormIDs()
{
// Create subscriber.
$emailAddress = $this->generateEmailAddress();
$subscriber = $this->api->create_subscriber(
email_address: $emailAddress
);

// Set subscriber_id to ensure subscriber is unsubscribed after test.
$this->subscriber_ids[] = $subscriber->subscriber->id;

$this->expectException(ClientException::class);

// Add subscribers to forms.
$result = $this->api->add_subscribers_to_forms(
forms_subscribers_ids: [
[
'form_id' => 9999999,
'subscriber_id' => $subscriber->subscriber->id,
],
[
'form_id' => 9999999,
'subscriber_id' => $subscriber->subscriber->id,
],
]
);
$this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.');
}

/**
* Test that add_subscribers_to_forms() returns a ClientException
* when invalid Subscriber IDs are specified, as this is only supported
* Skip this test from ConvertKitAPITest, as testAddSubscribersToForms() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testAddSubscribersToFormsWithInvalidSubscriberIDs()
{
// Create subscriber.
$emailAddress = $this->generateEmailAddress();
$subscriber = $this->api->create_subscriber(
email_address: $emailAddress
);

// Set subscriber_id to ensure subscriber is unsubscribed after test.
$this->subscriber_ids[] = $subscriber->subscriber->id;

$this->expectException(ClientException::class);

// Add subscribers to forms.
$result = $this->api->add_subscribers_to_forms(
forms_subscribers_ids: [
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID'],
'subscriber_id' => 999999,
],
[
'form_id' => (int) $_ENV['CONVERTKIT_API_FORM_ID_2'],
'subscriber_id' => 999999,
],
]
);
$this->markTestSkipped('testAddSubscribersToForms() above confirms a ClientException is thrown.');
}

/**
Expand All @@ -541,40 +432,29 @@ public function testCreateSubscribers()
}

/**
* Test that create_subscribers() throws a ClientException when no data is specified.
* Skip this test from ConvertKitAPITest, as testCreateSubscribersWithBlankData() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testCreateSubscribersWithBlankData()
{
$this->expectException(ClientException::class);
$result = $this->api->create_subscribers([
[],
]);
$this->markTestSkipped('testCreateSubscribers() above confirms a ClientException is thrown.');
}

/**
* Test that create_subscribers() throws a ClientException when invalid email addresses
* are specified, as this is only supported using OAuth.
* Skip this test from ConvertKitAPITest, as testCreateSubscribersWithBlankData() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testCreateSubscribersWithInvalidEmailAddresses()
{
$this->expectException(ClientException::class);
$subscribers = [
[
'email_address' => 'not-an-email-address',
],
[
'email_address' => 'not-an-email-address-again',
],
];
$result = $this->api->create_subscribers($subscribers);
$this->markTestSkipped('testCreateSubscribers() above confirms a ClientException is thrown.');
}

/**
Expand Down Expand Up @@ -610,37 +490,29 @@ public function testGetPurchases()
}

/**
* Test that get_purchases() throws a ClientException
* when the total count is included, as this is only
* supported using OAuth.
* Skip this test from ConvertKitAPITest, as testGetPurchases() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testGetPurchasesWithTotalCount()
{
$this->expectException(ClientException::class);
$result = $this->api->get_purchases(
include_total_count: true
);
$this->markTestSkipped('testGetPurchases() above confirms a ClientException is thrown.');
}

/**
* Test that get_purchases() throws a ClientException
* when pagination parameters and per_page limits are specified,
* as this is only supported using OAuth.
* Skip this test from ConvertKitAPITest, as testGetPurchases() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testGetPurchasesPagination()
{
$this->expectException(ClientException::class);
$result = $this->api->get_purchases(
per_page: 1
);
$this->markTestSkipped('testGetPurchases() above confirms a ClientException is thrown.');
}

/**
Expand All @@ -659,18 +531,16 @@ public function testGetPurchase()
}

/**
* Test that get_purchases() throws a ClientException when an invalid
* purchase ID is specified, as this is only supported
* using OAuth.
* Skip this test from ConvertKitAPITest, as testGetPurchase() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testGetPurchaseWithInvalidID()
{
$this->expectException(ClientException::class);
$this->api->get_purchase(12345);
$this->markTestSkipped('testGetPurchase() above confirms a ClientException is thrown.');
}

/**
Expand Down Expand Up @@ -720,77 +590,41 @@ public function testCreatePurchase()
}

/**
* Test that create_purchase() throws a ClientException when an invalid
* email address is specified, as this is only supported using OAuth.
* Skip this test from ConvertKitAPITest, as testCreatePurchase() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testCreatePurchaseWithInvalidEmailAddress()
{
$this->expectException(ClientException::class);
$this->api->create_purchase(
email_address: 'not-an-email-address',
transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'),
currency: 'usd',
products: [
[
'name' => 'Floppy Disk (512k)',
'sku' => '7890-ijkl',
'pid' => 9999,
'lid' => 7777,
'quantity' => 2,
'unit_price' => 5.00,
],
],
);
$this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.');
}

/**
* Test that create_purchase() throws a ClientException when a blank
* transaction ID is specified, as this is only supported using OAuth.
* Skip this test from ConvertKitAPITest, as testCreatePurchase() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testCreatePurchaseWithBlankTransactionID()
{
$this->expectException(ClientException::class);
$this->api->create_purchase(
email_address: $this->generateEmailAddress(),
transaction_id: '',
currency: 'usd',
products: [
[
'name' => 'Floppy Disk (512k)',
'sku' => '7890-ijkl',
'pid' => 9999,
'lid' => 7777,
'quantity' => 2,
'unit_price' => 5.00,
],
],
);
$this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.');
}

/**
* Test that create_purchase() throws a ClientException when no products
* are specified, as this is only supported using OAuth.
* Skip this test from ConvertKitAPITest, as testCreatePurchase() above
* confirms a ClientException is thrown.
*
* @since 2.2.0
*
* @return void
*/
public function testCreatePurchaseWithNoProducts()
{
$this->expectException(ClientException::class);
$this->api->create_purchase(
email_address: $this->generateEmailAddress(),
transaction_id: str_shuffle('wfervdrtgsdewrafvwefds'),
currency: 'usd',
products: [],
);
$this->markTestSkipped('testCreatePurchase() above confirms a ClientException is thrown.');
}
}