Skip to content

Commit fd721b1

Browse files
admanesachinnathanjosiah
authored andcommitted
MC-20548: Refactor sales module templates to use scalar variables.
Fix unit tests for snakecase use case.
1 parent 6524305 commit fd721b1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+514
-130
lines changed

app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoCommentSender.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '')
7373
'store' => $order->getStore(),
7474
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
7575
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
76+
'order_data' => [
77+
'customer_name' => $order->getCustomerName(),
78+
'frontend_status_label' => $order->getFrontendStatusLabel()
79+
]
7680
];
7781
$transportObject = new DataObject($transport);
7882

app/code/Magento/Sales/Model/Order/Email/Sender/CreditmemoSender.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
115115
'store' => $order->getStore(),
116116
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
117117
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
118+
'order_data' => [
119+
'customer_name' => $order->getCustomerName(),
120+
'is_not_virtual' => $order->getIsNotVirtual(),
121+
'email_customer_note' => $order->getEmailCustomerNote(),
122+
'frontend_status_label' => $order->getFrontendStatusLabel()
123+
]
118124
];
119125
$transportObject = new DataObject($transport);
120126

app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceCommentSender.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function send(Invoice $invoice, $notify = true, $comment = '')
7373
'store' => $order->getStore(),
7474
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
7575
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
76+
'order_data' => [
77+
'customer_name' => $order->getCustomerName(),
78+
'frontend_status_label' => $order->getFrontendStatusLabel()
79+
]
7680
];
7781
$transportObject = new DataObject($transport);
7882

app/code/Magento/Sales/Model/Order/Email/Sender/InvoiceSender.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ public function send(Invoice $invoice, $forceSyncMode = false)
114114
'payment_html' => $this->getPaymentHtml($order),
115115
'store' => $order->getStore(),
116116
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
117-
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
117+
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
118+
'order_data' => [
119+
'customer_name' => $order->getCustomerName(),
120+
'is_not_virtual' => $order->getIsNotVirtual(),
121+
'email_customer_note' => $order->getEmailCustomerNote(),
122+
'frontend_status_label' => $order->getFrontendStatusLabel()
123+
]
118124
];
119125
$transportObject = new DataObject($transport);
120126

app/code/Magento/Sales/Model/Order/Email/Sender/OrderCommentSender.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ public function send(Order $order, $notify = true, $comment = '')
7070
'store' => $order->getStore(),
7171
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
7272
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
73+
'order_data' => [
74+
'customer_name' => $order->getCustomerName(),
75+
'frontend_status_label' => $order->getFrontendStatusLabel()
76+
]
7377
];
7478
$transportObject = new DataObject($transport);
7579

app/code/Magento/Sales/Model/Order/Email/Sender/OrderSender.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,13 @@ protected function prepareTemplate(Order $order)
130130
'store' => $order->getStore(),
131131
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
132132
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
133-
'created_at_formatted' => $order->getCreatedAtFormatted(2)
133+
'created_at_formatted' => $order->getCreatedAtFormatted(2),
134+
'order_data' => [
135+
'customer_name' => $order->getCustomerName(),
136+
'is_not_virtual' => $order->getIsNotVirtual(),
137+
'email_customer_note' => $order->getEmailCustomerNote(),
138+
'frontend_status_label' => $order->getFrontendStatusLabel()
139+
]
134140
];
135141
$transportObject = new DataObject($transport);
136142

app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentCommentSender.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@ public function send(Shipment $shipment, $notify = true, $comment = '')
7373
'store' => $order->getStore(),
7474
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
7575
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
76+
'order_data' => [
77+
'customer_name' => $order->getCustomerName(),
78+
'frontend_status_label' => $order->getFrontendStatusLabel()
79+
]
7680
];
7781
$transportObject = new DataObject($transport);
7882

app/code/Magento/Sales/Model/Order/Email/Sender/ShipmentSender.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,13 @@ public function send(Shipment $shipment, $forceSyncMode = false)
114114
'payment_html' => $this->getPaymentHtml($order),
115115
'store' => $order->getStore(),
116116
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
117-
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
117+
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
118+
'order_data' => [
119+
'customer_name' => $order->getCustomerName(),
120+
'is_not_virtual' => $order->getIsNotVirtual(),
121+
'email_customer_note' => $order->getEmailCustomerNote(),
122+
'frontend_status_label' => $order->getFrontendStatusLabel()
123+
]
118124
];
119125
$transportObject = new DataObject($transport);
120126

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ public function stepMockSetup()
9898
'getStore', 'getBillingAddress', 'getPayment',
9999
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
100100
'getCustomerEmail', 'getShippingAddress', 'setSendEmail',
101-
'setEmailSent', 'getCreatedAtFormatted'
101+
'setEmailSent', 'getCreatedAtFormatted', 'getIsNotVirtual',
102+
'getEmailCustomerNote', 'getFrontendStatusLabel'
102103
]
103104
);
104105
$this->orderMock->expects($this->any())

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

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ public function testSendVirtualOrder()
5959
{
6060
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, true);
6161
$billingAddress = $this->addressMock;
62+
$customerName = 'test customer';
63+
$frontendStatusLabel = 'Complete';
64+
65+
$this->orderMock->expects($this->any())
66+
->method('getCustomerName')
67+
->willReturn($customerName);
68+
$this->orderMock->expects($this->once())
69+
->method('getFrontendStatusLabel')
70+
->willReturn($frontendStatusLabel);
71+
6272
$this->templateContainerMock->expects($this->once())
6373
->method('setTemplateVars')
6474
->with(
@@ -70,7 +80,11 @@ public function testSendVirtualOrder()
7080
'billing' => $billingAddress,
7181
'store' => $this->storeMock,
7282
'formattedShippingAddress' => null,
73-
'formattedBillingAddress' => 1
83+
'formattedBillingAddress' => 1,
84+
'order_data' => [
85+
'customer_name' => $customerName,
86+
'frontend_status_label' => $frontendStatusLabel
87+
]
7488
]
7589
)
7690
);
@@ -83,6 +97,15 @@ public function testSendTrueWithCustomerCopy()
8397
{
8498
$billingAddress = $this->addressMock;
8599
$comment = 'comment_test';
100+
$customerName = 'test customer';
101+
$frontendStatusLabel = 'Complete';
102+
103+
$this->orderMock->expects($this->any())
104+
->method('getCustomerName')
105+
->willReturn($customerName);
106+
$this->orderMock->expects($this->once())
107+
->method('getFrontendStatusLabel')
108+
->willReturn($frontendStatusLabel);
86109

87110
$this->orderMock->expects($this->once())
88111
->method('getCustomerIsGuest')
@@ -102,7 +125,11 @@ public function testSendTrueWithCustomerCopy()
102125
'billing' => $billingAddress,
103126
'store' => $this->storeMock,
104127
'formattedShippingAddress' => 1,
105-
'formattedBillingAddress' => 1
128+
'formattedBillingAddress' => 1,
129+
'order_data' => [
130+
'customer_name' => $customerName,
131+
'frontend_status_label' => $frontendStatusLabel
132+
]
106133
]
107134
)
108135
);
@@ -115,6 +142,15 @@ public function testSendTrueWithoutCustomerCopy()
115142
{
116143
$billingAddress = $this->addressMock;
117144
$comment = 'comment_test';
145+
$customerName = 'test customer';
146+
$frontendStatusLabel = 'Complete';
147+
148+
$this->orderMock->expects($this->any())
149+
->method('getCustomerName')
150+
->willReturn($customerName);
151+
$this->orderMock->expects($this->once())
152+
->method('getFrontendStatusLabel')
153+
->willReturn($frontendStatusLabel);
118154

119155
$this->orderMock->expects($this->once())
120156
->method('getCustomerIsGuest')
@@ -134,7 +170,11 @@ public function testSendTrueWithoutCustomerCopy()
134170
'comment' => $comment,
135171
'store' => $this->storeMock,
136172
'formattedShippingAddress' => 1,
137-
'formattedBillingAddress' => 1
173+
'formattedBillingAddress' => 1,
174+
'order_data' => [
175+
'customer_name' => $customerName,
176+
'frontend_status_label' => $frontendStatusLabel
177+
]
138178
]
139179
)
140180
);

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

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
9090
$comment = 'comment_test';
9191
$address = 'address_test';
9292
$configPath = 'sales_email/general/async_sending';
93+
$customerName = 'test customer';
94+
$frontendStatusLabel = 'Processing';
95+
$isNotVirtual = true;
9396

9497
$this->creditmemoMock->expects($this->once())
9598
->method('setSendEmail')
@@ -118,6 +121,22 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
118121
->method('getCustomerNote')
119122
->willReturn($comment);
120123

124+
$this->orderMock->expects($this->any())
125+
->method('getCustomerName')
126+
->willReturn($customerName);
127+
128+
$this->orderMock->expects($this->once())
129+
->method('getIsNotVirtual')
130+
->willReturn($isNotVirtual);
131+
132+
$this->orderMock->expects($this->once())
133+
->method('getEmailCustomerNote')
134+
->willReturn('');
135+
136+
$this->orderMock->expects($this->once())
137+
->method('getFrontendStatusLabel')
138+
->willReturn($frontendStatusLabel);
139+
121140
$this->templateContainerMock->expects($this->once())
122141
->method('setTemplateVars')
123142
->with(
@@ -129,7 +148,13 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
129148
'payment_html' => 'payment',
130149
'store' => $this->storeMock,
131150
'formattedShippingAddress' => $address,
132-
'formattedBillingAddress' => $address
151+
'formattedBillingAddress' => $address,
152+
'order_data' => [
153+
'customer_name' => $customerName,
154+
'is_not_virtual' => $isNotVirtual,
155+
'email_customer_note' => '',
156+
'frontend_status_label' => $frontendStatusLabel
157+
]
133158
]
134159
);
135160

@@ -211,9 +236,28 @@ public function sendDataProvider()
211236
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
212237
{
213238
$billingAddress = 'address_test';
239+
$customerName = 'test customer';
240+
$frontendStatusLabel = 'Complete';
241+
$isNotVirtual = false;
214242

215243
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
216244

245+
$this->orderMock->expects($this->any())
246+
->method('getCustomerName')
247+
->willReturn($customerName);
248+
249+
$this->orderMock->expects($this->once())
250+
->method('getIsNotVirtual')
251+
->willReturn($isNotVirtual);
252+
253+
$this->orderMock->expects($this->once())
254+
->method('getEmailCustomerNote')
255+
->willReturn('');
256+
257+
$this->orderMock->expects($this->once())
258+
->method('getFrontendStatusLabel')
259+
->willReturn($frontendStatusLabel);
260+
217261
$this->creditmemoMock->expects($this->once())
218262
->method('setSendEmail')
219263
->with(false);
@@ -247,7 +291,14 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
247291
'payment_html' => 'payment',
248292
'store' => $this->storeMock,
249293
'formattedShippingAddress' => $expectedShippingAddress,
250-
'formattedBillingAddress' => $billingAddress
294+
'formattedBillingAddress' => $billingAddress,
295+
'order_data' => [
296+
'customer_name' => $customerName,
297+
'is_not_virtual' => $isNotVirtual,
298+
'email_customer_note' => '',
299+
'frontend_status_label' => $frontendStatusLabel
300+
]
301+
251302
]
252303
);
253304

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

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,20 @@ public function testSendTrueWithCustomerCopy()
6363
$billingAddress = $this->addressMock;
6464
$this->stepAddressFormat($billingAddress);
6565
$comment = 'comment_test';
66+
$customerName = 'Test Customer';
67+
$frontendStatusLabel = 'Processing';
6668
$this->orderMock->expects($this->once())
6769
->method('getCustomerIsGuest')
6870
->will($this->returnValue(false));
71+
72+
$this->orderMock->expects($this->any())
73+
->method('getCustomerName')
74+
->willReturn($customerName);
75+
76+
$this->orderMock->expects($this->any())
77+
->method('getFrontendStatusLabel')
78+
->willReturn($frontendStatusLabel);
79+
6980
$this->identityContainerMock->expects($this->once())
7081
->method('isEnabled')
7182
->will($this->returnValue(true));
@@ -80,7 +91,11 @@ public function testSendTrueWithCustomerCopy()
8091
'billing' => $billingAddress,
8192
'store' => $this->storeMock,
8293
'formattedShippingAddress' => 1,
83-
'formattedBillingAddress' => 1
94+
'formattedBillingAddress' => 1,
95+
'order_data' => [
96+
'customer_name' => $customerName,
97+
'frontend_status_label' => $frontendStatusLabel
98+
]
8499
]
85100
)
86101
);
@@ -93,12 +108,22 @@ public function testSendTrueWithCustomerCopy()
93108
public function testSendTrueWithoutCustomerCopy()
94109
{
95110
$billingAddress = $this->addressMock;
111+
$customerName = 'Test Customer';
112+
$frontendStatusLabel = 'Processing';
96113
$this->stepAddressFormat($billingAddress);
97114
$comment = 'comment_test';
98115
$this->orderMock->expects($this->once())
99116
->method('getCustomerIsGuest')
100117
->will($this->returnValue(false));
101118

119+
$this->orderMock->expects($this->any())
120+
->method('getCustomerName')
121+
->willReturn($customerName);
122+
123+
$this->orderMock->expects($this->any())
124+
->method('getFrontendStatusLabel')
125+
->willReturn($frontendStatusLabel);
126+
102127
$this->identityContainerMock->expects($this->once())
103128
->method('isEnabled')
104129
->will($this->returnValue(true));
@@ -113,7 +138,11 @@ public function testSendTrueWithoutCustomerCopy()
113138
'comment' => $comment,
114139
'store' => $this->storeMock,
115140
'formattedShippingAddress' => 1,
116-
'formattedBillingAddress' => 1
141+
'formattedBillingAddress' => 1,
142+
'order_data' => [
143+
'customer_name' => $customerName,
144+
'frontend_status_label' => $frontendStatusLabel
145+
]
117146
]
118147
)
119148
);
@@ -127,6 +156,16 @@ public function testSendVirtualOrder()
127156
$isVirtualOrder = true;
128157
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
129158
$this->stepAddressFormat($this->addressMock, $isVirtualOrder);
159+
$customerName = 'Test Customer';
160+
$frontendStatusLabel = 'Complete';
161+
162+
$this->orderMock->expects($this->any())
163+
->method('getCustomerName')
164+
->willReturn($customerName);
165+
166+
$this->orderMock->expects($this->any())
167+
->method('getFrontendStatusLabel')
168+
->willReturn($frontendStatusLabel);
130169

131170
$this->identityContainerMock->expects($this->once())
132171
->method('isEnabled')
@@ -142,7 +181,11 @@ public function testSendVirtualOrder()
142181
'comment' => '',
143182
'store' => $this->storeMock,
144183
'formattedShippingAddress' => null,
145-
'formattedBillingAddress' => 1
184+
'formattedBillingAddress' => 1,
185+
'order_data' => [
186+
'customer_name' => $customerName,
187+
'frontend_status_label' => $frontendStatusLabel
188+
]
146189
]
147190
)
148191
);

0 commit comments

Comments
 (0)