QuoteTest.php 44 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Quote\Test\Unit\Model;
  7. use Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface;
  8. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  9. use Magento\Quote\Api\Data\CartInterface;
  10. use Magento\Quote\Model\Quote\Address;
  11. use Magento\Store\Model\ScopeInterface;
  12. /**
  13. * Test class for \Magento\Quote\Model
  14. *
  15. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  16. * @SuppressWarnings(PHPMD.TooManyFields)
  17. */
  18. class QuoteTest extends \PHPUnit\Framework\TestCase
  19. {
  20. /**
  21. * @var \Magento\Quote\Model\Quote\AddressFactory|\PHPUnit_Framework_MockObject_MockObject
  22. */
  23. protected $quoteAddressFactoryMock;
  24. /**
  25. * @var \Magento\Quote\Model\Quote\Address|\PHPUnit_Framework_MockObject_MockObject
  26. */
  27. protected $quoteAddressMock;
  28. /**
  29. * @var \Magento\Quote\Model\ResourceModel\Quote\Address\Collection|\PHPUnit_Framework_MockObject_MockObject
  30. */
  31. protected $quoteAddressCollectionMock;
  32. /**
  33. * @var \PHPUnit_Framework_MockObject_MockObject
  34. */
  35. protected $storeManagerMock;
  36. /**
  37. * @var \PHPUnit_Framework_MockObject_MockObject
  38. */
  39. protected $resourceMock;
  40. /**
  41. * @var \PHPUnit_Framework_MockObject_MockObject
  42. */
  43. protected $contextMock;
  44. /**
  45. * @var \PHPUnit_Framework_MockObject_MockObject
  46. */
  47. protected $customerFactoryMock;
  48. /**
  49. * @var \PHPUnit_Framework_MockObject_MockObject
  50. */
  51. protected $eventManagerMock;
  52. /**
  53. * @var \PHPUnit_Framework_MockObject_MockObject
  54. */
  55. protected $groupRepositoryMock;
  56. /**
  57. * @var \Magento\Quote\Model\Quote
  58. */
  59. protected $quote;
  60. /**
  61. * @var \Magento\Catalog\Model\Product |\PHPUnit_Framework_MockObject_MockObject
  62. */
  63. protected $productMock;
  64. /**
  65. * @var \Magento\Framework\DataObject\Factory |\PHPUnit_Framework_MockObject_MockObject
  66. */
  67. protected $objectFactoryMock;
  68. /**
  69. * @var \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
  70. */
  71. protected $quoteItemCollectionFactoryMock;
  72. /**
  73. * @var \Magento\Quote\Model\Quote\PaymentFactory
  74. */
  75. protected $paymentFactoryMock;
  76. /**
  77. * @var \Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory
  78. */
  79. protected $quotePaymentCollectionFactoryMock;
  80. /**
  81. * @var \Magento\Framework\App\Config | \PHPUnit_Framework_MockObject_MockObject
  82. */
  83. protected $scopeConfig;
  84. /**
  85. * @var \Magento\Customer\Api\AddressRepositoryInterface | \PHPUnit_Framework_MockObject_MockObject
  86. */
  87. protected $addressRepositoryMock;
  88. /**
  89. * @var \Magento\Framework\Api\SearchCriteriaBuilder | \PHPUnit_Framework_MockObject_MockObject
  90. */
  91. protected $criteriaBuilderMock;
  92. /**
  93. * @var \Magento\Framework\Api\FilterBuilder | \PHPUnit_Framework_MockObject_MockObject
  94. */
  95. protected $filterBuilderMock;
  96. /**
  97. * @var \Magento\Framework\Api\ExtensibleDataObjectConverter | \PHPUnit_Framework_MockObject_MockObject
  98. */
  99. protected $extensibleDataObjectConverterMock;
  100. /**
  101. * @var \Magento\Customer\Api\CustomerRepositoryInterface | \PHPUnit_Framework_MockObject_MockObject
  102. */
  103. protected $customerRepositoryMock;
  104. /**
  105. * @var \Magento\Framework\DataObject\Copy | \PHPUnit_Framework_MockObject_MockObject
  106. */
  107. protected $objectCopyServiceMock;
  108. /**
  109. * @var JoinProcessorInterface|\PHPUnit_Framework_MockObject_MockObject
  110. */
  111. private $extensionAttributesJoinProcessorMock;
  112. /**
  113. * @var \Magento\Customer\Api\Data\CustomerInterfaceFactory|\PHPUnit_Framework_MockObject_MockObject
  114. */
  115. private $customerDataFactoryMock;
  116. /**
  117. * @var \PHPUnit_Framework_MockObject_MockObject
  118. */
  119. private $itemProcessor;
  120. /**
  121. * @var \Magento\Sales\Model\OrderIncrementIdChecker|\PHPUnit_Framework_MockObject_MockObject
  122. */
  123. private $orderIncrementIdChecker;
  124. /**
  125. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  126. */
  127. protected function setUp()
  128. {
  129. $this->quoteAddressFactoryMock = $this->createPartialMock(
  130. \Magento\Quote\Model\Quote\AddressFactory::class,
  131. ['create']
  132. );
  133. $this->quoteAddressMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Address::class, [
  134. 'isDeleted', 'getCollection', 'getId', 'getCustomerAddressId',
  135. '__wakeup', 'getAddressType', 'getDeleteImmediately', 'validateMinimumAmount', 'setData'
  136. ]);
  137. $this->quoteAddressCollectionMock = $this->createMock(
  138. \Magento\Quote\Model\ResourceModel\Quote\Address\Collection::class
  139. );
  140. $this->extensibleDataObjectConverterMock = $this->createPartialMock(
  141. \Magento\Framework\Api\ExtensibleDataObjectConverter::class,
  142. ['toFlatArray']
  143. );
  144. $this->customerRepositoryMock = $this->getMockForAbstractClass(
  145. \Magento\Customer\Api\CustomerRepositoryInterface::class,
  146. [],
  147. '',
  148. false,
  149. true,
  150. true,
  151. ['getById', 'save']
  152. );
  153. $this->objectCopyServiceMock = $this->createPartialMock(
  154. \Magento\Framework\DataObject\Copy::class,
  155. ['copyFieldsetToTarget']
  156. );
  157. $this->productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
  158. $this->objectFactoryMock = $this->createPartialMock(\Magento\Framework\DataObject\Factory::class, ['create']);
  159. $this->quoteAddressFactoryMock->expects(
  160. $this->any()
  161. )->method(
  162. 'create'
  163. )->will(
  164. $this->returnValue($this->quoteAddressMock)
  165. );
  166. $this->quoteAddressMock->expects(
  167. $this->any()
  168. )->method(
  169. 'getCollection'
  170. )->will(
  171. $this->returnValue($this->quoteAddressCollectionMock)
  172. );
  173. $this->eventManagerMock = $this->getMockBuilder(\Magento\Framework\Event\Manager::class)
  174. ->disableOriginalConstructor()
  175. ->getMock();
  176. $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManager::class)
  177. ->disableOriginalConstructor()
  178. ->getMock();
  179. $this->resourceMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote::class)
  180. ->disableOriginalConstructor()
  181. ->getMock();
  182. $this->contextMock = $this->getMockBuilder(\Magento\Framework\Model\Context::class)
  183. ->disableOriginalConstructor()
  184. ->getMock();
  185. $this->customerFactoryMock = $this->getMockBuilder(\Magento\Customer\Model\CustomerFactory::class)
  186. ->disableOriginalConstructor()
  187. ->setMethods(['create'])
  188. ->getMock();
  189. $this->groupRepositoryMock = $this->getMockBuilder(\Magento\Customer\Api\GroupRepositoryInterface::class)
  190. ->disableOriginalConstructor()
  191. ->getMock();
  192. $this->contextMock->expects($this->any())
  193. ->method('getEventDispatcher')
  194. ->will($this->returnValue($this->eventManagerMock));
  195. $this->quoteItemCollectionFactoryMock = $this->createPartialMock(
  196. \Magento\Quote\Model\ResourceModel\Quote\Item\CollectionFactory::class,
  197. ['create']
  198. );
  199. $this->quotePaymentCollectionFactoryMock = $this->createPartialMock(
  200. \Magento\Quote\Model\ResourceModel\Quote\Payment\CollectionFactory::class,
  201. ['create']
  202. );
  203. $this->paymentFactoryMock = $this->createPartialMock(
  204. \Magento\Quote\Model\Quote\PaymentFactory::class,
  205. ['create']
  206. );
  207. $this->scopeConfig = $this->getMockBuilder(\Magento\Framework\App\Config::class)
  208. ->disableOriginalConstructor()
  209. ->getMock();
  210. $this->addressRepositoryMock = $this->getMockForAbstractClass(
  211. \Magento\Customer\Api\AddressRepositoryInterface::class,
  212. [],
  213. '',
  214. false
  215. );
  216. $this->criteriaBuilderMock = $this->getMockBuilder(\Magento\Framework\Api\SearchCriteriaBuilder::class)
  217. ->disableOriginalConstructor()
  218. ->getMock();
  219. $this->filterBuilderMock = $this->getMockBuilder(\Magento\Framework\Api\FilterBuilder::class)
  220. ->disableOriginalConstructor()
  221. ->getMock();
  222. $this->itemProcessor = $this->getMockBuilder(\Magento\Quote\Model\Quote\Item\Processor::class)
  223. ->disableOriginalConstructor()
  224. ->getMock();
  225. $this->extensionAttributesJoinProcessorMock = $this->createMock(
  226. \Magento\Framework\Api\ExtensionAttribute\JoinProcessorInterface::class
  227. );
  228. $this->customerDataFactoryMock = $this->createPartialMock(
  229. \Magento\Customer\Api\Data\CustomerInterfaceFactory::class,
  230. ['create']
  231. );
  232. $this->orderIncrementIdChecker = $this->createMock(\Magento\Sales\Model\OrderIncrementIdChecker::class);
  233. $this->quote = (new ObjectManager($this))
  234. ->getObject(
  235. \Magento\Quote\Model\Quote::class,
  236. [
  237. 'quoteAddressFactory' => $this->quoteAddressFactoryMock,
  238. 'storeManager' => $this->storeManagerMock,
  239. 'resource' => $this->resourceMock,
  240. 'context' => $this->contextMock,
  241. 'customerFactory' => $this->customerFactoryMock,
  242. 'groupRepository' => $this->groupRepositoryMock,
  243. 'objectFactory' => $this->objectFactoryMock,
  244. 'addressRepository' => $this->addressRepositoryMock,
  245. 'criteriaBuilder' => $this->criteriaBuilderMock,
  246. 'filterBuilder' => $this->filterBuilderMock,
  247. 'quoteItemCollectionFactory' => $this->quoteItemCollectionFactoryMock,
  248. 'quotePaymentCollectionFactory' => $this->quotePaymentCollectionFactoryMock,
  249. 'quotePaymentFactory' => $this->paymentFactoryMock,
  250. 'scopeConfig' => $this->scopeConfig,
  251. 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock,
  252. 'customerRepository' => $this->customerRepositoryMock,
  253. 'objectCopyService' => $this->objectCopyServiceMock,
  254. 'extensionAttributesJoinProcessor' => $this->extensionAttributesJoinProcessorMock,
  255. 'customerDataFactory' => $this->customerDataFactoryMock,
  256. 'itemProcessor' => $this->itemProcessor,
  257. 'orderIncrementIdChecker' => $this->orderIncrementIdChecker,
  258. 'data' => [
  259. 'reserved_order_id' => 1000001,
  260. ],
  261. ]
  262. );
  263. }
  264. /**
  265. * @param array $addresses
  266. * @param bool $expected
  267. * @dataProvider isMultipleShippingAddressesDataProvider
  268. */
  269. public function testIsMultipleShippingAddresses($addresses, $expected)
  270. {
  271. $this->quoteAddressCollectionMock->expects(
  272. $this->any()
  273. )->method(
  274. 'setQuoteFilter'
  275. )->will(
  276. $this->returnValue($this->quoteAddressCollectionMock)
  277. );
  278. $this->quoteAddressCollectionMock->expects(
  279. $this->once()
  280. )->method(
  281. 'getIterator'
  282. )->will(
  283. $this->returnValue(new \ArrayIterator($addresses))
  284. );
  285. $this->assertEquals($expected, $this->quote->isMultipleShippingAddresses());
  286. }
  287. /**
  288. * Customer group ID is not set to quote object and customer data is not available.
  289. */
  290. public function testGetCustomerGroupIdNotSet()
  291. {
  292. $this->assertEquals(
  293. \Magento\Customer\Model\GroupManagement::NOT_LOGGED_IN_ID,
  294. $this->quote->getCustomerGroupId(),
  295. "Customer group ID is invalid"
  296. );
  297. }
  298. /**
  299. * Customer group ID is set to quote object.
  300. */
  301. public function testGetCustomerGroupId()
  302. {
  303. /** Preconditions */
  304. $customerGroupId = 33;
  305. $this->quote->setCustomerGroupId($customerGroupId);
  306. /** SUT execution */
  307. $this->assertEquals($customerGroupId, $this->quote->getCustomerGroupId(), "Customer group ID is invalid");
  308. }
  309. /**
  310. * @return array
  311. */
  312. public function isMultipleShippingAddressesDataProvider()
  313. {
  314. return [
  315. [
  316. [$this->getAddressMock(Address::TYPE_SHIPPING), $this->getAddressMock(Address::TYPE_SHIPPING)],
  317. true,
  318. ],
  319. [
  320. [$this->getAddressMock(Address::TYPE_SHIPPING), $this->getAddressMock(Address::TYPE_BILLING)],
  321. false
  322. ]
  323. ];
  324. }
  325. /**
  326. * @param string $type One of \Magento\Customer\Model\Address\AbstractAddress::TYPE_ const
  327. * @return \PHPUnit_Framework_MockObject_MockObject
  328. */
  329. protected function getAddressMock($type)
  330. {
  331. $shippingAddressMock = $this->createPartialMock(
  332. \Magento\Quote\Model\Quote\Address::class,
  333. ['getAddressType', '__wakeup', 'isDeleted']
  334. );
  335. $shippingAddressMock->expects($this->any())->method('getAddressType')->will($this->returnValue($type));
  336. $shippingAddressMock->expects($this->any())->method('isDeleted')->will($this->returnValue(false));
  337. return $shippingAddressMock;
  338. }
  339. public function testGetStoreIdNoId()
  340. {
  341. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  342. ->disableOriginalConstructor()
  343. ->getMock();
  344. $storeMock->expects($this->once())
  345. ->method('getId')
  346. ->will($this->returnValue(null));
  347. $this->storeManagerMock->expects($this->once())
  348. ->method('getStore')
  349. ->will($this->returnValue($storeMock));
  350. $result = $this->quote->getStoreId();
  351. $this->assertNull($result);
  352. }
  353. public function testGetStoreId()
  354. {
  355. $storeId = 1;
  356. $result = $this->quote->setStoreId($storeId)->getStoreId();
  357. $this->assertEquals($storeId, $result);
  358. }
  359. public function testGetStore()
  360. {
  361. $storeId = 1;
  362. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  363. ->disableOriginalConstructor()
  364. ->getMock();
  365. $this->storeManagerMock->expects($this->once())
  366. ->method('getStore')
  367. ->with($storeId)
  368. ->will($this->returnValue($storeMock));
  369. $this->quote->setStoreId($storeId);
  370. $result = $this->quote->getStore();
  371. $this->assertInstanceOf(\Magento\Store\Model\Store::class, $result);
  372. }
  373. public function testSetStore()
  374. {
  375. $storeId = 1;
  376. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  377. ->disableOriginalConstructor()
  378. ->getMock();
  379. $storeMock->expects($this->once())
  380. ->method('getId')
  381. ->will($this->returnValue($storeId));
  382. $result = $this->quote->setStore($storeMock);
  383. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  384. }
  385. public function testGetSharedWebsiteStoreIds()
  386. {
  387. $sharedIds = null;
  388. $storeIds = [1, 2, 3];
  389. $websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class)
  390. ->disableOriginalConstructor()
  391. ->getMock();
  392. $websiteMock->expects($this->once())
  393. ->method('getStoreIds')
  394. ->will($this->returnValue($storeIds));
  395. $this->quote->setData('shared_store_ids', $sharedIds);
  396. $this->quote->setWebsite($websiteMock);
  397. $result = $this->quote->getSharedStoreIds();
  398. $this->assertEquals($storeIds, $result);
  399. }
  400. public function testGetSharedStoreIds()
  401. {
  402. $sharedIds = null;
  403. $storeIds = [1, 2, 3];
  404. $storeId = 1;
  405. $websiteMock = $this->getMockBuilder(\Magento\Store\Model\Website::class)
  406. ->disableOriginalConstructor()
  407. ->getMock();
  408. $websiteMock->expects($this->once())
  409. ->method('getStoreIds')
  410. ->will($this->returnValue($storeIds));
  411. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  412. ->disableOriginalConstructor()
  413. ->getMock();
  414. $storeMock->expects($this->once())
  415. ->method('getWebsite')
  416. ->will($this->returnValue($websiteMock));
  417. $this->storeManagerMock->expects($this->once())
  418. ->method('getStore')
  419. ->with($storeId)
  420. ->will($this->returnValue($storeMock));
  421. $this->quote->setData('shared_store_ids', $sharedIds);
  422. $this->quote->setStoreId($storeId);
  423. $result = $this->quote->getSharedStoreIds();
  424. $this->assertEquals($storeIds, $result);
  425. }
  426. public function testLoadActive()
  427. {
  428. $quoteId = 1;
  429. $this->resourceMock->expects($this->once())
  430. ->method('loadActive')
  431. ->with($this->quote, $quoteId);
  432. $this->eventManagerMock->expects($this->any())
  433. ->method('dispatch');
  434. $result = $this->quote->loadActive($quoteId);
  435. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  436. }
  437. public function testloadByIdWithoutStore()
  438. {
  439. $quoteId = 1;
  440. $this->resourceMock->expects($this->once())
  441. ->method('loadByIdWithoutStore')
  442. ->with($this->quote, $quoteId);
  443. $this->eventManagerMock->expects($this->any())
  444. ->method('dispatch');
  445. $result = $this->quote->loadByIdWithoutStore($quoteId);
  446. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  447. }
  448. /**
  449. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  450. */
  451. public function testSetCustomerAddressData()
  452. {
  453. $customerId = 1;
  454. $addressMock = $this->getMockForAbstractClass(
  455. \Magento\Customer\Api\Data\AddressInterface::class,
  456. [],
  457. '',
  458. false,
  459. true,
  460. true,
  461. ['getId']
  462. );
  463. $addressMock->expects($this->any())
  464. ->method('getId')
  465. ->will($this->returnValue(null));
  466. $addresses = [$addressMock];
  467. $customerMock = $this->getMockForAbstractClass(
  468. \Magento\Customer\Api\Data\CustomerInterface::class,
  469. [],
  470. '',
  471. false
  472. );
  473. $customerResultMock = $this->getMockForAbstractClass(
  474. \Magento\Customer\Api\Data\CustomerInterface::class,
  475. [],
  476. '',
  477. false
  478. );
  479. $requestMock = $this->createMock(
  480. \Magento\Framework\DataObject::class
  481. );
  482. $this->extensibleDataObjectConverterMock->expects($this->any())
  483. ->method('toFlatArray')
  484. ->will($this->returnValue(['customer_id' => $customerId]));
  485. $this->customerRepositoryMock->expects($this->any())
  486. ->method('getById')
  487. ->will($this->returnValue($customerMock));
  488. $this->customerDataFactoryMock->expects($this->any())
  489. ->method('create')
  490. ->will($this->returnValue($customerMock));
  491. $this->customerRepositoryMock->expects($this->never())
  492. ->method('save')
  493. ->will($this->returnValue($customerMock));
  494. $customerMock->expects($this->any())
  495. ->method('getAddresses')
  496. ->will($this->returnValue($addresses));
  497. $this->objectFactoryMock->expects($this->once())
  498. ->method('create')
  499. ->with($this->equalTo(['customer_id' => $customerId]))
  500. ->will($this->returnValue($requestMock));
  501. $result = $this->quote->setCustomerAddressData([$addressMock]);
  502. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  503. $this->assertEquals($customerResultMock, $this->quote->getCustomer());
  504. }
  505. public function testGetCustomerTaxClassId()
  506. {
  507. $groupId = 1;
  508. $taxClassId = 1;
  509. $groupMock = $this->getMockForAbstractClass(\Magento\Customer\Api\Data\GroupInterface::class, [], '', false);
  510. $groupMock->expects($this->once())
  511. ->method('getTaxClassId')
  512. ->willReturn($taxClassId);
  513. $this->groupRepositoryMock->expects($this->once())
  514. ->method('getById')
  515. ->with($groupId)
  516. ->will($this->returnValue($groupMock));
  517. $this->quote->setData('customer_group_id', $groupId);
  518. $result = $this->quote->getCustomerTaxClassId();
  519. $this->assertEquals($taxClassId, $result);
  520. }
  521. public function testGetAllAddresses()
  522. {
  523. $id = 1;
  524. $this->quoteAddressCollectionMock->expects($this->once())
  525. ->method('setQuoteFilter')
  526. ->with($id)
  527. ->will($this->returnSelf());
  528. $this->quoteAddressMock->expects($this->once())
  529. ->method('isDeleted')
  530. ->will($this->returnValue(false));
  531. $iterator = new \ArrayIterator([$this->quoteAddressMock]);
  532. $this->quoteAddressCollectionMock->expects($this->any())
  533. ->method('getIterator')
  534. ->will($this->returnValue($iterator));
  535. $this->quote->setId($id);
  536. $result = $this->quote->getAllAddresses();
  537. $this->assertEquals([$this->quoteAddressMock], $result);
  538. }
  539. /**
  540. * @dataProvider dataProviderGetAddress
  541. */
  542. public function testGetAddressById($addressId, $expected)
  543. {
  544. $id = 1;
  545. $this->quoteAddressCollectionMock->expects($this->once())
  546. ->method('setQuoteFilter')
  547. ->with($id)
  548. ->will($this->returnSelf());
  549. $this->quoteAddressMock->expects($this->once())
  550. ->method('getId')
  551. ->will($this->returnValue($id));
  552. $iterator = new \ArrayIterator([$this->quoteAddressMock]);
  553. $this->quoteAddressCollectionMock->expects($this->any())
  554. ->method('getIterator')
  555. ->will($this->returnValue($iterator));
  556. $this->quote->setId($id);
  557. $result = $this->quote->getAddressById($addressId);
  558. $this->assertEquals((bool)$expected, (bool)$result);
  559. }
  560. /**
  561. * @return array
  562. */
  563. public static function dataProviderGetAddress()
  564. {
  565. return [
  566. [1, true],
  567. [2, false]
  568. ];
  569. }
  570. /**
  571. * @param $isDeleted
  572. * @param $customerAddressId
  573. * @param $expected
  574. *
  575. * @dataProvider dataProviderGetAddressByCustomer
  576. */
  577. public function testGetAddressByCustomerAddressId($isDeleted, $customerAddressId, $expected)
  578. {
  579. $id = 1;
  580. $this->quoteAddressCollectionMock->expects($this->once())
  581. ->method('setQuoteFilter')
  582. ->with($id)
  583. ->will($this->returnSelf());
  584. $this->quoteAddressMock->expects($this->once())
  585. ->method('isDeleted')
  586. ->will($this->returnValue($isDeleted));
  587. $this->quoteAddressMock->expects($this->once())
  588. ->method('getCustomerAddressId')
  589. ->will($this->returnValue($customerAddressId));
  590. $iterator = new \ArrayIterator([$this->quoteAddressMock]);
  591. $this->quoteAddressCollectionMock->expects($this->any())
  592. ->method('getIterator')
  593. ->will($this->returnValue($iterator));
  594. $this->quote->setId($id);
  595. $result = $this->quote->getAddressByCustomerAddressId($id);
  596. $this->assertEquals((bool)$expected, (bool)$result);
  597. }
  598. /**
  599. * @return array
  600. */
  601. public static function dataProviderGetAddressByCustomer()
  602. {
  603. return [
  604. [false, 1, true],
  605. [false, 2, false]
  606. ];
  607. }
  608. /**
  609. * @param $isDeleted
  610. * @param $addressType
  611. * @param $customerAddressId
  612. * @param $expected
  613. *
  614. * @dataProvider dataProviderShippingAddress
  615. */
  616. public function testGetShippingAddressByCustomerAddressId($isDeleted, $addressType, $customerAddressId, $expected)
  617. {
  618. $id = 1;
  619. $this->quoteAddressCollectionMock->expects($this->once())
  620. ->method('setQuoteFilter')
  621. ->with($id)
  622. ->will($this->returnSelf());
  623. $this->quoteAddressMock->expects($this->once())
  624. ->method('isDeleted')
  625. ->will($this->returnValue($isDeleted));
  626. $this->quoteAddressMock->expects($this->once())
  627. ->method('getCustomerAddressId')
  628. ->will($this->returnValue($customerAddressId));
  629. $this->quoteAddressMock->expects($this->once())
  630. ->method('getAddressType')
  631. ->will($this->returnValue($addressType));
  632. $iterator = new \ArrayIterator([$this->quoteAddressMock]);
  633. $this->quoteAddressCollectionMock->expects($this->any())
  634. ->method('getIterator')
  635. ->will($this->returnValue($iterator));
  636. $this->quote->setId($id);
  637. $result = $this->quote->getShippingAddressByCustomerAddressId($id);
  638. $this->assertEquals($expected, (bool)$result);
  639. }
  640. /**
  641. * @return array
  642. */
  643. public static function dataProviderShippingAddress()
  644. {
  645. return [
  646. [false, \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING, 1, true],
  647. [false, \Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING, 2, false],
  648. ];
  649. }
  650. public function testRemoveAddress()
  651. {
  652. $id = 1;
  653. $this->quoteAddressCollectionMock->expects($this->once())
  654. ->method('setQuoteFilter')
  655. ->with($id)
  656. ->will($this->returnSelf());
  657. $this->quoteAddressMock->expects($this->once())
  658. ->method('isDeleted')
  659. ->with(true);
  660. $this->quoteAddressMock->expects($this->once())
  661. ->method('getId')
  662. ->will($this->returnValue($id));
  663. $iterator = new \ArrayIterator([$this->quoteAddressMock]);
  664. $this->quoteAddressCollectionMock->expects($this->any())
  665. ->method('getIterator')
  666. ->will($this->returnValue($iterator));
  667. $this->quote->setId($id);
  668. $result = $this->quote->removeAddress($id);
  669. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  670. }
  671. public function testRemoveAllAddresses()
  672. {
  673. $id = 1;
  674. $this->quoteAddressCollectionMock->expects($this->once())
  675. ->method('setQuoteFilter')
  676. ->with($id)
  677. ->will($this->returnSelf());
  678. $this->quoteAddressMock->expects($this->any())
  679. ->method('getAddressType')
  680. ->will($this->returnValue(\Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING));
  681. $this->quoteAddressMock->expects($this->any())
  682. ->method('getAddressType')
  683. ->will($this->returnValue(\Magento\Customer\Model\Address\AbstractAddress::TYPE_SHIPPING));
  684. $this->quoteAddressMock->expects($this->any())
  685. ->method('isDeleted')
  686. ->will($this->returnValue(false));
  687. $this->quoteAddressMock->expects($this->any())
  688. ->method('setData')
  689. ->will($this->returnSelf());
  690. $this->quoteAddressMock->expects($this->once())
  691. ->method('getId')
  692. ->will($this->returnValue($id));
  693. $this->quoteAddressMock->expects($this->once())
  694. ->method('getDeleteImmediately')
  695. ->will($this->returnValue(true));
  696. $iterator = new \ArrayIterator([$id => $this->quoteAddressMock]);
  697. $this->quoteAddressCollectionMock->expects($this->any())
  698. ->method('getIterator')
  699. ->will($this->returnValue($iterator));
  700. $this->quoteAddressCollectionMock->expects($this->once())
  701. ->method('removeItemByKey')
  702. ->with($id)
  703. ->will($this->returnValue($iterator));
  704. $this->quote->setId($id);
  705. $result = $this->quote->removeAllAddresses();
  706. $this->assertInstanceOf(\Magento\Quote\Model\Quote::class, $result);
  707. }
  708. /**
  709. * @expectedException \Magento\Framework\Exception\LocalizedException
  710. */
  711. public function testAddProductException()
  712. {
  713. $this->quote->addProduct($this->productMock, 'test');
  714. }
  715. public function testAddProductNoCandidates()
  716. {
  717. $expectedResult = 'test_string';
  718. $requestMock = $this->createMock(
  719. \Magento\Framework\DataObject::class
  720. );
  721. $this->objectFactoryMock->expects($this->once())
  722. ->method('create')
  723. ->with($this->equalTo(['qty' => 1]))
  724. ->will($this->returnValue($requestMock));
  725. $this->productMock->expects($this->once())
  726. ->method('isSalable')
  727. ->willReturn(true);
  728. $typeInstanceMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Type\Simple::class, [
  729. 'prepareForCartAdvanced'
  730. ]);
  731. $typeInstanceMock->expects($this->once())
  732. ->method('prepareForCartAdvanced')
  733. ->will($this->returnValue($expectedResult));
  734. $this->productMock->expects($this->once())
  735. ->method('getTypeInstance')
  736. ->will($this->returnValue($typeInstanceMock));
  737. $result = $this->quote->addProduct($this->productMock, null);
  738. $this->assertEquals($expectedResult, $result);
  739. }
  740. public function testAddProductItemPreparation()
  741. {
  742. $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
  743. $expectedResult = $itemMock;
  744. $requestMock = $this->createMock(
  745. \Magento\Framework\DataObject::class
  746. );
  747. $this->objectFactoryMock->expects($this->once())
  748. ->method('create')
  749. ->with($this->equalTo(['qty' => 1]))
  750. ->will($this->returnValue($requestMock));
  751. $typeInstanceMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Type\Simple::class, [
  752. 'prepareForCartAdvanced'
  753. ]);
  754. $productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, [
  755. 'getParentProductId',
  756. 'setStickWithinParent',
  757. '__wakeup'
  758. ]);
  759. $collectionMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote\Item\Collection::class);
  760. $itemMock->expects($this->any())
  761. ->method('representProduct')
  762. ->will($this->returnValue(true));
  763. $iterator = new \ArrayIterator([$itemMock]);
  764. $collectionMock->expects($this->any())
  765. ->method('getIterator')
  766. ->will($this->returnValue($iterator));
  767. $this->quoteItemCollectionFactoryMock->expects($this->once())
  768. ->method('create')
  769. ->will($this->returnValue($collectionMock));
  770. $this->productMock->expects($this->once())
  771. ->method('isSalable')
  772. ->willReturn(true);
  773. $typeInstanceMock->expects($this->once())
  774. ->method('prepareForCartAdvanced')
  775. ->will($this->returnValue([$productMock]));
  776. $this->productMock->expects($this->once())
  777. ->method('getTypeInstance')
  778. ->will($this->returnValue($typeInstanceMock));
  779. $result = $this->quote->addProduct($this->productMock, null);
  780. $this->assertEquals($expectedResult, $result);
  781. }
  782. public function testAddProductItemNew()
  783. {
  784. $itemMock = $this->createMock(\Magento\Quote\Model\Quote\Item::class);
  785. $expectedResult = $itemMock;
  786. $requestMock = $this->createMock(
  787. \Magento\Framework\DataObject::class
  788. );
  789. $this->objectFactoryMock->expects($this->once())
  790. ->method('create')
  791. ->with($this->equalTo(['qty' => 1]))
  792. ->will($this->returnValue($requestMock));
  793. $typeInstanceMock = $this->createPartialMock(\Magento\Catalog\Model\Product\Type\Simple::class, [
  794. 'prepareForCartAdvanced'
  795. ]);
  796. $productMock = $this->createPartialMock(\Magento\Catalog\Model\Product::class, [
  797. 'getParentProductId',
  798. 'setStickWithinParent',
  799. '__wakeup'
  800. ]);
  801. $collectionMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote\Item\Collection::class);
  802. $itemMock->expects($this->any())
  803. ->method('representProduct')
  804. ->will($this->returnValue(false));
  805. $iterator = new \ArrayIterator([$itemMock]);
  806. $collectionMock->expects($this->any())
  807. ->method('getIterator')
  808. ->will($this->returnValue($iterator));
  809. $this->quoteItemCollectionFactoryMock->expects($this->once())
  810. ->method('create')
  811. ->will($this->returnValue($collectionMock));
  812. $this->productMock->expects($this->once())
  813. ->method('isSalable')
  814. ->willReturn(true);
  815. $this->itemProcessor
  816. ->expects($this->once())
  817. ->method('init')
  818. ->willReturn($itemMock);
  819. $itemMock->expects($this->once())
  820. ->method('setProduct');
  821. $itemMock->expects($this->once())
  822. ->method('setOptions');
  823. $itemMock->expects($this->any())
  824. ->method('setQuote')
  825. ->with($this->quote);
  826. $typeInstanceMock->expects($this->once())
  827. ->method('prepareForCartAdvanced')
  828. ->will($this->returnValue([$productMock]));
  829. $this->productMock->expects($this->once())
  830. ->method('getTypeInstance')
  831. ->will($this->returnValue($typeInstanceMock));
  832. $result = $this->quote->addProduct($this->productMock, null);
  833. $this->assertEquals($expectedResult, $result);
  834. }
  835. public function testValidateMinimumAmount()
  836. {
  837. $storeId = 1;
  838. $this->quote->setStoreId($storeId);
  839. $valueMap = [
  840. ['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
  841. ['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
  842. ['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
  843. ['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
  844. ['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
  845. ];
  846. $this->scopeConfig->expects($this->any())
  847. ->method('isSetFlag')
  848. ->will($this->returnValueMap($valueMap));
  849. $this->quoteAddressMock->expects($this->once())
  850. ->method('validateMinimumAmount')
  851. ->willReturn(true);
  852. $this->quoteAddressCollectionMock->expects($this->once())
  853. ->method('setQuoteFilter')
  854. ->willReturn([$this->quoteAddressMock]);
  855. $this->assertTrue($this->quote->validateMinimumAmount());
  856. }
  857. public function testValidateMinimumAmountNegative()
  858. {
  859. $storeId = 1;
  860. $this->quote->setStoreId($storeId);
  861. $valueMap = [
  862. ['sales/minimum_order/active', ScopeInterface::SCOPE_STORE, $storeId, true],
  863. ['sales/minimum_order/multi_address', ScopeInterface::SCOPE_STORE, $storeId, true],
  864. ['sales/minimum_order/amount', ScopeInterface::SCOPE_STORE, $storeId, 20],
  865. ['sales/minimum_order/include_discount_amount', ScopeInterface::SCOPE_STORE, $storeId, true],
  866. ['sales/minimum_order/tax_including', ScopeInterface::SCOPE_STORE, $storeId, true],
  867. ];
  868. $this->scopeConfig->expects($this->any())
  869. ->method('isSetFlag')
  870. ->will($this->returnValueMap($valueMap));
  871. $this->quoteAddressMock->expects($this->once())
  872. ->method('validateMinimumAmount')
  873. ->willReturn(false);
  874. $this->quoteAddressCollectionMock->expects($this->once())
  875. ->method('setQuoteFilter')
  876. ->willReturn([$this->quoteAddressMock]);
  877. $this->assertFalse($this->quote->validateMinimumAmount());
  878. }
  879. public function testGetPaymentIsNotDeleted()
  880. {
  881. $this->quote->setId(1);
  882. $payment = $this->createPartialMock(
  883. \Magento\Quote\Model\Quote\Payment::class,
  884. ['setQuote', 'isDeleted', '__wakeup']
  885. );
  886. $payment->expects($this->once())
  887. ->method('setQuote');
  888. $payment->expects($this->once())
  889. ->method('isDeleted')
  890. ->willReturn(false);
  891. $quotePaymentCollectionMock = $this->createPartialMock(
  892. \Magento\Quote\Model\ResourceModel\Quote\Payment\Collection::class,
  893. ['setQuoteFilter', 'getFirstItem']
  894. );
  895. $quotePaymentCollectionMock->expects($this->once())
  896. ->method('setQuoteFilter')
  897. ->with(1)
  898. ->will($this->returnSelf());
  899. $quotePaymentCollectionMock->expects($this->once())
  900. ->method('getFirstItem')
  901. ->willReturn($payment);
  902. $this->quotePaymentCollectionFactoryMock->expects($this->once())
  903. ->method('create')
  904. ->willReturn($quotePaymentCollectionMock);
  905. $this->assertInstanceOf(\Magento\Quote\Model\Quote\Payment::class, $this->quote->getPayment());
  906. }
  907. public function testGetPaymentIsDeleted()
  908. {
  909. $this->quote->setId(1);
  910. $payment = $this->createPartialMock(
  911. \Magento\Quote\Model\Quote\Payment::class,
  912. ['setQuote', 'isDeleted', 'getId', '__wakeup']
  913. );
  914. $payment->expects($this->exactly(2))
  915. ->method('setQuote');
  916. $payment->expects($this->once())
  917. ->method('isDeleted')
  918. ->willReturn(true);
  919. $payment->expects($this->once())
  920. ->method('getId')
  921. ->willReturn(1);
  922. $quotePaymentCollectionMock = $this->createPartialMock(
  923. \Magento\Quote\Model\ResourceModel\Quote\Payment\Collection::class,
  924. ['setQuoteFilter', 'getFirstItem']
  925. );
  926. $quotePaymentCollectionMock->expects($this->once())
  927. ->method('setQuoteFilter')
  928. ->with(1)
  929. ->will($this->returnSelf());
  930. $quotePaymentCollectionMock->expects($this->once())
  931. ->method('getFirstItem')
  932. ->willReturn($payment);
  933. $this->quotePaymentCollectionFactoryMock->expects($this->once())
  934. ->method('create')
  935. ->willReturn($quotePaymentCollectionMock);
  936. $this->paymentFactoryMock->expects($this->once())
  937. ->method('create')
  938. ->willReturn($payment);
  939. $this->assertInstanceOf(\Magento\Quote\Model\Quote\Payment::class, $this->quote->getPayment());
  940. }
  941. public function testAddItem()
  942. {
  943. $item = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, ['setQuote', 'getId']);
  944. $item->expects($this->once())
  945. ->method('setQuote');
  946. $item->expects($this->once())
  947. ->method('getId')
  948. ->willReturn(false);
  949. $itemsMock = $this->createPartialMock(
  950. \Magento\Eav\Model\Entity\Collection\AbstractCollection::class,
  951. ['setQuote', 'addItem']
  952. );
  953. $itemsMock->expects($this->once())
  954. ->method('setQuote');
  955. $itemsMock->expects($this->once())
  956. ->method('addItem')
  957. ->with($item);
  958. $this->quoteItemCollectionFactoryMock->expects($this->once())
  959. ->method('create')
  960. ->willReturn($itemsMock);
  961. $this->eventManagerMock->expects($this->once())
  962. ->method('dispatch');
  963. $this->quote->addItem($item);
  964. }
  965. /**
  966. * @param array $productTypes
  967. * @param int $expected
  968. * @dataProvider dataProviderForTestBeforeSaveIsVirtualQuote
  969. */
  970. public function testBeforeSaveIsVirtualQuote(array $productTypes, $expected)
  971. {
  972. $storeId = 1;
  973. $currencyMock = $this->getMockBuilder(\Magento\Directory\Model\Currency::class)
  974. ->disableOriginalConstructor()
  975. ->getMock();
  976. $currencyMock->expects($this->any())
  977. ->method('getCode')
  978. ->will($this->returnValue('test_code'));
  979. $currencyMock->expects($this->any())
  980. ->method('getRate')
  981. ->will($this->returnValue('test_rate'));
  982. $storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
  983. ->disableOriginalConstructor()
  984. ->getMock();
  985. $storeMock->expects($this->once())
  986. ->method('getBaseCurrency')
  987. ->will($this->returnValue($currencyMock));
  988. $storeMock->expects($this->once())
  989. ->method('getCurrentCurrency')
  990. ->will($this->returnValue($currencyMock));
  991. $this->storeManagerMock->expects($this->any())
  992. ->method('getStore')
  993. ->with($storeId)
  994. ->will($this->returnValue($storeMock));
  995. $this->quote->setStoreId($storeId);
  996. $collectionMock = $this->createMock(\Magento\Quote\Model\ResourceModel\Quote\Item\Collection::class);
  997. $items = [];
  998. foreach ($productTypes as $type) {
  999. $productMock = $this->createMock(\Magento\Catalog\Model\Product::class);
  1000. $productMock->expects($this->any())->method('getIsVirtual')->willReturn($type);
  1001. $itemMock = $this->createPartialMock(
  1002. \Magento\Quote\Model\Quote\Item::class,
  1003. ['isDeleted', 'getParentItemId', 'getProduct']
  1004. );
  1005. $itemMock->expects($this->any())
  1006. ->method('isDeleted')
  1007. ->willReturn(false);
  1008. $itemMock->expects($this->any())
  1009. ->method('getParentItemId')
  1010. ->willReturn(false);
  1011. $itemMock->expects($this->any())
  1012. ->method('getProduct')
  1013. ->willReturn($productMock);
  1014. $items[] = $itemMock;
  1015. }
  1016. $iterator = new \ArrayIterator($items);
  1017. $collectionMock->expects($this->any())
  1018. ->method('getIterator')
  1019. ->will($this->returnValue($iterator));
  1020. $this->quoteItemCollectionFactoryMock->expects($this->once())
  1021. ->method('create')
  1022. ->will($this->returnValue($collectionMock));
  1023. $this->quote->beforeSave();
  1024. $this->assertEquals($expected, $this->quote->getDataByKey(CartInterface::KEY_IS_VIRTUAL));
  1025. $this->assertNull($this->quote->getUpdatedAt());
  1026. }
  1027. /**
  1028. * @return array
  1029. */
  1030. public function dataProviderForTestBeforeSaveIsVirtualQuote()
  1031. {
  1032. return [
  1033. [[true], 1],
  1034. [[true, true], 1],
  1035. [[false], 0],
  1036. [[true, false], 0],
  1037. [[false, false], 0]
  1038. ];
  1039. }
  1040. public function testGetItemsCollection()
  1041. {
  1042. $itemCollectionMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote\Collection::class)
  1043. ->disableOriginalConstructor()
  1044. ->setMethods(['setQuote'])
  1045. ->getMock();
  1046. $this->quoteItemCollectionFactoryMock->expects($this->once())
  1047. ->method('create')
  1048. ->willReturn($itemCollectionMock);
  1049. $this->extensionAttributesJoinProcessorMock->expects($this->once())
  1050. ->method('process')
  1051. ->with(
  1052. $this->isInstanceOf(\Magento\Quote\Model\ResourceModel\Quote\Collection::class)
  1053. );
  1054. $itemCollectionMock->expects($this->once())->method('setQuote')->with($this->quote);
  1055. $this->quote->getItemsCollection();
  1056. }
  1057. public function testGetAllItems()
  1058. {
  1059. $itemOneMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote\Item::class)
  1060. ->setMethods(['isDeleted'])
  1061. ->disableOriginalConstructor()
  1062. ->getMock();
  1063. $itemOneMock->expects($this->once())
  1064. ->method('isDeleted')
  1065. ->willReturn(false);
  1066. $itemTwoMock = $this->getMockBuilder(\Magento\Quote\Model\ResourceModel\Quote\Item::class)
  1067. ->setMethods(['isDeleted'])
  1068. ->disableOriginalConstructor()
  1069. ->getMock();
  1070. $itemTwoMock->expects($this->once())
  1071. ->method('isDeleted')
  1072. ->willReturn(true);
  1073. $items = [$itemOneMock, $itemTwoMock];
  1074. $itemResult = [$itemOneMock];
  1075. $this->quote->setData('items_collection', $items);
  1076. $this->assertEquals($itemResult, $this->quote->getAllItems());
  1077. }
  1078. /**
  1079. * Test to verify if existing reserved_order_id in use.
  1080. *
  1081. * @param bool $isReservedOrderIdExist
  1082. * @param int $reservedOrderId
  1083. * @return void
  1084. * @dataProvider reservedOrderIdDataProvider
  1085. */
  1086. public function testReserveOrderId(bool $isReservedOrderIdExist, int $reservedOrderId): void
  1087. {
  1088. $this->orderIncrementIdChecker
  1089. ->expects($this->once())
  1090. ->method('isIncrementIdUsed')
  1091. ->with(1000001)->willReturn($isReservedOrderIdExist);
  1092. $this->resourceMock->expects($this->any())->method('getReservedOrderId')->willReturn($reservedOrderId);
  1093. $this->quote->reserveOrderId();
  1094. $this->assertEquals($reservedOrderId, $this->quote->getReservedOrderId());
  1095. }
  1096. /**
  1097. * @return array
  1098. */
  1099. public function reservedOrderIdDataProvider(): array
  1100. {
  1101. return [
  1102. 'id_already_in_use' => [true, 100002],
  1103. 'id_not_in_use' => [false, 1000001],
  1104. ];
  1105. }
  1106. }