@@ -175,6 +175,7 @@ function test_get_attachments() {
175175 $ this ->assertTrue ($ attachments [0 ]['type ' ] === 'application/octet-stream ' );
176176 $ this ->assertTrue ($ attachments [0 ]['name ' ] === basename ($ temp ));
177177 $ this ->assertTrue ($ attachments [0 ]['data ' ] === base64_encode ('TEST ' ));
178+ unlink ($ temp );
178179 }
179180
180181 function test_isMail () {
@@ -185,7 +186,8 @@ function test_isMail() {
185186 $ this ->assertTrue ($ this ->mailer ->Mailer === 'sparkpost ' );
186187 }
187188
188- function test_get_request_body_without_template () {
189+ function test_get_request_body () {
190+ // WITHOUT TEMPLATE
189191 $ this ->mailer ->addAddress ('abc@xyz.com ' , 'abc ' );
190192 $ this ->mailer ->addBcc ('bcc@xyz.com ' , 'bcc ' );
191193 $ this ->mailer ->addCc ('cc@xyz.com ' , 'cc ' );
@@ -235,7 +237,30 @@ function test_get_request_body_without_template() {
235237 ];
236238
237239 $ actual = NSA ::invokeMethod ($ this ->mailer , 'get_request_body ' );
238- $ actual ['content ' ]['headers ' ] = []; // for simpler $expected_request_body. alternatively stub get_headers
240+ // for simpler expectation reset content.headers to empty array.
241+ // alternative is to stub get_headers which isn't working expectedly
242+ $ actual ['content ' ]['headers ' ] = [];
243+ $ this ->assertTrue ($ expected_request_body == $ actual );
244+
245+ //WITH TEMPLATE - reuse previous setup
246+ NSA ::setProperty ($ this ->mailer , 'settings ' , [
247+ 'enable_tracking ' => true ,
248+ 'transactional ' => false ,
249+ 'template ' => 'hello '
250+ ]);
251+
252+ $ actual = NSA ::invokeMethod ($ this ->mailer , 'get_request_body ' );
253+ $ expected_request_body ['content ' ] = [
254+ 'template_id ' => 'hello ' ,
255+ ];
256+ $ expected_request_body ['substitution_data ' ] = [
257+ 'content ' => '' ,
258+ 'subject ' => '' ,
259+ 'from_name ' => 'me ' ,
260+ 'from ' => 'me <me@hello.com> ' ,
261+ 'from_localpart ' => 'me '
262+ ];
263+
239264 $ this ->assertTrue ($ expected_request_body == $ actual );
240265 }
241266}
0 commit comments