Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
InvoiceCommentSenderTest.php
Go to the documentation of this file.
1 <?php
7 
9 
11 {
15  protected $sender;
16 
20  protected $invoiceMock;
21 
22  protected function setUp()
23  {
24  $this->stepMockSetup();
25  $this->paymentHelper = $this->createPartialMock(\Magento\Payment\Helper\Data::class, ['getInfoBlockHtml']);
26 
27  $this->invoiceResource = $this->createMock(\Magento\Sales\Model\ResourceModel\Order\Invoice::class);
28 
29  $this->stepIdentityContainerInit(\Magento\Sales\Model\Order\Email\Container\InvoiceCommentIdentity::class);
30 
31  $this->addressRenderer->expects($this->any())->method('format')->willReturn(1);
32 
33  $this->invoiceMock = $this->createPartialMock(
34  \Magento\Sales\Model\Order\Invoice::class,
35  ['getStore', '__wakeup', 'getOrder']
36  );
37  $this->invoiceMock->expects($this->any())
38  ->method('getStore')
39  ->will($this->returnValue($this->storeMock));
40  $this->invoiceMock->expects($this->any())
41  ->method('getOrder')
42  ->will($this->returnValue($this->orderMock));
43 
44  $this->sender = new InvoiceCommentSender(
45  $this->templateContainerMock,
46  $this->identityContainerMock,
47  $this->senderBuilderFactoryMock,
48  $this->loggerMock,
49  $this->addressRenderer,
50  $this->eventManagerMock
51  );
52  }
53 
54  public function testSendFalse()
55  {
56  $this->stepAddressFormat($this->addressMock);
57  $result = $this->sender->send($this->invoiceMock);
58  $this->assertFalse($result);
59  }
60 
61  public function testSendTrueWithCustomerCopy()
62  {
65  $comment = 'comment_test';
66  $this->orderMock->expects($this->once())
67  ->method('getCustomerIsGuest')
68  ->will($this->returnValue(false));
69  $this->identityContainerMock->expects($this->once())
70  ->method('isEnabled')
71  ->will($this->returnValue(true));
72  $this->templateContainerMock->expects($this->once())
73  ->method('setTemplateVars')
74  ->with(
75  $this->equalTo(
76  [
77  'order' => $this->orderMock,
78  'invoice' => $this->invoiceMock,
79  'comment' => $comment,
80  'billing' => $billingAddress,
81  'store' => $this->storeMock,
82  'formattedShippingAddress' => 1,
83  'formattedBillingAddress' => 1
84  ]
85  )
86  );
87 
88  $this->stepSendWithoutSendCopy();
89  $result = $this->sender->send($this->invoiceMock, true, $comment);
90  $this->assertTrue($result);
91  }
92 
94  {
97  $comment = 'comment_test';
98  $this->orderMock->expects($this->once())
99  ->method('getCustomerIsGuest')
100  ->will($this->returnValue(false));
101 
102  $this->identityContainerMock->expects($this->once())
103  ->method('isEnabled')
104  ->will($this->returnValue(true));
105  $this->templateContainerMock->expects($this->once())
106  ->method('setTemplateVars')
107  ->with(
108  $this->equalTo(
109  [
110  'order' => $this->orderMock,
111  'invoice' => $this->invoiceMock,
112  'billing' => $billingAddress,
113  'comment' => $comment,
114  'store' => $this->storeMock,
115  'formattedShippingAddress' => 1,
116  'formattedBillingAddress' => 1
117  ]
118  )
119  );
121  $result = $this->sender->send($this->invoiceMock, false, $comment);
122  $this->assertTrue($result);
123  }
124 
125  public function testSendVirtualOrder()
126  {
127  $isVirtualOrder = true;
128  $this->orderMock->setData(\Magento\Sales\Api\Data\OrderInterface::IS_VIRTUAL, $isVirtualOrder);
129  $this->stepAddressFormat($this->addressMock, $isVirtualOrder);
130 
131  $this->identityContainerMock->expects($this->once())
132  ->method('isEnabled')
133  ->will($this->returnValue(false));
134  $this->templateContainerMock->expects($this->once())
135  ->method('setTemplateVars')
136  ->with(
137  $this->equalTo(
138  [
139  'order' => $this->orderMock,
140  'invoice' => $this->invoiceMock,
141  'billing' => $this->addressMock,
142  'comment' => '',
143  'store' => $this->storeMock,
144  'formattedShippingAddress' => null,
145  'formattedBillingAddress' => 1
146  ]
147  )
148  );
149  $this->assertFalse($this->sender->send($this->invoiceMock));
150  }
151 }
$billingAddress
Definition: order.php:25