PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/magento/module-multishipping/Test/Unit/Model/Checkout/Type/MultishippingTest.php

https://gitlab.com/yousafsyed/easternglamor
PHP | 271 lines | 183 code | 39 blank | 49 comment | 0 complexity | 9f6d30fa3b9921c34e594ec83cc5d5ca MD5 | raw file
  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Multishipping\Test\Unit\Model\Checkout\Type;
  7. class MultishippingTest extends \PHPUnit_Framework_TestCase
  8. {
  9. /**
  10. * @var \Magento\Multishipping\Model\Checkout\Type\Multishipping
  11. */
  12. protected $model;
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $checkoutSessionMock;
  17. /**
  18. * @var \PHPUnit_Framework_MockObject_MockObject
  19. */
  20. protected $customerSessionMock;
  21. /**
  22. * @var \PHPUnit_Framework_MockObject_MockObject
  23. */
  24. protected $customerMock;
  25. /**
  26. * @var \PHPUnit_Framework_MockObject_MockObject
  27. */
  28. protected $quoteMock;
  29. /**
  30. * @var \PHPUnit_Framework_MockObject_MockObject
  31. */
  32. protected $helperMock;
  33. /**
  34. * @var \PHPUnit_Framework_MockObject_MockObject
  35. */
  36. protected $filterBuilderMock;
  37. /**
  38. * @var \PHPUnit_Framework_MockObject_MockObject
  39. */
  40. protected $addressRepositoryMock;
  41. /**
  42. * @var \PHPUnit_Framework_MockObject_MockObject
  43. */
  44. protected $searchCriteriaBuilderMock;
  45. /**
  46. * @var \PHPUnit_Framework_MockObject_MockObject
  47. */
  48. protected $totalsCollectorMock;
  49. protected function setUp()
  50. {
  51. $this->checkoutSessionMock = $this->getMock('\Magento\Checkout\Model\Session', [], [], '', false);
  52. $this->customerSessionMock = $this->getMock('\Magento\Customer\Model\Session', [], [], '', false);
  53. $orderFactoryMock = $this->getMock('\Magento\Sales\Model\OrderFactory', [], [], '', false);
  54. $eventManagerMock = $this->getMock('\Magento\Framework\Event\ManagerInterface', [], [], '', false);
  55. $scopeConfigMock = $this->getMock('\Magento\Framework\App\Config\ScopeConfigInterface', [], [], '', false);
  56. $sessionMock = $this->getMock('\Magento\Framework\Session\Generic', [], [], '', false);
  57. $addressFactoryMock = $this->getMock('\Magento\Quote\Model\Quote\AddressFactory', [], [], '', false);
  58. $toOrderMock = $this->getMock('\Magento\Quote\Model\Quote\Address\ToOrder', [], [], '', false);
  59. $toOrderAddressMock = $this->getMock('\Magento\Quote\Model\Quote\Address\ToOrderAddress', [], [], '', false);
  60. $toOrderPaymentMock = $this->getMock('\Magento\Quote\Model\Quote\Payment\ToOrderPayment', [], [], '', false);
  61. $toOrderItemMock = $this->getMock('\Magento\Quote\Model\Quote\Item\ToOrderItem', [], [], '', false);
  62. $storeManagerMock = $this->getMock('\Magento\Store\Model\StoreManagerInterface', [], [], '', false);
  63. $paymentSpecMock = $this->getMock('\Magento\Payment\Model\Method\SpecificationInterface', [], [], '', false);
  64. $this->helperMock = $this->getMock('\Magento\Multishipping\Helper\Data', [], [], '', false);
  65. $orderSenderMock = $this->getMock('\Magento\Sales\Model\Order\Email\Sender\OrderSender', [], [], '', false);
  66. $priceMock = $this->getMock('\Magento\Framework\Pricing\PriceCurrencyInterface', [], [], '', false);
  67. $quoteRepositoryMock = $this->getMock('\Magento\Quote\Api\CartRepositoryInterface');
  68. $this->filterBuilderMock = $this->getMock('\Magento\Framework\Api\FilterBuilder', [], [], '', false);
  69. $this->searchCriteriaBuilderMock = $this->getMock(
  70. '\Magento\Framework\Api\SearchCriteriaBuilder',
  71. [],
  72. [],
  73. '',
  74. false
  75. );
  76. $this->addressRepositoryMock = $this->getMock(
  77. '\Magento\Customer\Api\AddressRepositoryInterface',
  78. [],
  79. [],
  80. '',
  81. false
  82. );
  83. /**
  84. * This is used to get past _init() which is called in construct.
  85. */
  86. $data['checkout_session'] = $this->checkoutSessionMock;
  87. $this->quoteMock = $this->getMock('\Magento\Quote\Model\Quote', [], [], '', false);
  88. $this->customerMock = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface', [], [], '', false);
  89. $this->customerMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
  90. $this->checkoutSessionMock->expects($this->atLeastOnce())->method('getQuote')->willReturn($this->quoteMock);
  91. $this->customerSessionMock->expects($this->atLeastOnce())->method('getCustomerDataObject')
  92. ->willReturn($this->customerMock);
  93. $this->totalsCollectorMock = $this->getMock('Magento\Quote\Model\Quote\TotalsCollector', [], [], '', false);
  94. $this->model = new \Magento\Multishipping\Model\Checkout\Type\Multishipping(
  95. $this->checkoutSessionMock,
  96. $this->customerSessionMock,
  97. $orderFactoryMock,
  98. $this->addressRepositoryMock,
  99. $eventManagerMock,
  100. $scopeConfigMock,
  101. $sessionMock,
  102. $addressFactoryMock,
  103. $toOrderMock,
  104. $toOrderAddressMock,
  105. $toOrderPaymentMock,
  106. $toOrderItemMock,
  107. $storeManagerMock,
  108. $paymentSpecMock,
  109. $this->helperMock,
  110. $orderSenderMock,
  111. $priceMock,
  112. $quoteRepositoryMock,
  113. $this->searchCriteriaBuilderMock,
  114. $this->filterBuilderMock,
  115. $this->totalsCollectorMock,
  116. $data
  117. );
  118. }
  119. public function testSetShippingItemsInformation()
  120. {
  121. $info = [
  122. [
  123. 1 => [
  124. 'qty' => 2,
  125. 'address' => 42
  126. ]
  127. ]
  128. ];
  129. $this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([]);
  130. $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
  131. $this->helperMock->expects($this->once())->method('getMaximumQty')->willReturn(500);
  132. $this->quoteMock->expects($this->once())->method('getItemById')->with(array_keys($info[0])[0])
  133. ->willReturn(null);
  134. $this->quoteMock->expects($this->atLeastOnce())->method('getAllItems')->willReturn([]);
  135. $this->filterBuilderMock->expects($this->atLeastOnce())->method('setField')->willReturnSelf();
  136. $this->filterBuilderMock->expects($this->atLeastOnce())->method('setValue')->willReturnSelf();
  137. $this->filterBuilderMock->expects($this->atLeastOnce())->method('setConditionType')->willReturnSelf();
  138. $this->filterBuilderMock->expects($this->atLeastOnce())->method('create')->willReturnSelf();
  139. $searchCriteriaMock = $this->getMock('\Magento\Framework\Api\SearchCriteria', [], [], '', false);
  140. $this->searchCriteriaBuilderMock->expects($this->atLeastOnce())->method('addFilters')->willReturnSelf();
  141. $this->searchCriteriaBuilderMock->expects($this->atLeastOnce())->method('create')
  142. ->willReturn($searchCriteriaMock);
  143. $resultMock = $this->getMock('\Magento\Customer\Api\Data\AddressSearchResultsInterface', [], [], '', false);
  144. $this->addressRepositoryMock->expects($this->atLeastOnce())->method('getList')->willReturn($resultMock);
  145. $addressItemMock = $this->getMock('\Magento\Customer\Api\Data\AddressInterface', [], [], '', false);
  146. $resultMock->expects($this->atLeastOnce())->method('getItems')->willReturn([$addressItemMock]);
  147. $addressItemMock->expects($this->atLeastOnce())->method('getId')->willReturn(null);
  148. $this->assertEquals($this->model, $this->model->setShippingItemsInformation($info));
  149. }
  150. /**
  151. * @expectedException \Magento\Framework\Exception\LocalizedException
  152. * @expectedExceptionMessage Please check shipping address information.
  153. */
  154. public function testSetShippingItemsInformationForAddressLeak()
  155. {
  156. $info = [
  157. [
  158. 1 => [
  159. 'qty' => 2,
  160. 'address' => 43
  161. ]
  162. ]
  163. ];
  164. $customerAddressId = 42;
  165. $customerAddressMock = $this->getMock('\Magento\Customer\Model\Data\Address', [], [], '', false);
  166. $customerAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn($customerAddressId);
  167. $customerAddresses = [$customerAddressMock];
  168. $quoteItemMock = $this->getMock('\Magento\Quote\Model\Quote\Item', [], [], '', false);
  169. $this->quoteMock->expects($this->once())->method('getItemById')->willReturn($quoteItemMock);
  170. $this->quoteMock->expects($this->once())->method('getAllShippingAddresses')->willReturn([]);
  171. $this->checkoutSessionMock->expects($this->any())->method('getQuote')->willReturn($this->quoteMock);
  172. $this->helperMock->expects($this->once())->method('getMaximumQty')->willReturn(500);
  173. $this->customerMock->expects($this->once())->method('getAddresses')->willReturn($customerAddresses);
  174. $this->assertEquals($this->model, $this->model->setShippingItemsInformation($info));
  175. }
  176. public function testupdateQuoteCustomerShippingAddress()
  177. {
  178. $addressId = 42;
  179. $customerAddressId = 42;
  180. $customerAddressMock = $this->getMock('\Magento\Customer\Model\Data\Address', [], [], '', false);
  181. $customerAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn($customerAddressId);
  182. $customerAddresses = [$customerAddressMock];
  183. $this->customerMock->expects($this->once())->method('getAddresses')->willReturn($customerAddresses);
  184. $this->addressRepositoryMock->expects($this->once())->method('getById')->willReturn(null);
  185. $this->assertEquals($this->model, $this->model->updateQuoteCustomerShippingAddress($addressId));
  186. }
  187. /**
  188. * @expectedException \Magento\Framework\Exception\LocalizedException
  189. * @expectedExceptionMessage Please check shipping address information.
  190. */
  191. public function testupdateQuoteCustomerShippingAddressForAddressLeak()
  192. {
  193. $addressId = 43;
  194. $customerAddressId = 42;
  195. $customerAddressMock = $this->getMock('\Magento\Customer\Model\Data\Address', [], [], '', false);
  196. $customerAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn($customerAddressId);
  197. $customerAddresses = [$customerAddressMock];
  198. $this->customerMock->expects($this->once())->method('getAddresses')->willReturn($customerAddresses);
  199. $this->assertEquals($this->model, $this->model->updateQuoteCustomerShippingAddress($addressId));
  200. }
  201. public function testSetQuoteCustomerBillingAddress()
  202. {
  203. $addressId = 42;
  204. $customerAddressId = 42;
  205. $customerAddressMock = $this->getMock('\Magento\Customer\Model\Data\Address', [], [], '', false);
  206. $customerAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn($customerAddressId);
  207. $customerAddresses = [$customerAddressMock];
  208. $this->customerMock->expects($this->once())->method('getAddresses')->willReturn($customerAddresses);
  209. $this->assertEquals($this->model, $this->model->setQuoteCustomerBillingAddress($addressId));
  210. }
  211. /**
  212. * @expectedException \Magento\Framework\Exception\LocalizedException
  213. * @expectedExceptionMessage Please check billing address information.
  214. */
  215. public function testSetQuoteCustomerBillingAddressForAddressLeak()
  216. {
  217. $addressId = 43;
  218. $customerAddressId = 42;
  219. $customerAddressMock = $this->getMock('\Magento\Customer\Model\Data\Address', [], [], '', false);
  220. $customerAddressMock->expects($this->atLeastOnce())->method('getId')->willReturn($customerAddressId);
  221. $customerAddresses = [$customerAddressMock];
  222. $this->customerMock->expects($this->once())->method('getAddresses')->willReturn($customerAddresses);
  223. $this->assertEquals($this->model, $this->model->setQuoteCustomerBillingAddress($addressId));
  224. }
  225. public function testGetQuoteShippingAddressesItems()
  226. {
  227. $quoteItem = $this->getMock('Magento\Quote\Model\Quote\Address\Item', [], [], '', false);
  228. $this->checkoutSessionMock->expects($this->once())->method('getQuote')->willReturn($this->quoteMock);
  229. $this->quoteMock->expects($this->once())->method('getShippingAddressesItems')->willReturn($quoteItem);
  230. $this->model->getQuoteShippingAddressesItems();
  231. }
  232. }