DataTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Multishipping\Test\Unit\Helper;
  7. /**
  8. * Multishipping data helper Test
  9. */
  10. class DataTest extends \PHPUnit\Framework\TestCase
  11. {
  12. /**
  13. * Multishipping data helper
  14. *
  15. * @var \Magento\Multishipping\Helper\Data
  16. */
  17. protected $helper;
  18. /**
  19. * Core store config mock
  20. *
  21. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
  22. */
  23. protected $scopeConfigMock;
  24. /**
  25. * Quote mock
  26. *
  27. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Quote\Model\Quote
  28. */
  29. protected $quoteMock;
  30. /**
  31. * Checkout session mock
  32. *
  33. * @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Checkout\Model\Session
  34. */
  35. protected $checkoutSessionMock;
  36. protected function setUp()
  37. {
  38. $this->quoteMock = $this->createMock(\Magento\Quote\Model\Quote::class);
  39. $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
  40. $arguments = $objectManager->getConstructArguments(\Magento\Multishipping\Helper\Data::class);
  41. $this->helper = $objectManager->getObject(\Magento\Multishipping\Helper\Data::class, $arguments);
  42. $this->checkoutSessionMock = $arguments['checkoutSession'];
  43. /** @var \Magento\Framework\App\Helper\Context $context */
  44. $context = $arguments['context'];
  45. $this->scopeConfigMock = $context->getScopeConfig();
  46. }
  47. public function testGetMaximumQty()
  48. {
  49. $maximumQty = 10;
  50. $this->scopeConfigMock->expects(
  51. $this->once()
  52. )->method(
  53. 'getValue'
  54. )->with(
  55. \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY
  56. )->will(
  57. $this->returnValue($maximumQty)
  58. );
  59. $this->assertEquals($maximumQty, $this->helper->getMaximumQty());
  60. }
  61. /**
  62. * @param bool $result
  63. * @param bool $quoteHasItems
  64. * @param bool $isMultiShipping
  65. * @param bool $hasItemsWithDecimalQty
  66. * @param bool $validateMinimumAmount
  67. * @param int $itemsSummaryQty
  68. * @param int $itemVirtualQty
  69. * @param int $maximumQty
  70. * @dataProvider isMultishippingCheckoutAvailableDataProvider
  71. */
  72. public function testIsMultishippingCheckoutAvailable(
  73. $result,
  74. $quoteHasItems,
  75. $isMultiShipping,
  76. $hasItemsWithDecimalQty,
  77. $validateMinimumAmount,
  78. $itemsSummaryQty,
  79. $itemVirtualQty,
  80. $maximumQty
  81. ) {
  82. $this->scopeConfigMock->expects(
  83. $this->once()
  84. )->method(
  85. 'isSetFlag'
  86. )->with(
  87. \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_AVAILABLE
  88. )->will(
  89. $this->returnValue($isMultiShipping)
  90. );
  91. $this->checkoutSessionMock->expects(
  92. $this->once()
  93. )->method(
  94. 'getQuote'
  95. )->will(
  96. $this->returnValue($this->quoteMock)
  97. );
  98. $this->quoteMock->expects($this->once())->method('hasItems')->will($this->returnValue($quoteHasItems));
  99. $this->quoteMock->expects(
  100. $this->any()
  101. )->method(
  102. 'hasItemsWithDecimalQty'
  103. )->will(
  104. $this->returnValue($hasItemsWithDecimalQty)
  105. );
  106. $this->quoteMock->expects(
  107. $this->any()
  108. )->method(
  109. 'validateMinimumAmount'
  110. )->with(
  111. true
  112. )->will(
  113. $this->returnValue($validateMinimumAmount)
  114. );
  115. $this->quoteMock->expects(
  116. $this->any()
  117. )->method(
  118. 'getItemsSummaryQty'
  119. )->will(
  120. $this->returnValue($itemsSummaryQty)
  121. );
  122. $this->quoteMock->expects(
  123. $this->any()
  124. )->method(
  125. 'getItemVirtualQty'
  126. )->will(
  127. $this->returnValue($itemVirtualQty)
  128. );
  129. $this->scopeConfigMock->expects(
  130. $this->any()
  131. )->method(
  132. 'getValue'
  133. )->with(
  134. \Magento\Multishipping\Helper\Data::XML_PATH_CHECKOUT_MULTIPLE_MAXIMUM_QUANTITY
  135. )->will(
  136. $this->returnValue($maximumQty)
  137. );
  138. $this->assertEquals($result, $this->helper->isMultishippingCheckoutAvailable());
  139. }
  140. /**
  141. * Data provider
  142. *
  143. * @return array
  144. */
  145. public function isMultishippingCheckoutAvailableDataProvider()
  146. {
  147. return [
  148. [true, false, true, null, null, null, null, null],
  149. [false, false, false, null, null, null, null, null],
  150. [false, true, true, true, null, null, null, null],
  151. [false, true, true, false, false, null, null, null],
  152. [true, true, true, false, true, 2, 1, 3],
  153. [false, true, true, false, true, 1, 2, null],
  154. [false, true, true, false, true, 2, 1, 1],
  155. ];
  156. }
  157. }