/**
  * Set up
  */
 protected function setUp()
 {
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->rowCustomizerMock = $this->objectManagerHelper->getObject('\\Magento\\BundleImportExport\\Model\\Export\\RowCustomizer');
     $this->productResourceCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addAttributeToFilter', 'getIterator'], [], '', false);
     $this->product = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getId', 'getPriceType', 'getSkuType', 'getPriceView', 'getWeightType', 'getTypeInstance', 'getOptionsCollection', 'getSelectionsCollection'], [], '', false);
     $this->product->expects($this->any())->method('getId')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceType')->willReturn(1);
     $this->product->expects($this->any())->method('getSkuType')->willReturn(1);
     $this->product->expects($this->any())->method('getPriceView')->willReturn(1);
     $this->product->expects($this->any())->method('getWeightType')->willReturn(1);
     $this->product->expects($this->any())->method('getTypeInstance')->willReturnSelf();
     $this->optionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Option\\Collection', ['setOrder', 'getIterator'], [], '', false);
     $this->product->expects($this->any())->method('getOptionsCollection')->willReturn($this->optionsCollection);
     $this->optionsCollection->expects($this->any())->method('setOrder')->willReturnSelf();
     $this->option = $this->getMock('\\Magento\\Bundle\\Model\\Option', ['getId', 'getTitle', 'getType', 'getRequired'], [], '', false);
     $this->option->expects($this->any())->method('getId')->willReturn(1);
     $this->option->expects($this->any())->method('getTitle')->willReturn('title');
     $this->option->expects($this->any())->method('getType')->willReturn(1);
     $this->option->expects($this->any())->method('getRequired')->willReturn(1);
     $this->optionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->option])));
     $this->selection = $this->getMock('\\Magento\\Catalog\\Model\\Product', ['getSku', 'getSelectionPriceValue', 'getIsDefault', 'getSelectionQty', 'getSelectionPriceType'], [], '', false);
     $this->selection->expects($this->any())->method('getSku')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceValue')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionQty')->willReturn(1);
     $this->selection->expects($this->any())->method('getSelectionPriceType')->willReturn(1);
     $this->selectionsCollection = $this->getMock('\\Magento\\Bundle\\Model\\ResourceModel\\Selection\\Collection', ['getIterator', 'addAttributeToSort'], [], '', false);
     $this->selectionsCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->selection])));
     $this->selectionsCollection->expects($this->any())->method('addAttributeToSort')->willReturnSelf();
     $this->product->expects($this->any())->method('getSelectionsCollection')->willReturn($this->selectionsCollection);
     $this->productResourceCollection->expects($this->any())->method('addAttributeToFilter')->willReturnSelf();
     $this->productResourceCollection->expects($this->any())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$this->product])));
 }
 public function testGetCollection()
 {
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter');
     $this->productLinkRepositoryMock->expects($this->once())->method('getList')->willReturn([]);
     $this->requestMock->expects($this->exactly(2))->method('getParam')->willReturn(1);
     $this->assertInstanceOf(Collection::class, $this->getModel()->getCollection());
 }
 public function testGetData()
 {
     $items = ['testProduct1', 'testProduct2'];
     $expectedData = ['totalRecords' => count($items), 'items' => $items];
     $this->configMock->expects($this->once())->method('getComposableTypes')->willReturn([self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('isLoaded')->willReturn(false);
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter')->with('type_id', [self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('toArray')->willReturn($items);
     $this->collectionMock->expects($this->once())->method('getSize')->willReturn(count($items));
     $this->assertEquals($expectedData, $this->getModel()->getData());
 }
 public function testFindAttributeIdsByProductIds()
 {
     $productIds = [1, 2, 3];
     $attributeSetIds = [3, 4, 6];
     $select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();
     $select->expects($this->once())->method('reset')->with(Select::COLUMNS)->willReturnSelf();
     $select->expects($this->once())->method('columns')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $select->expects($this->once())->method('where')->with('entity_id IN (?)', $productIds)->willReturnSelf();
     $select->expects($this->once())->method('group')->with(ProductInterface::ATTRIBUTE_SET_ID)->willReturnSelf();
     $connection = $this->getMock(AdapterInterface::class);
     $connection->expects($this->once())->method('fetchCol')->with($select)->willReturn($attributeSetIds);
     $this->productCollection->expects($this->once())->method('getSelect')->willReturn($select);
     $this->productCollection->expects($this->once())->method('getConnection')->willReturn($connection);
     $this->assertEquals($attributeSetIds, $this->attributeSetFinder->findAttributeSetIdsByProductIds($productIds));
 }
 protected function _initConfigurableData()
 {
     $productIds = [1, 2, 3];
     $productAttributesOptions = [[['pricing_is_percent' => true, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 112345, 'super_attribute_label' => 'Super attribute label'], ['pricing_is_percent' => false, 'sku' => '_sku_', 'attribute_code' => 'code_of_attribute', 'option_title' => 'Option Title', 'pricing_value' => 212345, 'super_attribute_label' => ''], ['pricing_is_percent' => false, 'sku' => '_sku_2', 'attribute_code' => 'code_of_attribute_2', 'option_title' => 'Option Title 2', 'pricing_value' => 312345, 'super_attribute_label' => 'Super attribute label 2']]];
     $expectedConfigurableData = $this->getExpectedConfigurableData();
     $productMock = $this->getMock('Magento\\Catalog\\Model\\Product', ['getId', 'getTypeInstance', '__wakeup'], [], '', false);
     $productMock->expects($this->any())->method('getId')->will($this->returnValue($this->initiatedProductId));
     $typeInstanceMock = $this->getMock('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable', [], [], '', false);
     $typeInstanceMock->expects($this->any())->method('getConfigurableOptions')->will($this->returnValue($productAttributesOptions));
     $productMock->expects($this->any())->method('getTypeInstance')->will($this->returnValue($typeInstanceMock));
     $this->_collectionMock->expects($this->at(0))->method('addAttributeToFilter')->with('entity_id', ['in' => $productIds])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(1))->method('addAttributeToFilter')->with('type_id', ['eq' => \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE])->will($this->returnSelf());
     $this->_collectionMock->expects($this->at(2))->method('fetchItem')->will($this->returnValue($productMock));
     $this->_collectionMock->expects($this->at(3))->method('fetchItem')->will($this->returnValue(false));
     $this->_model->prepareData($this->_collectionMock, $productIds);
     $configurableData = $this->getPropertyValue($this->_model, 'configurableData');
     $this->assertEquals($expectedConfigurableData, $configurableData);
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     parent::setUp();
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\ResourceModel\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\DataObject(['id' => 1, 'attribute_set_name' => 'Default', '_attribute_set' => 'Default']);
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([$item]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Attribute\\Collection', ['setAttributeSetFilter'], [], '', false);
     $superAttributes = [];
     foreach ($this->_getSuperAttributes() as $superAttribute) {
         $item = $this->getMock('\\Magento\\Eav\\Model\\Entity\\Attribute\\AbstractAttribute', ['isStatic'], $superAttribute, '', false);
         $item->setData($superAttribute);
         $item->method('isStatic')->will($this->returnValue(false));
         $superAttributes[] = $item;
     }
     $this->attrCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->attrCollection));
     $this->attrCollection->expects($this->any())->method('setAttributeSetFilter')->will($this->returnValue($superAttributes));
     $this->_entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getOldSku', 'getNextBunch', 'isRowAllowedToImport', 'getConnection', 'getAttrSetIdToName', 'getErrorAggregator', 'getAttributeOptions'], [], '', false);
     $this->_entityModel->method('getErrorAggregator')->willReturn($this->getErrorAggregatorObject());
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->_connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto'], [], '', false);
     $this->select = $this->getMock('Magento\\Framework\\DB\\Select', ['from', 'where', 'joinLeft', 'getConnection'], [], '', false);
     $this->select->expects($this->any())->method('from')->will($this->returnSelf());
     $this->select->expects($this->any())->method('where')->will($this->returnSelf());
     $this->select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $this->_connection->expects($this->any())->method('select')->will($this->returnValue($this->select));
     $connectionMock = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $connectionMock->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getConnection')->willReturn($connectionMock);
     $this->_connection->expects($this->any())->method('insertOnDuplicate')->willReturnSelf();
     $this->_connection->expects($this->any())->method('delete')->willReturnSelf();
     $this->_connection->expects($this->any())->method('quoteInto')->willReturn('');
     $this->_connection->expects($this->any())->method('fetchAll')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\ResourceConnection', ['getConnection', 'getTableName'], [], '', false);
     $this->resource->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->resource->expects($this->any())->method('getTableName')->will($this->returnValue('tableName'));
     $this->_entityModel->expects($this->any())->method('getConnection')->will($this->returnValue($this->_connection));
     $this->productCollectionFactory = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\ResourceModel\\Product\\Collection', ['addFieldToFilter', 'addAttributeToSelect'], [], '', false);
     $products = [];
     $testProducts = [['id' => 1, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 2, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1], ['id' => 20, 'attribute_set_id' => 4, 'testattr2' => 1, 'testattr3' => 1]];
     foreach ($testProducts as $product) {
         $item = $this->getMock('\\Magento\\Framework\\DataObject', ['getAttributeSetId'], [], '', false);
         $item->setData($product);
         $item->expects($this->any())->method('getAttributeSetId')->willReturn(4);
         $products[] = $item;
     }
     $this->productCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addFieldToFilter')->will($this->returnValue($this->productCollection));
     $this->productCollection->expects($this->any())->method('addAttributeToSelect')->will($this->returnValue($products));
     $this->_entityModel->expects($this->any())->method('getAttributeOptions')->will($this->returnValue(['attr2val1' => '1', 'attr2val2' => '2', 'attr2val3' => '3', 'testattr3v1' => '4', 'testattr30v1' => '4', 'testattr3v2' => '5', 'testattr3v3' => '6']));
     $this->configurable = $this->objectManagerHelper->getObject('Magento\\ConfigurableImportExport\\Model\\Import\\Product\\Type\\Configurable', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'resource' => $this->resource, 'productColFac' => $this->productCollectionFactory]);
 }
 public function testGetData()
 {
     $items = ['testProduct1', 'testProduct2'];
     $expectedData = ['totalRecords' => count($items), 'items' => $items];
     $this->dataHelperMock->expects($this->once())->method('getAllowedSelectionTypes')->willReturn([self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('isLoaded')->willReturn(false);
     $this->collectionMock->expects($this->once())->method('addAttributeToFilter')->with('type_id', [self::ALLOWED_TYPE]);
     $this->collectionMock->expects($this->once())->method('addFilterByRequiredOptions');
     $this->collectionMock->expects($this->once())->method('addStoreFilter')->with(\Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $this->collectionMock->expects($this->once())->method('toArray')->willReturn($items);
     $this->collectionMock->expects($this->once())->method('getSize')->willReturn(count($items));
     $this->assertEquals($expectedData, $this->getModel()->getData());
 }
Example #8
0
 public function testGetMaxPrice()
 {
     $maxPrice = 8000;
     $this->productCollection->expects($this->once())->method('getMaxPrice')->will($this->returnValue($maxPrice));
     $this->assertSame(floatval($maxPrice), $this->target->getMaxPrice());
 }
Example #9
0
 /**
  * Test protected `_getProductCollection` and `getPageSize` methods via public `toHtml` method,
  * for display_type == DISPLAY_TYPE_ALL_PRODUCTS.
  *
  * @param bool $pagerEnable
  * @param int $productsCount
  * @param int $productsPerPage
  * @param int $expectedPageSize
  * @dataProvider getProductCollectionDataProvider
  */
 public function testGetProductAllCollection($pagerEnable, $productsCount, $productsPerPage, $expectedPageSize)
 {
     $this->generalGetProductCollection();
     $this->productCollection->expects($this->atLeastOnce())->method('setPageSize')->with($expectedPageSize)->willReturnSelf();
     $this->startTestGetProductCollection(NewWidget::DISPLAY_TYPE_ALL_PRODUCTS, $pagerEnable, $productsCount, $productsPerPage);
 }