Skip to content
Merged
Changes from 1 commit
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
56 changes: 35 additions & 21 deletions tests/ConvertKitAPITest.php
Original file line number Diff line number Diff line change
Expand Up @@ -765,8 +765,10 @@ public function testGetGrowthStatsWithStartDate()
$this->assertArrayHasKey('ending', $stats);

// Assert start and end dates were honored.
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00-05:00');
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59-05:00');
// Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P');
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
}

/**
Expand Down Expand Up @@ -802,8 +804,10 @@ public function testGetGrowthStatsWithEndDate()
$this->assertArrayHasKey('ending', $stats);

// Assert start and end dates were honored.
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00-05:00');
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59-05:00');
// Gets timezone offset for New York (-04:00 during DST, -05:00 otherwise).
$timezone = ( new DateTime() )->setTimezone(new DateTimeZone('America/New_York'))->format('P');
$this->assertEquals($stats['starting'], $starting->format('Y-m-d') . 'T00:00:00' . $timezone);
$this->assertEquals($stats['ending'], $ending->format('Y-m-d') . 'T23:59:59' . $timezone);
}

/**
Expand Down Expand Up @@ -1186,7 +1190,7 @@ public function testGetFormSubscriptionsWithBouncedSubscriberState()
*/
public function testGetFormSubscriptionsWithAddedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_form_subscriptions(
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
added_after: $date
Expand Down Expand Up @@ -1242,7 +1246,7 @@ public function testGetFormSubscriptionsWithAddedBeforeParam()
*/
public function testGetFormSubscriptionsWithCreatedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_form_subscriptions(
form_id: (int) $_ENV['CONVERTKIT_API_FORM_ID'],
created_after: $date
Expand Down Expand Up @@ -1702,7 +1706,7 @@ public function testGetSequenceSubscriptionsWithBouncedSubscriberState()
*/
public function testGetSequenceSubscriptionsWithAddedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_sequence_subscriptions(
sequence_id: (int) $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
added_after: $date
Expand Down Expand Up @@ -1758,7 +1762,7 @@ public function testGetSequenceSubscriptionsWithAddedBeforeParam()
*/
public function testGetSequenceSubscriptionsWithCreatedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_sequence_subscriptions(
sequence_id: (int) $_ENV['CONVERTKIT_API_SEQUENCE_ID'],
created_after: $date
Expand Down Expand Up @@ -1846,7 +1850,7 @@ public function testGetSequenceSubscriptionsPagination()

// Assert has_previous_page and has_next_page are correct.
$this->assertTrue($result->pagination->has_previous_page);
$this->assertTrue($result->pagination->has_next_page);
$this->assertFalse($result->pagination->has_next_page);

// Use pagination to fetch previous page.
$result = $this->api->get_sequence_subscriptions(
Expand Down Expand Up @@ -2058,7 +2062,7 @@ public function testCreateTagBlank()
}

/**
* Test that create_tag() throws a ClientException when creating
* Test that create_tag() returns the expected data when creating
* a tag that already exists.
*
* @since 1.0.0
Expand All @@ -2067,8 +2071,14 @@ public function testCreateTagBlank()
*/
public function testCreateTagThatExists()
{
$this->expectException(ClientException::class);
$result = $this->api->create_tag($_ENV['CONVERTKIT_API_TAG_NAME']);

// Assert response contains correct data.
$tag = get_object_vars($result->tag);
$this->assertArrayHasKey('id', $tag);
$this->assertArrayHasKey('name', $tag);
$this->assertArrayHasKey('created_at', $tag);
$this->assertEquals($tag['name'], $_ENV['CONVERTKIT_API_TAG_NAME']);
}

/**
Expand Down Expand Up @@ -2141,13 +2151,17 @@ public function testCreateTagsBlank()
*/
public function testCreateTagsThatExist()
{
$result = $this->api->create_tags([
$_ENV['CONVERTKIT_API_TAG_NAME'],
$_ENV['CONVERTKIT_API_TAG_NAME_2'],
]);
$result = $this->api->create_tags(
[
$_ENV['CONVERTKIT_API_TAG_NAME'],
$_ENV['CONVERTKIT_API_TAG_NAME_2'],
]
);

// Assert failures.
$this->assertCount(2, $result->failures);
// Assert existing tags are returned.
$this->assertCount(2, $result->tags);
$this->assertEquals($result->tags[1]->name, $_ENV['CONVERTKIT_API_TAG_NAME']);
$this->assertEquals($result->tags[0]->name, $_ENV['CONVERTKIT_API_TAG_NAME_2']);
}

/**
Expand Down Expand Up @@ -2530,7 +2544,7 @@ public function testGetTagSubscriptionsWithBouncedSubscriberState()
*/
public function testGetTagSubscriptionsWithTaggedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_tag_subscriptions(
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
tagged_after: $date
Expand Down Expand Up @@ -2586,7 +2600,7 @@ public function testGetTagSubscriptionsWithTaggedBeforeParam()
*/
public function testGetTagSubscriptionsWithCreatedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_tag_subscriptions(
tag_id: (int) $_ENV['CONVERTKIT_API_TAG_ID'],
created_after: $date
Expand Down Expand Up @@ -3396,7 +3410,7 @@ public function testGetSubscribersWithBouncedSubscriberState()
*/
public function testGetSubscribersWithCreatedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_subscribers(
created_after: $date
);
Expand Down Expand Up @@ -3448,7 +3462,7 @@ public function testGetSubscribersWithCreatedBeforeParam()
*/
public function testGetSubscribersWithUpdatedAfterParam()
{
$date = new \DateTime('2024-01-01');
$date = new \DateTime('2022-01-01');
$result = $this->api->get_subscribers(
updated_after: $date
);
Expand Down