diff --git a/app/code/Magento/CatalogImportExport/Model/Export/Product.php b/app/code/Magento/CatalogImportExport/Model/Export/Product.php index 15ab59aaab2b3..72810dc82611f 100644 --- a/app/code/Magento/CatalogImportExport/Model/Export/Product.php +++ b/app/code/Magento/CatalogImportExport/Model/Export/Product.php @@ -802,7 +802,7 @@ protected function getExportData() } } } catch (\Exception $e) { - $this->_logger->logException($e); + $this->_logger->critical($e); } return $exportData; } diff --git a/app/code/Magento/ConfigurableProduct/Model/Resource/Product/Type/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/Resource/Product/Type/Configurable.php index e556661f45b1a..671aa6b136ab4 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Resource/Product/Type/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/Resource/Product/Type/Configurable.php @@ -180,10 +180,6 @@ public function getConfigurableOptions($product, $attributes) implode( ' AND ', [ - $this->_getReadAdapter()->quoteInto( - 'entity_value.entity_type_id = ?', - $product->getEntityTypeId() - ), 'entity_value.attribute_id = super_attribute.attribute_id', 'entity_value.store_id = 0', 'entity_value.entity_id = product_link.product_id' diff --git a/app/code/Magento/Newsletter/Model/Subscriber.php b/app/code/Magento/Newsletter/Model/Subscriber.php index f288561028194..5fa2c3aa05263 100644 --- a/app/code/Magento/Newsletter/Model/Subscriber.php +++ b/app/code/Magento/Newsletter/Model/Subscriber.php @@ -442,7 +442,6 @@ public function subscribe($email) $this->setStatusChanged(true); try { - $this->save(); if ($isConfirmNeed === true && $isOwnSubscribes === false ) { @@ -450,6 +449,7 @@ public function subscribe($email) } else { $this->sendConfirmationSuccessEmail(); } + $this->save(); return $this->getStatus(); } catch (\Exception $e) { throw new \Exception($e->getMessage()); diff --git a/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php new file mode 100644 index 0000000000000..bd8380299a52e --- /dev/null +++ b/app/code/Magento/Newsletter/Test/Unit/Model/SubscriberTest.php @@ -0,0 +1,164 @@ +newsletterData = $this->getMock('Magento\Newsletter\Helper\Data', [], [], '', false); + $this->scopeConfig = $this->getMock('Magento\Framework\App\Config\ScopeConfigInterface'); + $this->transportBuilder = $this->getMock( + 'Magento\Framework\Mail\Template\TransportBuilder', + [ + 'setTemplateIdentifier', + 'setTemplateOptions', + 'setTemplateVars', + 'setFrom', + 'addTo', + 'getTransport' + ], + [], + '', + false + ); + $this->storeManager = $this->getMock('Magento\Store\Model\StoreManagerInterface'); + $this->customerSession = $this->getMock( + 'Magento\Customer\Model\Session', + [ + 'isLoggedIn', + 'getCustomerDataObject', + 'getCustomerId' + ], + [], + '', + false + ); + $this->customerRepository = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface'); + $this->customerAccountManagement = $this->getMock('Magento\Customer\Api\AccountManagementInterface'); + $this->inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface'); + $this->resource = $this->getMock( + 'Magento\Newsletter\Model\Resource\Subscriber', + [ + 'loadByEmail', + 'getIdFieldName', + 'save' + ], + [], + '', + false + ); + $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this); + + $this->subscriber = $this->objectManager->getObject( + 'Magento\Newsletter\Model\Subscriber', + [ + 'newsletterData' => $this->newsletterData, + 'scopeConfig' => $this->scopeConfig, + 'transportBuilder' => $this->transportBuilder, + 'storeManager' => $this->storeManager, + 'customerSession' => $this->customerSession, + 'customerRepository' => $this->customerRepository, + 'customerAccountManagement' => $this->customerAccountManagement, + 'inlineTranslation' => $this->inlineTranslation, + 'resource' => $this->resource + ] + ); + } + + public function testSubscribe() + { + $email = 'subscriber_email@magento.com'; + $this->resource->expects($this->any())->method('loadByEmail')->willReturn( + [ + 'subscriber_status' => 3, + 'subscriber_email' => $email, + 'name' => 'subscriber_name' + ] + ); + $this->resource->expects($this->any())->method('getIdFieldName')->willReturn('id_field'); + $this->scopeConfig->expects($this->any())->method('getValue')->willReturn(true); + $this->customerSession->expects($this->any())->method('isLoggedIn')->willReturn(true); + $customerDataModel = $this->getMock('\Magento\Customer\Api\Data\CustomerInterface'); + $this->customerSession->expects($this->any())->method('getCustomerDataObject')->willReturn($customerDataModel); + $this->customerSession->expects($this->any())->method('getCustomerId')->willReturn(1); + $customerDataModel->expects($this->any())->method('getEmail')->willReturn($email); + $this->customerRepository->expects($this->any())->method('getById')->willReturn($customerDataModel); + $customerDataModel->expects($this->any())->method('getStoreId')->willReturn(1); + $customerDataModel->expects($this->any())->method('getId')->willReturn(1); + $this->transportBuilder->expects($this->any())->method('setTemplateIdentifier')->willReturnSelf(); + $this->transportBuilder->expects($this->any())->method('setTemplateOptions')->willReturnSelf(); + $this->transportBuilder->expects($this->any())->method('setTemplateVars')->willReturnSelf(); + $this->transportBuilder->expects($this->any())->method('setFrom')->willReturnSelf(); + $this->transportBuilder->expects($this->any())->method('addTo')->willReturnSelf(); + $storeModel = $this->getMock('\Magento\Store\Model\Store', ['getId'], [], '', false); + $this->scopeConfig->expects($this->any())->method('getValue')->willReturn('owner_email@magento.com'); + $this->storeManager->expects($this->any())->method('getStore')->willReturn($storeModel); + $storeModel->expects($this->any())->method('getId')->willReturn(1); + $transport = $this->getMock('\Magento\Framework\Mail\TransportInterface'); + $this->transportBuilder->expects($this->any())->method('getTransport')->willReturn($transport); + $transport->expects($this->any())->method('sendMessage')->willReturnSelf(); + $inlineTranslation = $this->getMock('Magento\Framework\Translate\Inline\StateInterface'); + $inlineTranslation->expects($this->any())->method('resume')->willReturnSelf(); + $this->resource->expects($this->atLeastOnce())->method('save')->willReturnSelf(); + $this->assertEquals(1, $this->subscriber->subscribe($email)); + } +} diff --git a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php index def5584983e61..a83bb8be1c9fe 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Export/ProductTest.php @@ -125,4 +125,50 @@ public function verifyRow(array $rowData) ); } } + + /** + * Verifies if exception processing works properly + * + * @magentoDataFixture Magento/CatalogImportExport/_files/product_export_data.php + */ + public function testExceptionInGetExportData() + { + $exception = new \Exception('Error'); + + $rowCustomizerMock = $this->getMockBuilder('Magento\CatalogImportExport\Model\Export\RowCustomizerInterface') + ->disableOriginalConstructor() + ->getMock(); + + $loggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock(); + + $directoryMock = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false); + $directoryMock->expects($this->any())->method('getParentDirectory')->will($this->returnValue('some#path')); + $directoryMock->expects($this->any())->method('isWritable')->will($this->returnValue(true)); + + $filesystemMock = $this->getMock('Magento\Framework\Filesystem', [], [], '', false); + $filesystemMock->expects($this->once())->method('getDirectoryWrite')->will($this->returnValue($directoryMock)); + + $exportAdapter = new \Magento\ImportExport\Model\Export\Adapter\Csv($filesystemMock); + + $rowCustomizerMock->expects($this->once())->method('prepareData')->willThrowException($exception); + $loggerMock->expects($this->once())->method('critical')->with($exception); + + $collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + '\Magento\Catalog\Model\Resource\Product\Collection' + ); + + /** @var \Magento\CatalogImportExport\Model\Export\Product $model */ + $model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( + 'Magento\CatalogImportExport\Model\Export\Product', + [ + 'rowCustomizer' => $rowCustomizerMock, + 'logger' => $loggerMock, + 'collection' => $collection + ] + ); + + + $data = $model->setWriter($exportAdapter)->export(); + $this->assertEmpty($data); + } }