コード例 #1
0
ファイル: Import.php プロジェクト: pradeep-wagento/magento2
 /**
  * Create instance of entity adapter and return it
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  * @return \Magento\ImportExport\Model\Import\Entity\AbstractEntity|\Magento\ImportExport\Model\Import\AbstractEntity
  */
 protected function _getEntityAdapter()
 {
     if (!$this->_entityAdapter) {
         $entities = $this->_importConfig->getEntities();
         if (isset($entities[$this->getEntity()])) {
             try {
                 $this->_entityAdapter = $this->_entityFactory->create($entities[$this->getEntity()]['model']);
             } catch (\Exception $e) {
                 $this->_logger->critical($e);
                 throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity model.'));
             }
             if (!$this->_entityAdapter instanceof \Magento\ImportExport\Model\Import\Entity\AbstractEntity && !$this->_entityAdapter instanceof \Magento\ImportExport\Model\Import\AbstractEntity) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('The entity adapter object must be an instance of %1 or %2.', 'Magento\\ImportExport\\Model\\Import\\Entity\\AbstractEntity', 'Magento\\ImportExport\\Model\\Import\\AbstractEntity'));
             }
             // check for entity codes integrity
             if ($this->getEntity() != $this->_entityAdapter->getEntityTypeCode()) {
                 throw new \Magento\Framework\Exception\LocalizedException(__('The input entity code is not equal to entity adapter code.'));
             }
         } else {
             throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity.'));
         }
         $this->_entityAdapter->setParameters($this->getData());
     }
     return $this->_entityAdapter;
 }
コード例 #2
0
ファイル: ImportTest.php プロジェクト: kid17/magento2
 public function testImportSource()
 {
     $entityTypeCode = 'code';
     $this->_importData->expects($this->any())->method('getEntityTypeCode')->will($this->returnValue($entityTypeCode));
     $behaviour = 'behaviour';
     $this->_importData->expects($this->once())->method('getBehavior')->will($this->returnValue($behaviour));
     $this->import->expects($this->any())->method('getDataSourceModel')->will($this->returnValue($this->_importData));
     $this->import->expects($this->any())->method('setData')->withConsecutive(['entity', $entityTypeCode], ['behavior', $behaviour]);
     $phraseClass = '\\Magento\\Framework\\Phrase';
     $this->import->expects($this->any())->method('addLogComment')->with($this->isInstanceOf($phraseClass));
     $this->_entityAdapter->expects($this->once())->method('importData')->will($this->returnSelf());
     $this->import->expects($this->once())->method('_getEntityAdapter')->will($this->returnValue($this->_entityAdapter));
     $importOnceMethodsReturnNull = ['getEntity', 'getBehavior', 'getProcessedRowsCount', 'getProcessedEntitiesCount', 'getInvalidRowsCount', 'getErrorsCount'];
     foreach ($importOnceMethodsReturnNull as $method) {
         $this->import->expects($this->once())->method($method)->will($this->returnValue(null));
     }
     $this->import->importSource();
 }
コード例 #3
0
 /**
  * Test importSource with expected exception
  *
  */
 public function testImportSourceException()
 {
     $exceptionMock = new \Magento\Framework\Exception\AlreadyExistsException(__('URL key for specified store already exists.'));
     $entityTypeCode = 'code';
     $this->_importData->expects($this->any())->method('getEntityTypeCode')->will($this->returnValue($entityTypeCode));
     $behaviour = 'behaviour';
     $this->_importData->expects($this->any())->method('getBehavior')->will($this->returnValue($behaviour));
     $this->import->expects($this->any())->method('getDataSourceModel')->will($this->returnValue($this->_importData));
     $this->import->expects($this->any())->method('setData')->withConsecutive(['entity', $entityTypeCode], ['behavior', $behaviour]);
     $phraseClass = '\\Magento\\Framework\\Phrase';
     $this->import->expects($this->any())->method('addLogComment')->with($this->isInstanceOf($phraseClass));
     $this->_entityAdapter->expects($this->any())->method('importData')->will($this->throwException($exceptionMock));
     $this->import->expects($this->any())->method('_getEntityAdapter')->will($this->returnValue($this->_entityAdapter));
     $importOnceMethodsReturnNull = ['getBehavior'];
     foreach ($importOnceMethodsReturnNull as $method) {
         $this->import->expects($this->once())->method($method)->will($this->returnValue(null));
     }
     $this->import->importSource();
 }
コード例 #4
0
ファイル: Product.php プロジェクト: whoople/magento2-testing
 /**
  * Validate data rows and save bunches to DB
  *
  * @return $this
  */
 protected function _saveValidatedBunches()
 {
     $source = $this->_getSource();
     $source->rewind();
     while ($source->valid()) {
         try {
             $rowData = $source->current();
         } catch (\InvalidArgumentException $e) {
             $this->addRowError($e->getMessage(), $this->_processedRowsCount);
             $this->_processedRowsCount++;
             $source->next();
             continue;
         }
         $rowData = $this->_customFieldsMapping($rowData);
         $this->validateRow($rowData, $source->key());
         $source->next();
     }
     $this->getOptionEntity()->validateAmbiguousData();
     return parent::_saveValidatedBunches();
 }
コード例 #5
0
 /**
  * Test getDeletedItemsCount()
  */
 public function testGetDeletedItemsCount()
 {
     $this->assertNotEmpty('integer', $this->_model->getDeletedItemsCount());
 }
コード例 #6
0
ファイル: Product.php プロジェクト: Atlis/docker-magento2
 /**
  * Validate data rows and save bunches to DB
  *
  * @return $this
  */
 protected function _saveValidatedBunches()
 {
     $source = $this->_getSource();
     $source->rewind();
     while ($source->valid()) {
         if ($this->_errorsCount >= $this->_errorsLimit) {
             // errors limit check
             return $this;
         }
         $rowData = $source->current();
         $this->validateRow($rowData, $source->key());
         $source->next();
     }
     $this->getOptionEntity()->validateAmbiguousData();
     return parent::_saveValidatedBunches();
 }
コード例 #7
0
 /**
  * Test for method isAttributeValid()
  *
  * @dataProvider isAttributeValidDataProvider
  * @covers \Magento\ImportExport\Model\Import\Entity\AbstractEntity::isAttributeValid
  *
  * @param string $attrCode
  * @param array $attrParams
  * @param array $rowData
  * @param int $rowNum
  * @param bool $expectedResult
  */
 public function testIsAttributeValid($attrCode, array $attrParams, array $rowData, $rowNum, $expectedResult)
 {
     $this->_createSourceAdapterMock(['_test1']);
     $this->assertEquals($expectedResult, $this->_model->isAttributeValid($attrCode, $attrParams, $rowData, $rowNum));
 }