AddVatRequestParamsOrderCommentTest.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Test\Unit\Observer\Frontend;
  7. use Magento\Sales\Observer\Frontend\AddVatRequestParamsOrderComment;
  8. /**
  9. * Tests Magento\Sales\Observer\Frontend\AddVatRequestParamsOrderComment
  10. */
  11. class AddVatRequestParamsOrderCommentTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \Magento\Customer\Helper\Address|\PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $customerAddressHelperMock;
  17. /**
  18. * @var AddVatRequestParamsOrderComment
  19. */
  20. protected $observer;
  21. protected function setUp()
  22. {
  23. $this->customerAddressHelperMock = $this->getMockBuilder(\Magento\Customer\Helper\Address::class)
  24. ->disableOriginalConstructor()
  25. ->getMock();
  26. $this->observer = new AddVatRequestParamsOrderComment(
  27. $this->customerAddressHelperMock
  28. );
  29. }
  30. /**
  31. * @param string $configAddressType
  32. * @param string|int $vatRequestId
  33. * @param string|int $vatRequestDate
  34. * @param string $orderHistoryComment
  35. * @dataProvider addVatRequestParamsOrderCommentDataProvider
  36. */
  37. public function testAddVatRequestParamsOrderComment(
  38. $configAddressType,
  39. $vatRequestId,
  40. $vatRequestDate,
  41. $orderHistoryComment
  42. ) {
  43. $this->customerAddressHelperMock->expects($this->once())
  44. ->method('getTaxCalculationAddressType')
  45. ->will($this->returnValue($configAddressType));
  46. $orderAddressMock = $this->createPartialMock(
  47. \Magento\Sales\Model\Order\Address::class,
  48. ['getVatRequestId', 'getVatRequestDate', '__wakeup']
  49. );
  50. $orderAddressMock->expects($this->any())
  51. ->method('getVatRequestId')
  52. ->will($this->returnValue($vatRequestId));
  53. $orderAddressMock->expects($this->any())
  54. ->method('getVatRequestDate')
  55. ->will($this->returnValue($vatRequestDate));
  56. $orderMock = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
  57. ->disableOriginalConstructor()
  58. ->setMethods(['getShippingAddress', '__wakeup', 'addStatusHistoryComment', 'getBillingAddress'])
  59. ->getMock();
  60. $orderMock->expects($this->any())
  61. ->method('getShippingAddress')
  62. ->will($this->returnValue($orderAddressMock));
  63. if ($orderHistoryComment === null) {
  64. $orderMock->expects($this->never())
  65. ->method('addStatusHistoryComment');
  66. } else {
  67. $orderMock->expects($this->once())
  68. ->method('addStatusHistoryComment')
  69. ->with($orderHistoryComment, false);
  70. }
  71. $observer = $this->createPartialMock(\Magento\Framework\Event\Observer::class, ['getOrder']);
  72. $observer->expects($this->once())
  73. ->method('getOrder')
  74. ->will($this->returnValue($orderMock));
  75. $this->assertNull($this->observer->execute($observer));
  76. }
  77. /**
  78. * @return array
  79. */
  80. public function addVatRequestParamsOrderCommentDataProvider()
  81. {
  82. return [
  83. [
  84. \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
  85. 'vatRequestId',
  86. 'vatRequestDate',
  87. 'VAT Request Identifier: vatRequestId<br />VAT Request Date: vatRequestDate',
  88. ],
  89. [
  90. \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
  91. 1,
  92. 'vatRequestDate',
  93. null,
  94. ],
  95. [
  96. \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING,
  97. 'vatRequestId',
  98. 1,
  99. null,
  100. ],
  101. [
  102. null,
  103. 'vatRequestId',
  104. 'vatRequestDate',
  105. null,
  106. ],
  107. [
  108. \Magento\Customer\Model\Address\AbstractAddress::TYPE_BILLING,
  109. 'vatRequestId',
  110. 'vatRequestDate',
  111. null,
  112. ],
  113. ];
  114. }
  115. }