示例#1
0
 /**
  * @param array $configData
  * @param string $entity
  * @param string[] $expectedResult
  * @dataProvider getEntityTypesDataProvider
  */
 public function testGetEntityTypes($configData, $entity, $expectedResult)
 {
     $this->_configScopeMock->expects($this->any())->method('load')->with($this->_cacheId)->will($this->returnValue(false));
     $this->_readerMock->expects($this->any())->method('read')->will($this->returnValue($configData));
     $this->_model = new \Magento\ImportExport\Model\Import\Config($this->_readerMock, $this->_configScopeMock, $this->_cacheId);
     $this->assertEquals($expectedResult, $this->_model->getEntityTypes($entity));
 }
 /**
  * Test getEntityBehaviors with not existing behavior class
  *
  * @expectedException \Magento\Framework\Exception\LocalizedException
  * @expectedExceptionMessage The behavior token for customer is invalid.
  */
 public function testGetEntityBehaviorsWithUnknownBehavior()
 {
     $this->_importConfig->merge(['entities' => ['customer' => ['behaviorModel' => 'Unknown_Behavior_Class']]]);
     $importModel = $this->_model;
     $actualBehaviors = $importModel->getEntityBehaviors();
     $this->assertArrayNotHasKey('customer', $actualBehaviors);
 }
示例#3
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));
 }
示例#4
0
 /**
  * @return $this
  */
 protected function _initTypeModels()
 {
     $entityTypes = ['simple' => ['model' => 'simple_product', 'params' => []]];
     $productTypeInstance = $this->getMockBuilder('\\Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType')->disableOriginalConstructor()->getMock();
     $productTypeInstance->expects($this->once())->method('isSuitable')->willReturn(true);
     $productTypeInstance->expects($this->once())->method('getParticularAttributes')->willReturn([]);
     $productTypeInstance->expects($this->once())->method('getCustomFieldsMapping')->willReturn([]);
     $this->_importConfig->expects($this->once())->method('getEntityTypes')->with(self::ENTITY_TYPE_CODE)->willReturn($entityTypes);
     $this->_productTypeFactory->expects($this->once())->method('create')->willReturn($productTypeInstance);
     return $this;
 }
示例#5
0
 /**
  * Initialize product type models.
  *
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _initTypeModels()
 {
     $productTypes = $this->_importConfig->getEntityTypes($this->getEntityTypeCode());
     foreach ($productTypes as $productTypeName => $productTypeConfig) {
         $params = [$this, $productTypeName];
         if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], ['params' => $params]))) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Entity type model \'%1\' is not found', $productTypeConfig['model']));
         }
         if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
             throw new \Magento\Framework\Exception\LocalizedException(__('Entity type model must be an instance of ' . 'Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType'));
         }
         if ($model->isSuitable()) {
             $this->_productTypeModels[$productTypeName] = $model;
         }
         $this->_fieldsMap = array_merge($this->_fieldsMap, $model->getCustomFieldsMapping());
         $this->_specialAttributes = array_merge($this->_specialAttributes, $model->getParticularAttributes());
     }
     $this->_initErrorTemplates();
     // remove doubles
     $this->_specialAttributes = array_unique($this->_specialAttributes);
     return $this;
 }
示例#6
0
 /**
  * Initialize product type models.
  *
  * @return $this
  * @throws \Magento\Framework\Model\Exception
  */
 protected function _initTypeModels()
 {
     $productTypes = $this->_importConfig->getEntityTypes($this->getEntityTypeCode());
     foreach ($productTypes as $productTypeName => $productTypeConfig) {
         $params = array($this, $productTypeName);
         if (!($model = $this->_productTypeFactory->create($productTypeConfig['model'], array('params' => $params)))) {
             throw new \Magento\Framework\Model\Exception(sprintf("Entity type model '%s' is not found", $productTypeConfig['model']));
         }
         if (!$model instanceof \Magento\CatalogImportExport\Model\Import\Product\Type\AbstractType) {
             throw new \Magento\Framework\Model\Exception(__('Entity type model must be an instance of ' . 'Magento\\CatalogImportExport\\Model\\Import\\Product\\Type\\AbstractType'));
         }
         if ($model->isSuitable()) {
             $this->_productTypeModels[$productTypeName] = $model;
         }
         $this->_specialAttributes = array_merge($this->_specialAttributes, $model->getParticularAttributes());
     }
     // remove doubles
     $this->_specialAttributes = array_unique($this->_specialAttributes);
     return $this;
 }