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