@@ -89,6 +89,43 @@ function ($method, $url, $options): MockResponse {
89
89
Assert::assertSame ('' , $ email ->getReplyTo ()[0 ]->getName ());
90
90
}
91
91
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
+
92
129
private function assertSparkpostRequestBody (string $ body ): void
93
130
{
94
131
$ bodyArray = json_decode ($ body , true );
0 commit comments