@@ -24,24 +24,140 @@ public function setUp()
2424 parent ::setUp ();
2525 }
2626
27+ public function testTransactional ()
28+ {
29+ Email::dropTransport ('elasticemail ' );
30+ Email::setConfigTransport (
31+ 'elasticemail ' ,
32+ [
33+ 'className ' => 'ElasticEmail.ElasticEmail ' ,
34+ 'apiKey ' => '123 '
35+ ]
36+ );
37+
38+ $ email = new Email ();
39+ $ email ->setProfile (['transport ' => 'elasticemail ' ]);
40+
41+ $ emailInstance = $ email ->getTransport ();
42+ $ emailInstance ->isTransactional (true );
43+
44+ $ emailParams = $ emailInstance ->getEmailParams ();
45+ $ this ->assertArrayHasKey ('isTransactional ' , $ emailParams );
46+ $ this ->assertTrue ($ emailParams ['isTransactional ' ]);
47+ }
48+
49+ public function testTemplate ()
50+ {
51+ Email::dropTransport ('elasticemail ' );
52+ Email::setConfigTransport (
53+ 'elasticemail ' ,
54+ [
55+ 'className ' => 'ElasticEmail.ElasticEmail ' ,
56+ 'apiKey ' => '123 '
57+ ]
58+ );
59+
60+ $ email = new Email ();
61+ $ email ->setProfile (['transport ' => 'elasticemail ' ]);
62+
63+ $ emailInstance = $ email ->getTransport ();
64+ $ emailInstance ->setTemplate (111 );
65+
66+ $ emailParams = $ emailInstance ->getEmailParams ();
67+ $ this ->assertArrayHasKey ('template ' , $ emailParams );
68+ $ this ->assertEquals (111 , $ emailParams ['template ' ]);
69+ }
70+
71+ public function testTemplateVars ()
72+ {
73+ Email::dropTransport ('elasticemail ' );
74+ Email::setConfigTransport (
75+ 'elasticemail ' ,
76+ [
77+ 'className ' => 'ElasticEmail.ElasticEmail ' ,
78+ 'apiKey ' => '123 '
79+ ]
80+ );
81+
82+ $ mergeVars = [
83+ 'foo ' => 'bar '
84+ ];
85+
86+ $ email = new Email ();
87+ $ email ->setProfile (['transport ' => 'elasticemail ' ]);
88+
89+ $ emailInstance = $ email ->getTransport ();
90+ $ emailInstance ->setMergeVariables ($ mergeVars );
91+
92+ $ emailParams = $ emailInstance ->getEmailParams ();
93+ $ this ->assertArrayHasKey ('merge_foo ' , $ emailParams );
94+ $ this ->assertEquals ('bar ' , $ emailParams ['merge_foo ' ]);
95+ }
96+
97+ public function testSchedule ()
98+ {
99+ Email::dropTransport ('elasticemail ' );
100+ Email::setConfigTransport (
101+ 'elasticemail ' ,
102+ [
103+ 'className ' => 'ElasticEmail.ElasticEmail ' ,
104+ 'apiKey ' => '123 '
105+ ]
106+ );
107+
108+ $ email = new Email ();
109+ $ email ->setProfile (['transport ' => 'elasticemail ' ]);
110+
111+ $ emailInstance = $ email ->getTransport ();
112+ $ emailInstance ->setScheduleTime (60 );
113+
114+ $ emailParams = $ emailInstance ->getEmailParams ();
115+ $ this ->assertArrayHasKey ('timeOffSetMinutes ' , $ emailParams );
116+ $ this ->assertEquals (60 , $ emailParams ['timeOffSetMinutes ' ]);
117+ }
118+
27119 public function testMissingApiKey ()
28120 {
29121 $ this ->expectException ('ElasticEmail\Mailer\Exception\MissingElasticEmailApiKeyException ' );
30122
123+ Email::dropTransport ('elasticemail ' );
31124 Email::setConfigTransport (
32125 'elasticemail ' ,
33126 [
34127 'className ' => 'ElasticEmail.ElasticEmail ' ,
35128 'apiKey ' => ''
36129 ]
37130 );
38-
131+
39132 $ email = new Email ();
40133 $ email ->setProfile (['transport ' => 'elasticemail ' ]);
41134 $ email ->setFrom (['from@example.com ' => 'CakePHP Elastic Email ' ])
135+ ->setTo ('to@example.com ' )
136+ ->setEmailFormat ('both ' )
137+ ->setSubject ('Email from CakePHP Elastic Email plugin ' )
138+ ->send ('Hello there, <br> This is an email from CakePHP Elastic Email plugin. ' );
139+ }
140+
141+ public function testInvalidKey ()
142+ {
143+ Email::dropTransport ('elasticemail ' );
144+ Email::setConfigTransport (
145+ 'elasticemail ' ,
146+ [
147+ 'className ' => 'ElasticEmail.ElasticEmail ' ,
148+ 'apiKey ' => '123 '
149+ ]
150+ );
151+
152+ $ email = new Email ();
153+ $ email ->setProfile (['transport ' => 'elasticemail ' ]);
154+ $ res = $ email ->setFrom (['from@example.com ' => 'CakePHP Elastic Email ' ])
42155 ->setTo ('to@example.com ' )
43156 ->setEmailFormat ('both ' )
44157 ->setSubject ('{title} - Email from CakePHP Elastic Email plugin ' )
45158 ->send ('Hello {firstname} {lastname}, <br> This is an email from CakePHP Elastic Email plugin. ' );
159+
160+ $ this ->assertEquals (false , $ res ['apiResponse ' ]['success ' ]);
161+ $ this ->assertEquals ('Incorrect apikey ' , $ res ['apiResponse ' ]['error ' ]);
46162 }
47163}
0 commit comments