Skip to content

Commit

Permalink
MAGETWO-82955: Merge branch '2.2-develop' of github.com:magento-engco…
Browse files Browse the repository at this point in the history
…m/magento2ce into MAGETWO-82955-PR-11747
  • Loading branch information
ishakhsuvarov committed Oct 29, 2017
2 parents 66cc8d2 + 373bd01 commit d61550d
Show file tree
Hide file tree
Showing 14 changed files with 344 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2042,6 +2042,7 @@ protected function uploadMediaFiles($fileName, $renameFileOff = false)
$res = $this->_getUploader()->move($fileName, $renameFileOff);
return $res['file'];
} catch (\Exception $e) {
$this->_logger->critical($e);
return '';
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1194,6 +1194,70 @@ public function testParseAttributesWithWrappedValuesWillReturnsLowercasedAttribu
$this->assertArrayNotHasKey('PARAM2', $attributes);
}

/**
* Test that errors occurred during importing images are logged.
*
* @param string $fileName
* @param bool $throwException
* @dataProvider uploadMediaFilesDataProvider
*/
public function testUploadMediaFiles(string $fileName, bool $throwException)
{
$exception = new \Exception();
$expectedFileName = $fileName;
if ($throwException) {
$expectedFileName = '';
$this->_logger->expects($this->once())->method('critical')->with($exception);
}

$fileUploaderMock = $this
->getMockBuilder(\Magento\CatalogImportExport\Model\Import\Uploader::class)
->disableOriginalConstructor()
->getMock();

$fileUploaderMock
->expects($this->once())
->method('move')
->willReturnCallback(
function ($name) use ($throwException, $exception) {
if ($throwException) {
throw $exception;
}
return ['file' => $name];
}
);

$this->setPropertyValue(
$this->importProduct,
'_fileUploader',
$fileUploaderMock
);

$actualFileName = $this->invokeMethod(
$this->importProduct,
'uploadMediaFiles',
[$fileName]
);

$this->assertEquals(
$expectedFileName,
$actualFileName
);
}

/**
* Data provider for testUploadMediaFiles.
*
* @return array
*/
public function uploadMediaFilesDataProvider()
{
return [
['test1.jpg', false],
['test2.jpg', true],
];
}

public function getImagesFromRowDataProvider()
{
return [
Expand Down
1 change: 0 additions & 1 deletion app/code/Magento/ImportExport/Model/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,6 @@ public function validateSource(\Magento\ImportExport\Model\Import\AbstractSource
ProcessingError::ERROR_LEVEL_CRITICAL,
null,
null,
null,
$e->getMessage()
);
}
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Model/Order/Pdf/Creditmemo.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ public function __construct(
protected function _drawHeader(\Zend_Pdf_Page $page)
{
$this->_setFontRegular($page, 10);
$page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 570, $this->y - 30);
$this->y -= 10;
$page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));

//columns headers
$lines[0][] = ['text' => __('Products'), 'feed' => 35];
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Model/Order/Pdf/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,12 @@ protected function _drawHeader(\Zend_Pdf_Page $page)
{
/* Add table head */
$this->_setFontRegular($page, 10);
$page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 570, $this->y - 15);
$this->y -= 10;
$page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));

//columns headers
$lines[0][] = ['text' => __('Products'), 'feed' => 35];
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Sales/Model/Order/Pdf/Shipment.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ protected function _drawHeader(\Zend_Pdf_Page $page)
{
/* Add table head */
$this->_setFontRegular($page, 10);
$page->setFillColor(new \Zend_Pdf_Color_RGB(0.93, 0.92, 0.92));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0.93, 0.92, 0.92));
$page->setLineColor(new \Zend_Pdf_Color_GrayScale(0.5));
$page->setLineWidth(0.5);
$page->drawRectangle(25, $this->y, 570, $this->y - 15);
$this->y -= 10;
$page->setFillColor(new \Zend_Pdf_Color_RGB(0, 0, 0));
$page->setFillColor(new \Zend_Pdf_Color_Rgb(0, 0, 0));

//columns headers
$lines[0][] = ['text' => __('Products'), 'feed' => 100];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

<scope args="chips" render=""/>

<div class="admin__data-grid-filters-wrap" data-part="filter-form" css="_show: hasVisible() && $collapsible.opened()">
<div class="admin__data-grid-filters-wrap" data-part="filter-form" css="_show: hasVisible() && $collapsible.opened()" keyboard="{ 13: apply }">
<fieldset class="admin__fieldset admin__data-grid-filters">
<legend class="admin__filters-legend">
<span translate="'Advanced filter'"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
use Magento\Framework\Filesystem;
use Magento\ImportExport\Model\Import;
use Magento\Store\Model\Store;
use Magento\UrlRewrite\Model\UrlRewrite;
use Psr\Log\LoggerInterface;

/**
* Class ProductTest
Expand Down Expand Up @@ -62,11 +62,20 @@ class ProductTest extends \Magento\TestFramework\Indexer\TestCase
*/
protected $objectManager;

/**
* @var LoggerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $logger;

protected function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->logger = $this->getMockBuilder(LoggerInterface::class)
->disableOriginalConstructor()
->getMock();
$this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
\Magento\CatalogImportExport\Model\Import\Product::class
\Magento\CatalogImportExport\Model\Import\Product::class,
['logger' => $this->logger]
);
parent::setUp();
}
Expand Down Expand Up @@ -659,6 +668,21 @@ public function testSaveMediaImage()
$this->assertEquals('Additional Image Label Two', $additionalImageTwoItem->getLabel());
}

/**
* Test that errors occurred during importing images are logged.
*
* @magentoDataIsolation enabled
* @magentoAppIsolation enabled
* @magentoDataFixture mediaImportImageFixture
* @magentoDataFixture mediaImportImageFixtureError
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function testSaveMediaImageError()
{
$this->logger->expects(self::once())->method('critical');
$this->importDataForMediaTest('import_media.csv', 1);
}

/**
* Copy fixture images into media import directory
*/
Expand Down Expand Up @@ -717,6 +741,30 @@ public static function mediaImportImageFixtureRollback()
$mediaDirectory->delete('catalog');
}

/**
* Copy incorrect fixture image into media import directory.
*/
public static function mediaImportImageFixtureError()
{
/** @var \Magento\Framework\Filesystem\Directory\Write $mediaDirectory */
$mediaDirectory = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->get(
\Magento\Framework\Filesystem::class
)->getDirectoryWrite(
DirectoryList::MEDIA
);
$dirPath = $mediaDirectory->getAbsolutePath('import');
$items = [
[
'source' => __DIR__ . '/_files/magento_additional_image_error.jpg',
'dest' => $dirPath . '/magento_additional_image_two.jpg',
],
];
foreach ($items as $item) {
copy($item['source'], $item['dest']);
}
}


/**
* Export CSV string to array
*
Expand Down Expand Up @@ -1564,8 +1612,9 @@ public function testProductWithWrappedAdditionalAttributes()
* Import and check data from file
*
* @param string $fileName
* @param int $expectedErrors
*/
private function importDataForMediaTest($fileName)
private function importDataForMediaTest(string $fileName, int $expectedErrors = 0)
{
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
Expand Down Expand Up @@ -1603,7 +1652,7 @@ private function importDataForMediaTest($fileName)
$this->assertTrue($errors->getErrorsCount() == 0);

$this->_model->importData();
$this->assertTrue($this->_model->getErrorAggregator()->getErrorsCount() == 0);
$this->assertTrue($this->_model->getErrorAggregator()->getErrorsCount() == $expectedErrors);
}

/**
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ public function testValidateSourceException()
$this->_model->validateSource($source);
}

public function testValidateSourceExceptionMessage()
{
$exceptionMessage = 'Test Exception Message.';

$validationStrategy = ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_STOP_ON_ERROR;
$this->_model->setEntity('catalog_product');
$this->_model->setData(\Magento\ImportExport\Model\Import::FIELD_NAME_VALIDATION_STRATEGY, $validationStrategy);
$this->_model->setData(\Magento\ImportExport\Model\Import::FIELD_NAME_ALLOWED_ERROR_COUNT, 0);

/** @var \Magento\ImportExport\Model\Import\AbstractSource|\PHPUnit_Framework_MockObject_MockObject $source */
$source = $this->getMockForAbstractClass(
\Magento\ImportExport\Model\Import\AbstractSource::class,
[['sku', 'name']]
);
$source->expects($this->any())->method('_getNextRow')->willThrowException(
new \Exception($exceptionMessage)
);

$this->assertFalse($this->_model->validateSource($source));
$this->assertEquals(
$exceptionMessage,
$this->_model->getErrorAggregator()->getAllErrors()[0]->getErrorMessage()
);
}

public function testGetEntity()
{
$entityName = 'entity_name';
Expand Down
4 changes: 2 additions & 2 deletions lib/internal/Magento/Framework/Config/Converter/Dom/Flat.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public function convert(\DOMNode $source, $basePath = '')
}
} else {
if ($result) {
$result['value'] = $value;
$result['value'] = trim($value);
} else {
$result = $value;
$result = trim($value);
}
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
// @codingStandardsIgnoreFile
return [
'root' => [
'node_one' => [
Expand All @@ -11,14 +12,20 @@
'subnode' => [
['attributeThree' => '30'],
['attributeThree' => '40', 'attributeFour' => '40', 'value' => 'Value1'],
['attributeThree' => '50', 'value' => 'value_from_new_line'],
['attributeThree' => '60', 'value' => 'auto_formatted_by_ide_value_due_to_line_size_restriction']
],
'books' => ['attributeFive' => '50'],
],
'multipleNode' => [
'one' => ['id' => 'one', 'name' => 'name1', 'value' => '1'],
'two' => ['id' => 'two', 'name' => 'name2', 'value' => '2'],
'three' => ['id' => 'three', 'name' => 'name3', 'value' => 'value_from_new_line'],
'four' => ['id' => 'four', 'name' => 'name4', 'value' => 'auto_formatted_by_ide_value_due_to_line_size_restriction'],
],
'someOtherVal' => '',
'someDataVal' => '',
'valueFromNewLine' => 'value_from_new_line',
'autoFormattedValue' => 'auto_formatted_by_ide_value_due_to_line_size_restriction'
]
];
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<node_one attributeOne = '10' attributeTwo = '20'>
<subnode attributeThree = '30'></subnode>
<subnode attributeThree = '40' attributeFour = '40' >Value1</subnode>
<subnode attributeThree = '50'>
value_from_new_line
</subnode>
<subnode attributeThree = '60'>auto_formatted_by_ide_value_due_to_line_size_restriction
</subnode>
<books attributeFive = '50' />
</node_one>
<multipleNode id="one" name="name1">
Expand All @@ -19,4 +24,18 @@
</multipleNode>
<someOtherVal></someOtherVal>
<someDataVal><![CDATA[]]></someDataVal>
<multipleNode id="three" name="name3">
<value>
value_from_new_line
</value>
</multipleNode>
<multipleNode id="four" name="name4">
<value>auto_formatted_by_ide_value_due_to_line_size_restriction
</value>
</multipleNode>
<valueFromNewLine>
value_from_new_line
</valueFromNewLine>
<autoFormattedValue>auto_formatted_by_ide_value_due_to_line_size_restriction
</autoFormattedValue>
</root>
Loading

0 comments on commit d61550d

Please sign in to comment.