Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AddVatRequestParamsOrderCommentTest.php
Go to the documentation of this file.
1 <?php
7 
9 
13 class AddVatRequestParamsOrderCommentTest extends \PHPUnit\Framework\TestCase
14 {
19 
23  protected $observer;
24 
25  protected function setUp()
26  {
27  $this->customerAddressHelperMock = $this->getMockBuilder(\Magento\Customer\Helper\Address::class)
28  ->disableOriginalConstructor()
29  ->getMock();
30 
31  $this->observer = new AddVatRequestParamsOrderComment(
32  $this->customerAddressHelperMock
33  );
34  }
35 
44  $configAddressType,
45  $vatRequestId,
46  $vatRequestDate,
47  $orderHistoryComment
48  ) {
49  $this->customerAddressHelperMock->expects($this->once())
50  ->method('getTaxCalculationAddressType')
51  ->will($this->returnValue($configAddressType));
52 
53  $orderAddressMock = $this->createPartialMock(
54  \Magento\Sales\Model\Order\Address::class,
55  ['getVatRequestId', 'getVatRequestDate', '__wakeup']
56  );
57  $orderAddressMock->expects($this->any())
58  ->method('getVatRequestId')
59  ->will($this->returnValue($vatRequestId));
60  $orderAddressMock->expects($this->any())
61  ->method('getVatRequestDate')
62  ->will($this->returnValue($vatRequestDate));
63 
64  $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
65  ->disableOriginalConstructor()
66  ->setMethods(['getShippingAddress', '__wakeup', 'addStatusHistoryComment', 'getBillingAddress'])
67  ->getMock();
68  $orderMock->expects($this->any())
69  ->method('getShippingAddress')
70  ->will($this->returnValue($orderAddressMock));
71  if ($orderHistoryComment === null) {
72  $orderMock->expects($this->never())
73  ->method('addStatusHistoryComment');
74  } else {
75  $orderMock->expects($this->once())
76  ->method('addStatusHistoryComment')
77  ->with($orderHistoryComment, false);
78  }
79  $observer = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getOrder']);
80  $observer->expects($this->once())
81  ->method('getOrder')
82  ->will($this->returnValue($orderMock));
83 
84  $this->assertNull($this->observer->execute($observer));
85  }
86 
91  {
92  return [
93  [
94  \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
95  'vatRequestId',
96  'vatRequestDate',
97  'VAT Request Identifier: vatRequestId<br />VAT Request Date: vatRequestDate',
98  ],
99  [
100  \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
101  1,
102  'vatRequestDate',
103  null,
104  ],
105  [
106  \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
107  'vatRequestId',
108  1,
109  null,
110  ],
111  [
112  null,
113  'vatRequestId',
114  'vatRequestDate',
115  null,
116  ],
117  [
118  \Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING,
119  'vatRequestId',
120  'vatRequestDate',
121  null,
122  ],
123  ];
124  }
125 }
testAddVatRequestParamsOrderComment( $configAddressType, $vatRequestId, $vatRequestDate, $orderHistoryComment)