Skip to content

Commit 6ea6b39

Browse files
committed
Adding a test for the test send email button
1 parent 9ffed82 commit 6ea6b39

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

Diff for: Tests/Functional/Mailer/Transport/SparkpostTransportTest.php

+37
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,43 @@ function ($method, $url, $options): MockResponse {
8989
Assert::assertSame('', $email->getReplyTo()[0]->getName());
9090
}
9191

92+
public function testTestTransportButton(): void
93+
{
94+
$expectedResponses = [
95+
function ($method, $url, $options): MockResponse {
96+
Assert::assertSame(Request::METHOD_POST, $method);
97+
Assert::assertSame('https://api.sparkpost.com/api/v1/utils/content-previewer/', $url);
98+
$this->assertSparkpostTestRequestBody($options['body']);
99+
100+
return new MockResponse('{"results": {"subject": "Hello there!", "html": "This is test body for {contactfield=email}!"}}');
101+
},
102+
function ($method, $url, $options): MockResponse {
103+
Assert::assertSame(Request::METHOD_POST, $method);
104+
Assert::assertSame('https://api.sparkpost.com/api/v1/transmissions/', $url);
105+
$this->assertSparkpostTestRequestBody($options['body']);
106+
107+
return new MockResponse('{"results": {"total_rejected_recipients": 0, "total_accepted_recipients": 1, "id": "11668787484950529"}}');
108+
},
109+
];
110+
111+
/** @var MockHttpClient $mockHttpClient */
112+
$mockHttpClient = self::getContainer()->get(HttpClientInterface::class);
113+
$mockHttpClient->setResponseFactory($expectedResponses);
114+
$this->client->request(Request::METHOD_GET, '/s/ajax?action=email:sendTestEmail');
115+
Assert::assertTrue($this->client->getResponse()->isOk());
116+
Assert::assertSame('{"success":1,"message":"Success!"}', $this->client->getResponse()->getContent());
117+
}
118+
119+
private function assertSparkpostTestRequestBody(string $body): void
120+
{
121+
$bodyArray = json_decode($body, true);
122+
Assert::assertSame('Admin <[email protected]>', $bodyArray['content']['from']);
123+
Assert::assertNull($bodyArray['content']['html']);
124+
Assert::assertSame('[email protected]', $bodyArray['content']['reply_to']);
125+
Assert::assertSame('Mautic test email', $bodyArray['content']['subject']);
126+
Assert::assertSame('Hi! This is a test email from Mautic. Testing...testing...1...2...3!', $bodyArray['content']['text']);
127+
}
128+
92129
private function assertSparkpostRequestBody(string $body): void
93130
{
94131
$bodyArray = json_decode($body, true);

0 commit comments

Comments
 (0)