7
7
namespace Magento \Framework \Mail \Test \Unit \Template ;
8
8
9
9
use Magento \Framework \App \TemplateTypesInterface ;
10
+ use Magento \Framework \DataObject ;
10
11
use Magento \Framework \Mail \MessageInterface ;
11
12
12
13
/**
@@ -99,17 +100,37 @@ protected function setUp()
99
100
*/
100
101
public function testGetTransport ($ templateType , $ messageType , $ bodyText , $ templateNamespace )
101
102
{
102
- $ this ->builder ->setTemplateModel ($ templateNamespace );
103
-
104
103
$ vars = ['reason ' => 'Reason ' , 'customer ' => 'Customer ' ];
105
104
$ options = ['area ' => 'frontend ' , 'store ' => 1 ];
105
+ $ from = 'email_from ' ;
106
+ $ sender = ['email ' => 'from@example.com ' , 'name ' => 'name ' ];
106
107
107
- $ template = $ this ->createMock (\Magento \Framework \Mail \TemplateInterface::class);
108
+ $ this ->builder ->setTemplateModel ($ templateNamespace );
109
+ $ this ->builder ->setFrom ($ from );
110
+
111
+ $ template = $ this ->createPartialMock (
112
+ \Magento \Framework \Mail \TemplateInterface::class,
113
+ [
114
+ 'setVars ' ,
115
+ 'isPlain ' ,
116
+ 'setOptions ' ,
117
+ 'getSubject ' ,
118
+ 'getType ' ,
119
+ 'processTemplate ' ,
120
+ 'getDesignConfig ' ,
121
+ ]
122
+ );
108
123
$ template ->expects ($ this ->once ())->method ('setVars ' )->with ($ this ->equalTo ($ vars ))->willReturnSelf ();
109
124
$ template ->expects ($ this ->once ())->method ('setOptions ' )->with ($ this ->equalTo ($ options ))->willReturnSelf ();
110
125
$ template ->expects ($ this ->once ())->method ('getSubject ' )->willReturn ('Email Subject ' );
111
126
$ template ->expects ($ this ->once ())->method ('getType ' )->willReturn ($ templateType );
112
127
$ template ->expects ($ this ->once ())->method ('processTemplate ' )->willReturn ($ bodyText );
128
+ $ template ->method ('getDesignConfig ' )->willReturn (new DataObject ($ options ));
129
+
130
+ $ this ->senderResolverMock ->expects ($ this ->once ())
131
+ ->method ('resolve ' )
132
+ ->with ($ from , 1 )
133
+ ->willReturn ($ sender );
113
134
114
135
$ this ->templateFactoryMock ->expects ($ this ->once ())
115
136
->method ('get ' )
@@ -128,6 +149,9 @@ public function testGetTransport($templateType, $messageType, $bodyText, $templa
128
149
->method ('setBody ' )
129
150
->with ($ this ->equalTo ($ bodyText ))
130
151
->willReturnSelf ();
152
+ $ this ->messageMock ->method ('setFrom ' )
153
+ ->with ($ sender ['email ' ], $ sender ['name ' ])
154
+ ->willReturnSelf ();
131
155
132
156
$ transport = $ this ->createMock (\Magento \Framework \Mail \TransportInterface::class);
133
157
@@ -161,24 +185,6 @@ public function getTransportDataProvider()
161
185
];
162
186
}
163
187
164
- /**
165
- * @return void
166
- */
167
- public function testSetFrom ()
168
- {
169
- $ sender = ['email ' => 'from@example.com ' , 'name ' => 'name ' ];
170
- $ this ->senderResolverMock ->expects ($ this ->once ())
171
- ->method ('resolve ' )
172
- ->with ($ sender )
173
- ->willReturn ($ sender );
174
- $ this ->messageMock ->expects ($ this ->once ())
175
- ->method ('setFrom ' )
176
- ->with ('from@example.com ' , 'name ' )
177
- ->willReturnSelf ();
178
-
179
- $ this ->builder ->setFrom ($ sender );
180
- }
181
-
182
188
/**
183
189
* @return void
184
190
*/
0 commit comments