QuoteItemTest.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\GiftMessage\Test\Unit\Model\Plugin;
  7. class QuoteItemTest extends \PHPUnit\Framework\TestCase
  8. {
  9. /**
  10. * @var \Magento\Bundle\Model\Plugin\QuoteItem
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $quoteItemMock;
  17. /**
  18. * @var \Closure
  19. */
  20. protected $closureMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $orderItemMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $helperMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $subjectMock;
  33. protected function setUp()
  34. {
  35. $this->orderItemMock = $this->createPartialMock(
  36. \Magento\Sales\Model\Order\Item::class,
  37. ['setGiftMessageId', 'setGiftMessageAvailable', '__wakeup']
  38. );
  39. $this->quoteItemMock = $this->createPartialMock(
  40. \Magento\Quote\Model\Quote\Item::class,
  41. ['getGiftMessageId', 'getStoreId', '__wakeup']
  42. );
  43. $orderItems = $this->orderItemMock;
  44. $this->closureMock = function () use ($orderItems) {
  45. return $orderItems;
  46. };
  47. $this->subjectMock = $this->createMock(\Magento\Quote\Model\Quote\Item\ToOrderItem::class);
  48. $this->helperMock = $this->createPartialMock(
  49. \Magento\GiftMessage\Helper\Message::class,
  50. ['setGiftMessageId', 'isMessagesAllowed']
  51. );
  52. $this->model = new \Magento\GiftMessage\Model\Plugin\QuoteItem($this->helperMock);
  53. }
  54. public function testAfterItemToOrderItem()
  55. {
  56. $storeId = 1;
  57. $giftMessageId = 1;
  58. $isMessageAvailable = true;
  59. $this->quoteItemMock->expects($this->any())->method('getStoreId')->will($this->returnValue($storeId));
  60. $this->quoteItemMock->expects(
  61. $this->any()
  62. )->method(
  63. 'getGiftMessageId'
  64. )->will(
  65. $this->returnValue($giftMessageId)
  66. );
  67. $this->helperMock->expects(
  68. $this->once()
  69. )->method(
  70. 'isMessagesAllowed'
  71. )->with(
  72. 'item',
  73. $this->quoteItemMock,
  74. $storeId
  75. )->will(
  76. $this->returnValue($isMessageAvailable)
  77. );
  78. $this->orderItemMock->expects($this->once())->method('setGiftMessageId')->with($giftMessageId);
  79. $this->orderItemMock->expects($this->once())->method('setGiftMessageAvailable')->with($isMessageAvailable);
  80. $this->assertSame(
  81. $this->orderItemMock,
  82. $this->model->afterConvert($this->subjectMock, $this->orderItemMock, $this->quoteItemMock, [])
  83. );
  84. }
  85. }