/** * @param array $productTypes * @param int $expected * @dataProvider dataProviderForTestBeforeSaveIsVirtualQuote */ public function testBeforeSaveIsVirtualQuote(array $productTypes, $expected) { $storeId = 1; $currencyMock = $this->getMockBuilder('Magento\\Directory\\Model\\Currency')->disableOriginalConstructor()->getMock(); $currencyMock->expects($this->any())->method('getCode')->will($this->returnValue('test_code')); $currencyMock->expects($this->any())->method('getRate')->will($this->returnValue('test_rate')); $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock(); $storeMock->expects($this->once())->method('getBaseCurrency')->will($this->returnValue($currencyMock)); $storeMock->expects($this->once())->method('getCurrentCurrency')->will($this->returnValue($currencyMock)); $this->storeManagerMock->expects($this->any())->method('getStore')->with($storeId)->will($this->returnValue($storeMock)); $this->quote->setStoreId($storeId); $collectionMock = $this->getMock('Magento\\Quote\\Model\\Resource\\Quote\\Item\\Collection', [], [], '', false); $items = []; foreach ($productTypes as $type) { $productMock = $this->getMock('\\Magento\\Catalog\\Model\\Product', [], [], '', false); $productMock->expects($this->any())->method('getIsVirtual')->willReturn($type); $itemMock = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['isDeleted', 'getParentItemId', 'getProduct'], [], '', false); $itemMock->expects($this->any())->method('isDeleted')->willReturn(false); $itemMock->expects($this->any())->method('getParentItemId')->willReturn(false); $itemMock->expects($this->any())->method('getProduct')->willReturn($productMock); $items[] = $itemMock; } $iterator = new \ArrayIterator($items); $collectionMock->expects($this->any())->method('getIterator')->will($this->returnValue($iterator)); $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->will($this->returnValue($collectionMock)); $this->quote->beforeSave(); $this->assertEquals($expected, $this->quote->getDataByKey(CartInterface::KEY_IS_VIRTUAL)); }
public function testGetItemsCollection() { $itemCollectionMock = $this->getMockBuilder('Magento\\Quote\\Model\\Resource\\Quote\\Collection')->disableOriginalConstructor()->setMethods(['setQuote'])->getMock(); $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->willReturn($itemCollectionMock); $this->extensionAttributesJoinProcessorMock->expects($this->once())->method('process')->with($this->isInstanceOf('Magento\\Quote\\Model\\Resource\\Quote\\Collection')); $itemCollectionMock->expects($this->once())->method('setQuote')->with($this->quote); $this->quote->getItemsCollection(); }
public function testAddItem() { $item = $this->getMock('Magento\\Quote\\Model\\Quote\\Item', ['setQuote', 'getId'], [], '', false); $item->expects($this->once())->method('setQuote'); $item->expects($this->once())->method('getId')->willReturn(false); $itemsMock = $this->getMock('Magento\\Eav\\Model\\Entity\\Collection\\AbstractCollection', ['setQuote', 'addItem'], [], '', false); $itemsMock->expects($this->once())->method('setQuote'); $itemsMock->expects($this->once())->method('addItem')->with($item); $this->quoteItemCollectionFactoryMock->expects($this->once())->method('create')->willReturn($itemsMock); $this->eventManagerMock->expects($this->once())->method('dispatch'); $this->quote->addItem($item); }