Example #1
0
 protected function setUp()
 {
     $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getBehavior', 'getNewSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope', 'getConnection'], [], '', false);
     $this->connection = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', ['select', 'fetchAll', 'fetchPairs', 'joinLeft', 'insertOnDuplicate', 'delete', 'quoteInto', 'fetchAssoc'], [], '', false);
     $select = $this->getMock('Magento\\Framework\\DB\\Select', [], [], '', false);
     $select->expects($this->any())->method('from')->will($this->returnSelf());
     $select->expects($this->any())->method('where')->will($this->returnSelf());
     $select->expects($this->any())->method('joinLeft')->will($this->returnSelf());
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $this->connection->expects($this->any())->method('select')->will($this->returnValue($select));
     $this->connection->expects($this->any())->method('fetchPairs')->will($this->returnValue(['1' => '1', '2' => '2']));
     $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->resource = $this->getMock('Magento\\Framework\\App\\Resource', ['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->attrSetColFac = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->attrSetColFac->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
     $this->prodAttrColFac = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\Collection', [], [], '', false);
     $attrCollection->expects($this->any())->method('addFieldToFilter')->willReturn([]);
     $this->prodAttrColFac->expects($this->any())->method('create')->will($this->returnValue($attrCollection));
     $this->params = [0 => $this->entityModel, 1 => 'bundle'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->bundle = $this->objectManagerHelper->getObject('Magento\\BundleImportExport\\Model\\Import\\Product\\Type\\Bundle', ['attrSetColFac' => $this->attrSetColFac, 'prodAttrColFac' => $this->prodAttrColFac, 'resource' => $this->resource, 'params' => $this->params]);
 }
Example #2
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $item = new \Magento\Framework\Object(['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\\Resource\\Product\\Attribute\\CollectionFactory', ['create'], [], '', false);
     $this->attrCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\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', 'getAttributeOptions'], [], '', false);
     $this->params = [0 => $this->_entityModel, 1 => 'configurable'];
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $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', 'getAdapter'], [], '', 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));
     $adapter = $this->getMock('Magento\\Framework\\DB\\Adapter\\Pdo\\Mysql', [], [], '', false);
     $adapter->expects($this->any())->method('quoteInto')->will($this->returnValue('query'));
     $this->select->expects($this->any())->method('getAdapter')->willReturn($adapter);
     $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('fetchPairs')->will($this->returnValue([]));
     $this->resource = $this->getMock('\\Magento\\Framework\\App\\Resource', ['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\\Resource\\Product\\CollectionFactory', ['create'], [], '', false);
     $this->productCollection = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\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\\Object', ['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]);
 }
Example #3
0
 protected function setUp()
 {
     $this->setCollectionFactory = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', ['create'], [], '', false);
     $this->setCollection = $this->getMock('Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', ['setEntityTypeFilter'], [], '', false);
     $this->setCollectionFactory->expects($this->any())->method('create')->will($this->returnValue($this->setCollection));
     $this->setCollection->expects($this->any())->method('setEntityTypeFilter')->will($this->returnValue([]));
     $this->attrCollectionFactory = $this->getMock('Magento\\Catalog\\Model\\Resource\\Product\\Attribute\\CollectionFactory', [], [], '', false);
     $this->entityModel = $this->getMock('Magento\\CatalogImportExport\\Model\\Import\\Product', ['getNewSku', 'getNextBunch', 'isRowAllowedToImport', 'getRowScope'], [], '', false);
     $this->params = [0 => $this->entityModel, 1 => 'grouped'];
     $this->links = $this->getMock('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped\\Links', [], [], '', false);
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->grouped = $this->objectManagerHelper->getObject('Magento\\GroupedImportExport\\Model\\Import\\Product\\Type\\Grouped', ['attrSetColFac' => $this->setCollectionFactory, 'prodAttrColFac' => $this->attrCollectionFactory, 'params' => $this->params, 'links' => $this->links]);
 }
Example #4
0
 /**
  * @return void
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->_eavConfig = $this->getMock('Magento\\Eav\\Model\\Config', array('getEntityType', 'getEntityTypeId'), array(), '', false);
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityType')->with($this->equalTo('catalog_product'))->will($this->returnSelf());
     $this->_eavConfig->expects($this->atLeastOnce())->method('getEntityTypeId')->will($this->returnValue('1'));
     $this->_optionModel = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Option', array(), array(), '', false);
     $this->_optionFactory = $this->getMock('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\OptionFactory', array('create'), array(), '', false);
     $this->_optionFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_optionModel));
     $this->_storeManager = $this->getMock('\\Magento\\Store\\Model\\StoreManager', array('getWebsites', 'getStores'), array(), '', false);
     $this->_storeManager->expects($this->atLeastOnce())->method('getWebsites')->will($this->returnValue(array()));
     $this->_storeManager->expects($this->atLeastOnce())->method('getStores')->will($this->returnValue(array()));
     $this->_setCol = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\Collection', array('setEntityTypeFilter'), array(), '', false);
     $this->_setCol->expects($this->atLeastOnce())->method('setEntityTypeFilter')->with($this->equalTo('1'))->will($this->returnValue(array()));
     $this->_setColFactory = $this->getMock('\\Magento\\Eav\\Model\\Resource\\Entity\\Attribute\\Set\\CollectionFactory', array('create'), array(), '', false);
     $this->_setColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_setCol));
     $this->_importConfig = $this->getMock('\\Magento\\ImportExport\\Model\\Import\\Config', array('getEntityTypes'), array(), '', false);
     $this->_importConfig->expects($this->atLeastOnce())->method('getEntityTypes')->with('catalog_product')->will($this->returnValue(array()));
     $this->_categoryCol = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\Collection', array('addNameToResult'), array(), '', false);
     $this->_categoryCol->expects($this->atLeastOnce())->method('addNameToResult')->will($this->returnValue(array()));
     $this->_categoryColFactory = $this->getMock('\\Magento\\Catalog\\Model\\Resource\\Category\\CollectionFactory', array('create'), array(), '', false);
     $this->_categoryColFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_categoryCol));
     $this->_product = $this->getMock('\\Magento\\Catalog\\Model\\Product', array('getProductEntitiesInfo', '__wakeup'), array(), '', false);
     $this->_product->expects($this->atLeastOnce())->method('getProductEntitiesInfo')->with($this->equalTo(array('entity_id', 'type_id', 'attribute_set_id', 'sku')))->will($this->returnValue(array()));
     $this->_productFactory = $this->getMock('\\Magento\\Catalog\\Model\\ProductFactory', array('create'), array(), '', false);
     $this->_productFactory->expects($this->atLeastOnce())->method('create')->will($this->returnValue($this->_product));
     $this->_customerGroupService = $this->getMock('Magento\\Customer\\Service\\V1\\CustomerGroupService', array('getGroups'), array(), '', false);
     $this->_customerGroupService->expects($this->atLeastOnce())->method('getGroups')->will($this->returnValue(array()));
     $objectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
     $this->_model = $objectManager->getObject('\\Magento\\CatalogImportExport\\Model\\Import\\Product', array('config' => $this->_eavConfig, 'optionFactory' => $this->_optionFactory, 'storeManager' => $this->_storeManager, 'setColFactory' => $this->_setColFactory, 'importConfig' => $this->_importConfig, 'categoryColFactory' => $this->_categoryColFactory, 'productFactory' => $this->_productFactory, 'customerGroupService' => $this->_customerGroupService));
 }
 /**
  * Prepares values options to be used as select options or hashed array
  * Result is stored in following keys:
  *  'value_select_options' - normal select array: array(array('value' => $value, 'label' => $label), ...)
  *  'value_option' - hashed array: array($value => $label, ...),
  *
  * @return $this
  */
 protected function _prepareValueOptions()
 {
     // Check that both keys exist. Maybe somehow only one was set not in this routine, but externally.
     $selectReady = $this->getData('value_select_options');
     $hashedReady = $this->getData('value_option');
     if ($selectReady && $hashedReady) {
         return $this;
     }
     // Get array of select options. It will be used as source for hashed options
     $selectOptions = null;
     if ($this->getAttribute() === 'attribute_set_id') {
         $entityTypeId = $this->_config->getEntityType(\Magento\Catalog\Model\Product::ENTITY)->getId();
         $selectOptions = $this->_attrSetCollection->setEntityTypeFilter($entityTypeId)->load()->toOptionArray();
     } elseif ($this->getAttribute() === 'type_id') {
         foreach ($selectReady as $value => $label) {
             if (is_array($label) && isset($label['value'])) {
                 $selectOptions[] = $label;
             } else {
                 $selectOptions[] = array('value' => $value, 'label' => $label);
             }
         }
         $selectReady = null;
     } elseif (is_object($this->getAttributeObject())) {
         $attributeObject = $this->getAttributeObject();
         if ($attributeObject->usesSource()) {
             if ($attributeObject->getFrontendInput() == 'multiselect') {
                 $addEmptyOption = false;
             } else {
                 $addEmptyOption = true;
             }
             $selectOptions = $attributeObject->getSource()->getAllOptions($addEmptyOption);
         }
     }
     // Set new values only if we really got them
     if ($selectOptions !== null) {
         // Overwrite only not already existing values
         if (!$selectReady) {
             $this->setData('value_select_options', $selectOptions);
         }
         if (!$hashedReady) {
             $hashedOptions = array();
             foreach ($selectOptions as $option) {
                 if (is_array($option['value'])) {
                     continue;
                     // We cannot use array as index
                 }
                 $hashedOptions[$option['value']] = $option['label'];
             }
             $this->setData('value_option', $hashedOptions);
         }
     }
     return $this;
 }
Example #6
0
 /**
  * Initialize attribute sets code-to-id pairs.
  *
  * @return $this
  */
 protected function _initAttributeSets()
 {
     $productTypeId = $this->_productFactory->create()->getTypeId();
     foreach ($this->_attrSetColFactory->create()->setEntityTypeFilter($productTypeId) as $attributeSet) {
         $this->_attrSetIdToName[$attributeSet->getId()] = $attributeSet->getAttributeSetName();
     }
     return $this;
 }
Example #7
0
 /**
  *  Add filter by entity type id to collection
  *
  * @return \Magento\Framework\Model\Resource\Db\Collection\AbstractCollection|$this
  */
 protected function _initSelect()
 {
     parent::_initSelect();
     $this->setEntityTypeFilter($this->_registryManager->registry('entityType'));
     return $this;
 }