Skip to content

Commit de967c7

Browse files
author
Dmytro Voskoboinikov
committed
MAGETWO-35620: Implement Observer
1 parent 38ab1fa commit de967c7

File tree

4 files changed

+157
-24
lines changed

4 files changed

+157
-24
lines changed

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/CreditmemoSenderTest.php

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class CreditmemoSenderTest extends \PHPUnit_Framework_TestCase
6565
*/
6666
protected $globalConfig;
6767

68+
/**
69+
* @var \Magento\Sales\Model\Order\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
70+
*/
71+
protected $addressRenderer;
72+
6873
protected function setUp()
6974
{
7075
$this->senderMock = $this->getMock(
@@ -110,6 +115,14 @@ protected function setUp()
110115
false
111116
);
112117

118+
$this->addressRenderer = $this->getMock(
119+
'Magento\Sales\Model\Order\Address\Renderer',
120+
['format'],
121+
[],
122+
'',
123+
false
124+
);
125+
113126
$this->storeMock = $this->getMock(
114127
'\Magento\Store\Model\Store',
115128
['getStoreId', '__wakeup'],
@@ -134,7 +147,7 @@ protected function setUp()
134147
[
135148
'getStore', 'getBillingAddress', 'getPayment',
136149
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
137-
'getCustomerEmail'
150+
'getCustomerEmail', 'getShippingAddress'
138151
],
139152
[],
140153
'',
@@ -179,7 +192,8 @@ protected function setUp()
179192
$this->senderBuilderFactoryMock,
180193
$this->paymentHelper,
181194
$this->creditmemoResource,
182-
$this->globalConfig
195+
$this->globalConfig,
196+
$this->addressRenderer
183197
);
184198
}
185199

@@ -194,7 +208,7 @@ protected function setUp()
194208
public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
195209
{
196210
$comment = 'comment_test';
197-
$billingAddress = 'billing_address';
211+
$address = 'address_test';
198212
$configPath = 'sales_email/general/async_sending';
199213

200214
$this->creditmemoMock->expects($this->once())
@@ -207,9 +221,26 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
207221
->willReturn($configValue);
208222

209223
if (!$configValue || $forceSyncMode) {
224+
$addressMock = $this->getMock(
225+
'Magento\Sales\Model\Order\Address',
226+
[],
227+
[],
228+
'',
229+
false
230+
);
231+
232+
$this->addressRenderer->expects($this->any())
233+
->method('format')
234+
->with($addressMock, 'html')
235+
->willReturn($address);
236+
210237
$this->orderMock->expects($this->any())
211238
->method('getBillingAddress')
212-
->willReturn($billingAddress);
239+
->willReturn($addressMock);
240+
241+
$this->orderMock->expects($this->any())
242+
->method('getShippingAddress')
243+
->willReturn($addressMock);
213244

214245
$this->creditmemoMock->expects($this->once())
215246
->method('getCustomerNoteNotify')
@@ -224,11 +255,13 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
224255
->with(
225256
[
226257
'order' => $this->orderMock,
227-
'invoice' => $this->creditmemoMock,
258+
'creditmemo' => $this->creditmemoMock,
228259
'comment' => $customerNoteNotify ? $comment : '',
229-
'billing' => $billingAddress,
260+
'billing' => $addressMock,
230261
'payment_html' => 'payment',
231262
'store' => $this->storeMock,
263+
'formattedShippingAddress' => $address,
264+
'formattedBillingAddress' => $address
232265
]
233266
);
234267

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/InvoiceSenderTest.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ class InvoiceSenderTest extends \PHPUnit_Framework_TestCase
6565
*/
6666
protected $globalConfig;
6767

68+
/**
69+
* @var \Magento\Sales\Model\Order\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
70+
*/
71+
protected $addressRenderer;
72+
6873
protected function setUp()
6974
{
7075
$this->senderMock = $this->getMock(
@@ -110,6 +115,14 @@ protected function setUp()
110115
false
111116
);
112117

118+
$this->addressRenderer = $this->getMock(
119+
'Magento\Sales\Model\Order\Address\Renderer',
120+
['format'],
121+
[],
122+
'',
123+
false
124+
);
125+
113126
$this->storeMock = $this->getMock(
114127
'\Magento\Store\Model\Store',
115128
['getStoreId', '__wakeup'],
@@ -134,7 +147,7 @@ protected function setUp()
134147
[
135148
'getStore', 'getBillingAddress', 'getPayment',
136149
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
137-
'getCustomerEmail'
150+
'getCustomerEmail', 'getShippingAddress'
138151
],
139152
[],
140153
'',
@@ -179,7 +192,8 @@ protected function setUp()
179192
$this->senderBuilderFactoryMock,
180193
$this->paymentHelper,
181194
$this->invoiceResource,
182-
$this->globalConfig
195+
$this->globalConfig,
196+
$this->addressRenderer
183197
);
184198
}
185199

@@ -194,7 +208,7 @@ protected function setUp()
194208
public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
195209
{
196210
$comment = 'comment_test';
197-
$billingAddress = 'billing_address';
211+
$address = 'address_test';
198212
$configPath = 'sales_email/general/async_sending';
199213

200214
$this->invoiceMock->expects($this->once())
@@ -207,9 +221,26 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
207221
->willReturn($configValue);
208222

209223
if (!$configValue || $forceSyncMode) {
224+
$addressMock = $this->getMock(
225+
'Magento\Sales\Model\Order\Address',
226+
[],
227+
[],
228+
'',
229+
false
230+
);
231+
232+
$this->addressRenderer->expects($this->any())
233+
->method('format')
234+
->with($addressMock, 'html')
235+
->willReturn($address);
236+
210237
$this->orderMock->expects($this->any())
211238
->method('getBillingAddress')
212-
->willReturn($billingAddress);
239+
->willReturn($addressMock);
240+
241+
$this->orderMock->expects($this->any())
242+
->method('getShippingAddress')
243+
->willReturn($addressMock);
213244

214245
$this->invoiceMock->expects($this->once())
215246
->method('getCustomerNoteNotify')
@@ -226,9 +257,11 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
226257
'order' => $this->orderMock,
227258
'invoice' => $this->invoiceMock,
228259
'comment' => $customerNoteNotify ? $comment : '',
229-
'billing' => $billingAddress,
260+
'billing' => $addressMock,
230261
'payment_html' => 'payment',
231262
'store' => $this->storeMock,
263+
'formattedShippingAddress' => $address,
264+
'formattedBillingAddress' => $address
232265
]
233266
);
234267

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/OrderSenderTest.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ class OrderSenderTest extends \PHPUnit_Framework_TestCase
6161
*/
6262
protected $globalConfig;
6363

64+
/**
65+
* @var \Magento\Sales\Model\Order\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
66+
*/
67+
protected $addressRenderer;
68+
6469
protected function setUp()
6570
{
6671
$this->senderMock = $this->getMock(
@@ -112,6 +117,14 @@ protected function setUp()
112117
false
113118
);
114119

120+
$this->addressRenderer = $this->getMock(
121+
'Magento\Sales\Model\Order\Address\Renderer',
122+
['format'],
123+
[],
124+
'',
125+
false
126+
);
127+
115128
$this->storeMock = $this->getMock(
116129
'\Magento\Store\Model\Store',
117130
['getStoreId', '__wakeup'],
@@ -136,7 +149,8 @@ protected function setUp()
136149
[
137150
'getStore', 'getBillingAddress', 'getPayment',
138151
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
139-
'getCustomerEmail', 'setSendEmail', 'setEmailSent'
152+
'getCustomerEmail', 'setSendEmail', 'setEmailSent',
153+
'getShippingAddress'
140154
],
141155
[],
142156
'',
@@ -163,7 +177,8 @@ protected function setUp()
163177
$this->senderBuilderFactoryMock,
164178
$this->paymentHelper,
165179
$this->orderResource,
166-
$this->globalConfig
180+
$this->globalConfig,
181+
$this->addressRenderer
167182
);
168183
}
169184

@@ -176,7 +191,7 @@ protected function setUp()
176191
*/
177192
public function testSend($configValue, $forceSyncMode, $emailSendingResult)
178193
{
179-
$billingAddress = 'billing_address';
194+
$address = 'address_test';
180195
$configPath = 'sales_email/general/async_sending';
181196

182197
$this->orderMock->expects($this->once())
@@ -189,23 +204,42 @@ public function testSend($configValue, $forceSyncMode, $emailSendingResult)
189204
->willReturn($configValue);
190205

191206
if (!$configValue || $forceSyncMode) {
192-
$this->orderMock->expects($this->any())
193-
->method('getBillingAddress')
194-
->willReturn($billingAddress);
195-
196207
$this->identityContainerMock->expects($this->once())
197208
->method('isEnabled')
198209
->willReturn($emailSendingResult);
199210

200211
if ($emailSendingResult) {
212+
$addressMock = $this->getMock(
213+
'Magento\Sales\Model\Order\Address',
214+
[],
215+
[],
216+
'',
217+
false
218+
);
219+
220+
$this->addressRenderer->expects($this->any())
221+
->method('format')
222+
->with($addressMock, 'html')
223+
->willReturn($address);
224+
225+
$this->orderMock->expects($this->any())
226+
->method('getBillingAddress')
227+
->willReturn($addressMock);
228+
229+
$this->orderMock->expects($this->any())
230+
->method('getShippingAddress')
231+
->willReturn($addressMock);
232+
201233
$this->templateContainerMock->expects($this->once())
202234
->method('setTemplateVars')
203235
->with(
204236
[
205237
'order' => $this->orderMock,
206-
'billing' => $billingAddress,
238+
'billing' => $addressMock,
207239
'payment_html' => 'payment',
208240
'store' => $this->storeMock,
241+
'formattedShippingAddress' => $address,
242+
'formattedBillingAddress' => $address
209243
]
210244
);
211245

app/code/Magento/Sales/Test/Unit/Model/Order/Email/Sender/ShipmentSenderTest.php

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@ class ShipmentSenderTest extends \PHPUnit_Framework_TestCase
6666
*/
6767
protected $globalConfig;
6868

69+
/**
70+
* @var \Magento\Sales\Model\Order\Address\Renderer|\PHPUnit_Framework_MockObject_MockObject
71+
*/
72+
protected $addressRenderer;
73+
6974
protected function setUp()
7075
{
7176
$this->senderMock = $this->getMock(
@@ -111,6 +116,14 @@ protected function setUp()
111116
false
112117
);
113118

119+
$this->addressRenderer = $this->getMock(
120+
'Magento\Sales\Model\Order\Address\Renderer',
121+
['format'],
122+
[],
123+
'',
124+
false
125+
);
126+
114127
$this->storeMock = $this->getMock(
115128
'\Magento\Store\Model\Store',
116129
['getStoreId', '__wakeup'],
@@ -135,7 +148,7 @@ protected function setUp()
135148
[
136149
'getStore', 'getBillingAddress', 'getPayment',
137150
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
138-
'getCustomerEmail'
151+
'getCustomerEmail', 'getShippingAddress'
139152
],
140153
[],
141154
'',
@@ -180,7 +193,8 @@ protected function setUp()
180193
$this->senderBuilderFactoryMock,
181194
$this->paymentHelper,
182195
$this->shipmentResource,
183-
$this->globalConfig
196+
$this->globalConfig,
197+
$this->addressRenderer
184198
);
185199
}
186200

@@ -195,7 +209,7 @@ protected function setUp()
195209
public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $emailSendingResult)
196210
{
197211
$comment = 'comment_test';
198-
$billingAddress = 'billing_address';
212+
$address = 'address_test';
199213
$configPath = 'sales_email/general/async_sending';
200214

201215
$this->shipmentMock->expects($this->once())
@@ -208,9 +222,26 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
208222
->willReturn($configValue);
209223

210224
if (!$configValue || $forceSyncMode) {
225+
$addressMock = $this->getMock(
226+
'Magento\Sales\Model\Order\Address',
227+
[],
228+
[],
229+
'',
230+
false
231+
);
232+
233+
$this->addressRenderer->expects($this->any())
234+
->method('format')
235+
->with($addressMock, 'html')
236+
->willReturn($address);
237+
211238
$this->orderMock->expects($this->any())
212239
->method('getBillingAddress')
213-
->willReturn($billingAddress);
240+
->willReturn($addressMock);
241+
242+
$this->orderMock->expects($this->any())
243+
->method('getShippingAddress')
244+
->willReturn($addressMock);
214245

215246
$this->shipmentMock->expects($this->once())
216247
->method('getCustomerNoteNotify')
@@ -227,9 +258,11 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
227258
'order' => $this->orderMock,
228259
'shipment' => $this->shipmentMock,
229260
'comment' => $customerNoteNotify ? $comment : '',
230-
'billing' => $billingAddress,
261+
'billing' => $addressMock,
231262
'payment_html' => 'payment',
232263
'store' => $this->storeMock,
264+
'formattedShippingAddress' => $address,
265+
'formattedBillingAddress' => $address
233266
]
234267
);
235268

0 commit comments

Comments
 (0)