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