|
26 | 26 | use Magento\Framework\Filesystem;
|
27 | 27 | use Magento\ImportExport\Model\Import;
|
28 | 28 | use Magento\Store\Model\Store;
|
29 |
| -use Magento\UrlRewrite\Model\UrlRewrite; |
| 29 | +use Psr\Log\LoggerInterface; |
30 | 30 |
|
31 | 31 | /**
|
32 | 32 | * Class ProductTest
|
@@ -62,11 +62,20 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
|
62 | 62 | */
|
63 | 63 | protected $objectManager;
|
64 | 64 |
|
| 65 | + /** |
| 66 | + * @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject |
| 67 | + */ |
| 68 | + private $logger; |
| 69 | + |
65 | 70 | protected function setUp()
|
66 | 71 | {
|
67 | 72 | $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
| 73 | + $this->logger = $this->getMockBuilder(LoggerInterface::class) |
| 74 | + ->disableOriginalConstructor() |
| 75 | + ->getMock(); |
68 | 76 | $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
|
69 |
| - \Magento\CatalogImportExport\Model\Import\Product::class |
| 77 | + \Magento\CatalogImportExport\Model\Import\Product::class, |
| 78 | + ['logger' => $this->logger] |
70 | 79 | );
|
71 | 80 | parent::setUp();
|
72 | 81 | }
|
@@ -659,6 +668,21 @@ public function testSaveMediaImage()
|
659 | 668 | $this->assertEquals('Additional Image Label Two', $additionalImageTwoItem->getLabel());
|
660 | 669 | }
|
661 | 670 |
|
| 671 | + /** |
| 672 | + * Test that errors occurred during importing images are logged. |
| 673 | + * |
| 674 | + * @magentoDataIsolation enabled |
| 675 | + * @magentoAppIsolation enabled |
| 676 | + * @magentoDataFixture mediaImportImageFixture |
| 677 | + * @magentoDataFixture mediaImportImageFixtureError |
| 678 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 679 | + */ |
| 680 | + public function testSaveMediaImageError() |
| 681 | + { |
| 682 | + $this->logger->expects(self::once())->method('critical'); |
| 683 | + $this->importDataForMediaTest('import_media.csv', 1); |
| 684 | + } |
| 685 | + |
662 | 686 | /**
|
663 | 687 | * Copy fixture images into media import directory
|
664 | 688 | */
|
@@ -717,6 +741,30 @@ public static function mediaImportImageFixtureRollback()
|
717 | 741 | $mediaDirectory->delete('catalog');
|
718 | 742 | }
|
719 | 743 |
|
| 744 | + /** |
| 745 | + * Copy incorrect fixture image into media import directory. |
| 746 | + */ |
| 747 | + public static function mediaImportImageFixtureError() |
| 748 | + { |
| 749 | + /** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */ |
| 750 | + $mediaDirectory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get( |
| 751 | + \Magento\Framework\Filesystem::class |
| 752 | + )->getDirectoryWrite( |
| 753 | + DirectoryList::MEDIA |
| 754 | + ); |
| 755 | + $dirPath = $mediaDirectory->getAbsolutePath('import'); |
| 756 | + $items = [ |
| 757 | + [ |
| 758 | + 'source' => __DIR__ . '/_files/magento_additional_image_error.jpg', |
| 759 | + 'dest' => $dirPath . '/magento_additional_image_two.jpg', |
| 760 | + ], |
| 761 | + ]; |
| 762 | + foreach ($items as $item) { |
| 763 | + copy($item['source'], $item['dest']); |
| 764 | + } |
| 765 | + } |
| 766 | + |
| 767 | + |
720 | 768 | /**
|
721 | 769 | * Export CSV string to array
|
722 | 770 | *
|
@@ -1564,8 +1612,9 @@ public function testProductWithWrappedAdditionalAttributes()
|
1564 | 1612 | * Import and check data from file
|
1565 | 1613 | *
|
1566 | 1614 | * @param string $fileName
|
| 1615 | + * @param int $expectedErrors |
1567 | 1616 | */
|
1568 |
| - private function importDataForMediaTest($fileName) |
| 1617 | + private function importDataForMediaTest(string $fileName, int $expectedErrors = 0) |
1569 | 1618 | {
|
1570 | 1619 | $filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
|
1571 | 1620 | $directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
|
@@ -1603,7 +1652,7 @@ private function importDataForMediaTest($fileName)
|
1603 | 1652 | $this->assertTrue($errors->getErrorsCount() == 0);
|
1604 | 1653 |
|
1605 | 1654 | $this->_model->importData();
|
1606 |
| - $this->assertTrue($this->_model->getErrorAggregator()->getErrorsCount() == 0); |
| 1655 | + $this->assertTrue($this->_model->getErrorAggregator()->getErrorsCount() == $expectedErrors); |
1607 | 1656 | }
|
1608 | 1657 |
|
1609 | 1658 | /**
|
|
0 commit comments