@@ -58,8 +58,17 @@ public function getTransportData()
5858 public function testCustomHeader ()
5959 {
6060 $ json = json_encode (['foo ' => 'bar ' ]);
61+ $ deliveryTime = (new \DateTimeImmutable ('2020-03-20 13:01:00 ' ))->format (\DateTimeImmutable::RFC2822 );
62+
6163 $ email = new Email ();
6264 $ email ->getHeaders ()->addTextHeader ('X-Mailgun-Variables ' , $ json );
65+ $ email ->getHeaders ()->addTextHeader ('h:foo ' , 'foo-value ' );
66+ $ email ->getHeaders ()->addTextHeader ('t:text ' , 'text-value ' );
67+ $ email ->getHeaders ()->addTextHeader ('o:deliverytime ' , $ deliveryTime );
68+ $ email ->getHeaders ()->addTextHeader ('v:version ' , 'version-value ' );
69+ $ email ->getHeaders ()->addTextHeader ('template ' , 'template-value ' );
70+ $ email ->getHeaders ()->addTextHeader ('recipient-variables ' , 'recipient-variables-value ' );
71+ $ email ->getHeaders ()->addTextHeader ('amp-html ' , 'amp-html-value ' );
6372 $ envelope = new Envelope (new Address ('alice@system.com ' ), [new Address ('bob@system.com ' )]);
6473
6574 $ transport = new MailgunApiTransport ('ACCESS_KEY ' , 'DOMAIN ' );
@@ -69,6 +78,43 @@ public function testCustomHeader()
6978
7079 $ this ->assertArrayHasKey ('h:x-mailgun-variables ' , $ payload );
7180 $ this ->assertEquals ($ json , $ payload ['h:x-mailgun-variables ' ]);
81+
82+ $ this ->assertArrayHasKey ('h:foo ' , $ payload );
83+ $ this ->assertEquals ('foo-value ' , $ payload ['h:foo ' ]);
84+ $ this ->assertArrayHasKey ('t:text ' , $ payload );
85+ $ this ->assertEquals ('text-value ' , $ payload ['t:text ' ]);
86+ $ this ->assertArrayHasKey ('o:deliverytime ' , $ payload );
87+ $ this ->assertEquals ($ deliveryTime , $ payload ['o:deliverytime ' ]);
88+ $ this ->assertArrayHasKey ('v:version ' , $ payload );
89+ $ this ->assertEquals ('version-value ' , $ payload ['v:version ' ]);
90+ $ this ->assertArrayHasKey ('template ' , $ payload );
91+ $ this ->assertEquals ('template-value ' , $ payload ['template ' ]);
92+ $ this ->assertArrayHasKey ('recipient-variables ' , $ payload );
93+ $ this ->assertEquals ('recipient-variables-value ' , $ payload ['recipient-variables ' ]);
94+ $ this ->assertArrayHasKey ('amp-html ' , $ payload );
95+ $ this ->assertEquals ('amp-html-value ' , $ payload ['amp-html ' ]);
96+ }
97+
98+ /**
99+ * @legacy
100+ */
101+ public function testPrefixHeaderWithH ()
102+ {
103+ $ json = json_encode (['foo ' => 'bar ' ]);
104+ $ deliveryTime = (new \DateTimeImmutable ('2020-03-20 13:01:00 ' ))->format (\DateTimeImmutable::RFC2822 );
105+
106+ $ email = new Email ();
107+ $ email ->getHeaders ()->addTextHeader ('bar ' , 'bar-value ' );
108+
109+ $ envelope = new Envelope (new Address ('alice@system.com ' ), [new Address ('bob@system.com ' )]);
110+
111+ $ transport = new MailgunApiTransport ('ACCESS_KEY ' , 'DOMAIN ' );
112+ $ method = new \ReflectionMethod (MailgunApiTransport::class, 'getPayload ' );
113+ $ method ->setAccessible (true );
114+ $ payload = $ method ->invoke ($ transport , $ email , $ envelope );
115+
116+ $ this ->assertArrayHasKey ('h:bar ' , $ payload , 'We should prefix headers with "h:" to keep BC ' );
117+ $ this ->assertEquals ('bar-value ' , $ payload ['h:bar ' ]);
72118 }
73119
74120 public function testSend ()
@@ -130,7 +176,7 @@ public function testSendThrowsForErrorResponse()
130176 ->text ('Hello There! ' );
131177
132178 $ this ->expectException (HttpTransportException::class);
133- $ this ->expectExceptionMessage ('Unable to send an email: i \'m a teapot (code 418). ' );
179+ $ this ->expectExceptionMessage ('Unable to send an email: " i \'m a teapot" (code 418). ' );
134180 $ transport ->send ($ mail );
135181 }
136182
0 commit comments