From 8a88734818823bbfa5717d187a4973b4e53047c0 Mon Sep 17 00:00:00 2001 From: Tim Carr Date: Fri, 19 Apr 2024 14:58:41 +0100 Subject: [PATCH] Added email template tests --- tests/wpunit/APITest.php | 89 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) diff --git a/tests/wpunit/APITest.php b/tests/wpunit/APITest.php index 936a561..9dfd506 100644 --- a/tests/wpunit/APITest.php +++ b/tests/wpunit/APITest.php @@ -1500,6 +1500,95 @@ public function testUnsubscribeWithInvalidEmail() $this->assertEquals('Not Found: The entity you were trying to find doesn\'t exist', $result->get_error_message()); } + /** + * Test that get_email_templates() returns the expected data. + * + * @since 2.0.0 + * + * @return void + */ + public function testGetEmailTemplates() + { + $result = $this->api->get_email_templates(); + + // Assert email templates and pagination exist. + $this->assertDataExists($result, 'email_templates'); + $this->assertPaginationExists($result); + } + + /** + * Test that get_email_templates() returns the expected data + * when the total count is included. + * + * @since 1.0.0 + * + * @return void + */ + public function testGetEmailTemplatesWithTotalCount() + { + $result = $this->api->get_email_templates(true); + + // Assert email templates and pagination exist. + $this->assertDataExists($result, 'email_templates'); + $this->assertPaginationExists($result); + + // Assert total count is included. + $this->assertArrayHasKey('total_count', $result['pagination']); + $this->assertGreaterThan(0, $result['pagination']['total_count']); + } + + /** + * Test that get_email_templates() returns the expected data + * when pagination parameters and per_page limits are specified. + * + * @since 2.0.0 + * + * @return void + */ + public function testGetEmailTemplatesPagination() + { + // Return one broadcast. + $result = $this->api->get_email_templates(false, '', '', 1); + + // Assert email templates and pagination exist. + $this->assertDataExists($result, 'email_templates'); + $this->assertPaginationExists($result); + + // Assert a single email template was returned. + $this->assertCount(1, $result['email_templates']); + + // Assert has_previous_page and has_next_page are correct. + $this->assertFalse($result['pagination']['has_previous_page']); + $this->assertTrue($result['pagination']['has_next_page']); + + // Use pagination to fetch next page. + $result = $this->api->get_email_templates(false, $result['pagination']['end_cursor'], '', 1); + + // Assert email templates and pagination exist. + $this->assertDataExists($result, 'email_templates'); + $this->assertPaginationExists($result); + + // Assert a single email template was returned. + $this->assertCount(1, $result['email_templates']); + + // Assert has_previous_page and has_next_page are correct. + $this->assertTrue($result['pagination']['has_previous_page']); + $this->assertTrue($result['pagination']['has_next_page']); + + // Use pagination to fetch previous page. + $result = $this->api->get_email_templates(false, '', $result['pagination']['start_cursor'], 1); + + // Assert email templates and pagination exist. + $this->assertDataExists($result, 'email_templates'); + $this->assertPaginationExists($result); + + // Assert a single email template was returned. + $this->assertCount(1, $result['email_templates']); + + // Assert has_previous_page and has_next_page are correct. + $this->assertFalse($result['pagination']['has_previous_page']); + $this->assertTrue($result['pagination']['has_next_page']); + } /** * Test that get_broadcasts() returns the expected data