Skip to content

Commit

Permalink
MC-20548: Refactor sales module templates to use scalar variables.
Browse files Browse the repository at this point in the history
Fix unit tests for snakecase use case.
  • Loading branch information
admanesachin authored and nathanjosiah committed Nov 6, 2019
1 parent 6524305 commit fd721b1
Show file tree
Hide file tree
Showing 49 changed files with 514 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function send(Creditmemo $creditmemo, $notify = true, $comment = '')
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public function send(Creditmemo $creditmemo, $forceSyncMode = false)
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'is_not_virtual' => $order->getIsNotVirtual(),
'email_customer_note' => $order->getEmailCustomerNote(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function send(Invoice $invoice, $notify = true, $comment = '')
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ public function send(Invoice $invoice, $forceSyncMode = false)
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'is_not_virtual' => $order->getIsNotVirtual(),
'email_customer_note' => $order->getEmailCustomerNote(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ public function send(Order $order, $notify = true, $comment = '')
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,13 @@ protected function prepareTemplate(Order $order)
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'created_at_formatted' => $order->getCreatedAtFormatted(2)
'created_at_formatted' => $order->getCreatedAtFormatted(2),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'is_not_virtual' => $order->getIsNotVirtual(),
'email_customer_note' => $order->getEmailCustomerNote(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function send(Shipment $shipment, $notify = true, $comment = '')
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,13 @@ public function send(Shipment $shipment, $forceSyncMode = false)
'payment_html' => $this->getPaymentHtml($order),
'store' => $order->getStore(),
'formattedShippingAddress' => $this->getFormattedShippingAddress($order),
'formattedBillingAddress' => $this->getFormattedBillingAddress($order)
'formattedBillingAddress' => $this->getFormattedBillingAddress($order),
'order_data' => [
'customer_name' => $order->getCustomerName(),
'is_not_virtual' => $order->getIsNotVirtual(),
'email_customer_note' => $order->getEmailCustomerNote(),
'frontend_status_label' => $order->getFrontendStatusLabel()
]
];
$transportObject = new DataObject($transport);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public function stepMockSetup()
'getStore', 'getBillingAddress', 'getPayment',
'__wakeup', 'getCustomerIsGuest', 'getCustomerName',
'getCustomerEmail', 'getShippingAddress', 'setSendEmail',
'setEmailSent', 'getCreatedAtFormatted'
'setEmailSent', 'getCreatedAtFormatted', 'getIsNotVirtual',
'getEmailCustomerNote', 'getFrontendStatusLabel'
]
);
$this->orderMock->expects($this->any())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ public function testSendVirtualOrder()
{
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, true);
$billingAddress = $this->addressMock;
$customerName = 'test customer';
$frontendStatusLabel = 'Complete';

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);
$this->orderMock->expects($this->once())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->templateContainerMock->expects($this->once())
->method('setTemplateVars')
->with(
Expand All @@ -70,7 +80,11 @@ public function testSendVirtualOrder()
'billing' => $billingAddress,
'store' => $this->storeMock,
'formattedShippingAddress' => null,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand All @@ -83,6 +97,15 @@ public function testSendTrueWithCustomerCopy()
{
$billingAddress = $this->addressMock;
$comment = 'comment_test';
$customerName = 'test customer';
$frontendStatusLabel = 'Complete';

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);
$this->orderMock->expects($this->once())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->orderMock->expects($this->once())
->method('getCustomerIsGuest')
Expand All @@ -102,7 +125,11 @@ public function testSendTrueWithCustomerCopy()
'billing' => $billingAddress,
'store' => $this->storeMock,
'formattedShippingAddress' => 1,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand All @@ -115,6 +142,15 @@ public function testSendTrueWithoutCustomerCopy()
{
$billingAddress = $this->addressMock;
$comment = 'comment_test';
$customerName = 'test customer';
$frontendStatusLabel = 'Complete';

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);
$this->orderMock->expects($this->once())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->orderMock->expects($this->once())
->method('getCustomerIsGuest')
Expand All @@ -134,7 +170,11 @@ public function testSendTrueWithoutCustomerCopy()
'comment' => $comment,
'store' => $this->storeMock,
'formattedShippingAddress' => 1,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
$comment = 'comment_test';
$address = 'address_test';
$configPath = 'sales_email/general/async_sending';
$customerName = 'test customer';
$frontendStatusLabel = 'Processing';
$isNotVirtual = true;

$this->creditmemoMock->expects($this->once())
->method('setSendEmail')
Expand Down Expand Up @@ -118,6 +121,22 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
->method('getCustomerNote')
->willReturn($comment);

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);

$this->orderMock->expects($this->once())
->method('getIsNotVirtual')
->willReturn($isNotVirtual);

$this->orderMock->expects($this->once())
->method('getEmailCustomerNote')
->willReturn('');

$this->orderMock->expects($this->once())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->templateContainerMock->expects($this->once())
->method('setTemplateVars')
->with(
Expand All @@ -129,7 +148,13 @@ public function testSend($configValue, $forceSyncMode, $customerNoteNotify, $ema
'payment_html' => 'payment',
'store' => $this->storeMock,
'formattedShippingAddress' => $address,
'formattedBillingAddress' => $address
'formattedBillingAddress' => $address,
'order_data' => [
'customer_name' => $customerName,
'is_not_virtual' => $isNotVirtual,
'email_customer_note' => '',
'frontend_status_label' => $frontendStatusLabel
]
]
);

Expand Down Expand Up @@ -211,9 +236,28 @@ public function sendDataProvider()
public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expectedShippingAddress)
{
$billingAddress = 'address_test';
$customerName = 'test customer';
$frontendStatusLabel = 'Complete';
$isNotVirtual = false;

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

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);

$this->orderMock->expects($this->once())
->method('getIsNotVirtual')
->willReturn($isNotVirtual);

$this->orderMock->expects($this->once())
->method('getEmailCustomerNote')
->willReturn('');

$this->orderMock->expects($this->once())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->creditmemoMock->expects($this->once())
->method('setSendEmail')
->with(false);
Expand Down Expand Up @@ -247,7 +291,14 @@ public function testSendVirtualOrder($isVirtualOrder, $formatCallCount, $expecte
'payment_html' => 'payment',
'store' => $this->storeMock,
'formattedShippingAddress' => $expectedShippingAddress,
'formattedBillingAddress' => $billingAddress
'formattedBillingAddress' => $billingAddress,
'order_data' => [
'customer_name' => $customerName,
'is_not_virtual' => $isNotVirtual,
'email_customer_note' => '',
'frontend_status_label' => $frontendStatusLabel
]

]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,20 @@ public function testSendTrueWithCustomerCopy()
$billingAddress = $this->addressMock;
$this->stepAddressFormat($billingAddress);
$comment = 'comment_test';
$customerName = 'Test Customer';
$frontendStatusLabel = 'Processing';
$this->orderMock->expects($this->once())
->method('getCustomerIsGuest')
->will($this->returnValue(false));

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);

$this->orderMock->expects($this->any())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
->will($this->returnValue(true));
Expand All @@ -80,7 +91,11 @@ public function testSendTrueWithCustomerCopy()
'billing' => $billingAddress,
'store' => $this->storeMock,
'formattedShippingAddress' => 1,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand All @@ -93,12 +108,22 @@ public function testSendTrueWithCustomerCopy()
public function testSendTrueWithoutCustomerCopy()
{
$billingAddress = $this->addressMock;
$customerName = 'Test Customer';
$frontendStatusLabel = 'Processing';
$this->stepAddressFormat($billingAddress);
$comment = 'comment_test';
$this->orderMock->expects($this->once())
->method('getCustomerIsGuest')
->will($this->returnValue(false));

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);

$this->orderMock->expects($this->any())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
->will($this->returnValue(true));
Expand All @@ -113,7 +138,11 @@ public function testSendTrueWithoutCustomerCopy()
'comment' => $comment,
'store' => $this->storeMock,
'formattedShippingAddress' => 1,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand All @@ -127,6 +156,16 @@ public function testSendVirtualOrder()
$isVirtualOrder = true;
$this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
$this->stepAddressFormat($this->addressMock, $isVirtualOrder);
$customerName = 'Test Customer';
$frontendStatusLabel = 'Complete';

$this->orderMock->expects($this->any())
->method('getCustomerName')
->willReturn($customerName);

$this->orderMock->expects($this->any())
->method('getFrontendStatusLabel')
->willReturn($frontendStatusLabel);

$this->identityContainerMock->expects($this->once())
->method('isEnabled')
Expand All @@ -142,7 +181,11 @@ public function testSendVirtualOrder()
'comment' => '',
'store' => $this->storeMock,
'formattedShippingAddress' => null,
'formattedBillingAddress' => 1
'formattedBillingAddress' => 1,
'order_data' => [
'customer_name' => $customerName,
'frontend_status_label' => $frontendStatusLabel
]
]
)
);
Expand Down
Loading

0 comments on commit fd721b1

Please sign in to comment.