public function testGetItems() { $optionId = 1; $optionData = ['title' => 'test title']; $productSku = 'product_sku'; $productMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductInterface'); $productMock->expects($this->once())->method('getSku')->willReturn($productSku); $optionMock = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getOptionId', 'getData', 'getTitle', 'getDefaultTitle'], [], '', false); $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $optionsCollMock = $objectManager->getCollectionMock('Magento\\Bundle\\Model\\Resource\\Option\\Collection', [$optionMock]); $this->typeMock->expects($this->once())->method('getOptionsCollection')->with($productMock)->willReturn($optionsCollMock); $optionMock->expects($this->exactly(2))->method('getOptionId')->willReturn($optionId); $optionMock->expects($this->once())->method('getData')->willReturn($optionData); $optionMock->expects($this->once())->method('getTitle')->willReturn(null); $optionMock->expects($this->once())->method('getDefaultTitle')->willReturn($optionData['title']); $linkMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\LinkInterface'); $this->linkListMock->expects($this->once())->method('getItems')->with($productMock, $optionId)->willReturn([$linkMock]); $this->optionBuilderMock->expects($this->once())->method('populateWithArray')->with($optionData)->willReturnSelf(); $this->optionBuilderMock->expects($this->once())->method('setOptionId')->with($optionId)->willReturnSelf(); $this->optionBuilderMock->expects($this->once())->method('setTitle')->with($optionData['title'])->willReturnSelf(); $this->optionBuilderMock->expects($this->once())->method('setSku')->with($productSku)->willReturnSelf(); $this->optionBuilderMock->expects($this->once())->method('setProductLinks')->with([$linkMock])->willReturnSelf(); $newOptionMock = $this->getMock('\\Magento\\Bundle\\Api\\Data\\OptionInterface'); $this->optionBuilderMock->expects($this->once())->method('create')->willReturn($newOptionMock); $this->assertEquals([$newOptionMock], $this->model->getItems($productMock)); }
protected function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->observerMock = $this->getMock('Magento\\Framework\\Event\\Observer', [], [], '', false); $this->eventMock = $this->getMock('Magento\\Framework\\Event', ['getCollection', '__wakeup'], [], '', false); $this->productMock = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product', ['getIsRecurring', 'getRecurringPayment', 'setRecurringPayment', '__wakeup', '__sleep'], [], '', false); $this->collectionMock = $objectManager->getCollectionMock('Magento\\Catalog\\Model\\Resource\\Product\\Collection', [$this->productMock]); $this->model = new UnserializeProductRecurringPayment(); }
protected function setUp() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); $this->quoteRepositoryMock = $this->getMock('\\Magento\\Sales\\Model\\QuoteRepository', [], [], '', false); $methods = ['getId', 'getStoreId', 'getCreatedAt', 'getUpdatedAt', 'getConvertedAt', 'getIsActive', 'getIsVirtual', 'getItemsCount', 'getItemsQty', 'getCheckoutMethod', 'getReservedOrderId', 'getOrigOrderId', 'getBaseGrandTotal', 'getBaseSubtotal', 'getSubtotal', 'getBaseSubtotalWithDiscount', 'getSubtotalWithDiscount', 'getCustomerId', 'getCustomerEmail', 'getCustomerGroupId', 'getCustomerTaxClassId', 'getCustomerPrefix', 'getCustomerFirstname', 'getCustomerMiddlename', 'getCustomerLastname', 'getCustomerSuffix', 'getCustomerDob', 'getCustomerNote', 'getCustomerNoteNotify', 'getCustomerIsGuest', 'getCustomerGender', 'getCustomerTaxvat', '__wakeup', 'load', 'getGrandTotal', 'getGlobalCurrencyCode', 'getBaseCurrencyCode', 'getStoreCurrencyCode', 'getQuoteCurrencyCode', 'getStoreToBaseRate', 'getStoreToQuoteRate', 'getBaseToGlobalRate', 'getBaseToQuoteRate', 'setStoreId', 'getShippingAddress', 'getAllItems']; $this->quoteMock = $this->getMock('\\Magento\\Sales\\Model\\Quote', $methods, [], '', false); $this->quoteCollectionMock = $objectManager->getCollectionMock('\\Magento\\Sales\\Model\\Resource\\Quote\\Collection', [$this->quoteMock]); $this->searchResultsBuilderMock = $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\CartSearchResultsBuilder', [], [], '', false); $this->cartMapperMock = $this->getMock('\\Magento\\Checkout\\Service\\V1\\Data\\CartMapper', ['map'], [], '', false); $this->service = new ReadService($this->quoteRepositoryMock, $this->quoteCollectionMock, $this->searchResultsBuilderMock, $this->cartMapperMock); }
public function testBuild() { $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $expectedData = array('100500' => array('some' => 'data')); $attributes = array('attributeOne' => array('code' => 'one'), 'attributeTwo' => array('code' => 'two')); $this->_linkMock->expects($this->once())->method('useRelatedLinks'); $this->_linkMock->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes)); $productLinkMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link', array('__wakeup', 'getLinkedProductId', 'toArray'), array(), '', false); $productLinkMock->expects($this->once())->method('getLinkedProductId')->will($this->returnValue('100500')); $productLinkMock->expects($this->once())->method('toArray')->with(array('one', 'two'))->will($this->returnValue(array('some' => 'data'))); $collectionMock = $helper->getCollectionMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link\\Collection', array($productLinkMock)); $this->_productMock->expects($this->once())->method('getRelatedLinkCollection')->will($this->returnValue($collectionMock)); $this->_duplicateMock->expects($this->once())->method('setRelatedLinkData')->with($expectedData); $this->_model->build($this->_productMock, $this->_duplicateMock); }
public function testCollect() { $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this); /** @var \Magento\Sales\Model\Order\Invoice\Total\Tax $model */ $model = $objectManager->getObject('Magento\\Sales\\Model\\Order\\Invoice\\Total\\Tax'); $collection = $objectManager->getCollectionMock('Magento\\Sales\\Model\\Resource\\Order\\Invoice\\Collection', array()); $order = $this->getMock('\\Magento\\Sales\\Model\\Order', array('getInvoiceCollection', 'getHiddenTaxAmount', 'getBaseHiddenTaxAmount', '__wakeup'), array(), '', false); $order->expects($this->atLeastOnce())->method('getInvoiceCollection')->will($this->returnValue($collection)); $order->expects($this->atLeastOnce())->method('getHiddenTaxAmount')->will($this->returnValue(10)); $order->expects($this->atLeastOnce())->method('getBaseHiddenTaxAmount')->will($this->returnValue(10)); $invoiceItems[] = $this->getInvoiceItem(0, 10); $invoice = $this->getMock('\\Magento\\Sales\\Model\\Order\\Invoice', array('getAllItems', 'getOrder', 'getGrandTotal', 'setGrandTotal', '__wakeup'), array(), '', false); $invoice->expects($this->atLeastOnce())->method('getAllItems')->will($this->returnValue($invoiceItems)); $invoice->expects($this->atLeastOnce())->method('getOrder')->will($this->returnValue($order)); $invoice->expects($this->atLeastOnce())->method('getGrandTotal')->will($this->returnValue(0)); $invoice->expects($this->atLeastOnce())->method('setGrandTotal')->with($this->equalTo(10))->will($this->returnSelf()); $model->collect($invoice); }
public function testBuild() { $helper = new \Magento\TestFramework\Helper\ObjectManager($this); $expectedData = array('100500' => array('some' => 'data')); $this->_productMock->expects($this->once())->method('getTypeId')->will($this->returnValue(\Magento\GroupedProduct\Model\Product\Type\Grouped::TYPE_CODE)); $attributes = array('attributeOne' => array('code' => 'one'), 'attributeTwo' => array('code' => 'two')); $this->_linkMock->expects($this->once())->method('getAttributes')->will($this->returnValue($attributes)); $productLinkMock = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link', array('__wakeup', 'getLinkedProductId', 'toArray'), array(), '', false); $this->_linkMock->expects($this->atLeastOnce())->method('setLinkTypeId')->with(\Magento\GroupedProduct\Model\Resource\Product\Link::LINK_TYPE_GROUPED); $productLinkMock->expects($this->once())->method('getLinkedProductId')->will($this->returnValue('100500')); $productLinkMock->expects($this->once())->method('toArray')->with(array('one', 'two'))->will($this->returnValue(array('some' => 'data'))); $collectionMock = $helper->getCollectionMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Link\\Collection', array($productLinkMock)); $collectionMock->expects($this->once())->method('setProduct')->with($this->_productMock); $collectionMock->expects($this->once())->method('addLinkTypeIdFilter'); $collectionMock->expects($this->once())->method('addProductIdFilter'); $collectionMock->expects($this->once())->method('joinAttributes'); $this->_linkMock->expects($this->once())->method('getLinkCollection')->will($this->returnValue($collectionMock)); $this->_duplicateMock->expects($this->once())->method('setGroupedLinkData')->with($expectedData); $this->_model->build($this->_productMock, $this->_duplicateMock); }