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