Skip to content

Commit

Permalink
Merge pull request #548 from magento-dragons/DRAGONS-PR2.0
Browse files Browse the repository at this point in the history
Fixed issues:
 - MAGETWO-59050 Portdown MAGETWO-50198 to 2.0
 - MAGETWO-59829 [Backport] Product import with images not working
  • Loading branch information
Oleksii Korshenko authored Oct 28, 2016
2 parents 572505c + a03ce7d commit 39229d6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 46 deletions.
10 changes: 5 additions & 5 deletions app/code/Magento/CatalogImportExport/Model/Import/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ public function move($fileName, $renameFileOff = false)

$filePath = $this->_directory->getRelativePath($this->getTmpDir() . '/' . $fileName);
$this->_setUploadFile($filePath);
$result = $this->save($this->getDestDir());
$destDir = $this->_directory->getAbsolutePath($this->getDestDir());
$result = $this->save($destDir);
$result['name'] = self::getCorrectFileName($result['name']);
return $result;
}
Expand Down Expand Up @@ -305,11 +306,10 @@ protected function _moveFile($tmpPath, $destPath)
$tmpRealPath = $this->_directory->getDriver()->getRealPath(
$this->_directory->getAbsolutePath($tmpPath)
);
$destinationRealPath = $this->_directory->getDriver()->getRealPath(
$this->_directory->getAbsolutePath($destPath)
);
$destinationRealPath = $this->_directory->getDriver()->getRealPath($destPath);
$relativeDestPath = $this->_directory->getRelativePath($destPath);
$isSameFile = $tmpRealPath === $destinationRealPath;
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $destPath);
return $isSameFile ?: $this->_directory->copyFile($tmpPath, $relativeDestPath);
} else {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,11 @@ protected function setUp()

$this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();

$this->directoryMock = $this->getMockBuilder('\Magento\Framework\Filesystem\Directory\Writer')
->setMethods(['writeFile', 'getRelativePath'])
->setMethods(['writeFile', 'getRelativePath', 'isWritable', 'getAbsolutePath'])
->disableOriginalConstructor()
->getMock();

Expand All @@ -92,6 +93,7 @@ protected function setUp()
$this->filesystem,
$this->readFactory,
])
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
->getMock();
}

Expand All @@ -100,10 +102,14 @@ protected function setUp()
*/
public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
{
$destDir = 'var/dest/dir';
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $expectedFileName;
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
->willReturn($destDir . '/' . $expectedFileName);
// Check writeFile() method invoking.
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue(null));
$this->directoryMock->expects($this->any())->method('writeFile')->will($this->returnValue($expectedFileName));

// Create adjusted reader which does not validate path.
$readMock = $this->getMockBuilder('Magento\Framework\Filesystem\File\Read')
Expand All @@ -113,59 +119,39 @@ public function testMoveFileUrl($fileUrl, $expectedHost, $expectedFileName)
// Check readAll() method invoking.
$readMock->expects($this->once())->method('readAll')->will($this->returnValue(null));

$this->readFactory = $this->getMockBuilder('\Magento\Framework\Filesystem\File\ReadFactory')
->disableOriginalConstructor()
->setMethods(['create'])
->getMock();
// Check create() method invoking with expected argument.
$this->readFactory->expects($this->once())
->method('create')
->will($this->returnValue($readMock))->with($expectedHost);

$uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader')
->setConstructorArgs([
$this->coreFileStorageDb,
$this->coreFileStorage,
$this->imageFactory,
$this->validator,
$this->filesystem,
$this->readFactory,
])
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
->getMock();
->method('create')
->will($this->returnValue($readMock))->with($expectedHost);

//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
$uploaderMock->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
$this->uploader->expects($this->any())->method('getTmpDir')->will($this->returnValue(''));
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $expectedFileName)
->willReturn(['name' => $expectedFileName]);

$uploaderMock->move($fileUrl);
$this->uploader->setDestDir($destDir);
$this->assertEquals(['name' => $expectedFileName], $this->uploader->move($fileUrl));
}

public function testMoveFileName()
{
$destDir = 'var/dest/dir';
$fileName = 'test_uploader_file';
$expectedRelativeFilePath = $this->uploader->getTmpDir() . '/' . $fileName;
$this->directoryMock->expects($this->once())->method('isWritable')->with($destDir)->willReturn(true);
$this->directoryMock->expects($this->any())->method('getRelativePath')->with($expectedRelativeFilePath);

$uploaderMock = $this->getMockBuilder('\Magento\CatalogImportExport\Model\Import\Uploader')
->setConstructorArgs([
$this->coreFileStorageDb,
$this->coreFileStorage,
$this->imageFactory,
$this->validator,
$this->filesystem,
$this->readFactory,
])
->setMethods(['_setUploadFile', 'save', 'getTmpDir'])
->getMock();
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($destDir)
->willReturn($destDir . '/' . $fileName);

//Check invoking of getTmpDir(), _setUploadFile(), save() methods.
$uploaderMock->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
$uploaderMock->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
$uploaderMock->expects($this->once())->method('save')->will($this->returnValue(['name' => null]));
$this->uploader->expects($this->once())->method('getTmpDir')->will($this->returnValue(''));
$this->uploader->expects($this->once())->method('_setUploadFile')->will($this->returnSelf());
$this->uploader->expects($this->once())->method('save')->with($destDir . '/' . $fileName)
->willReturn(['name' => $fileName]);

$uploaderMock->move($fileName);
$this->uploader->setDestDir($destDir);
$this->assertEquals(['name' => $fileName], $this->uploader->move($fileName));
}

public function moveFileUrlDataProvider()
Expand Down
6 changes: 5 additions & 1 deletion app/code/Magento/Checkout/Model/Cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,11 @@ public function addOrderItem($orderItem, $qtyFlag = null)
if ($orderItem->getParentItem() === null) {
$storeId = $this->_storeManager->getStore()->getId();
try {
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId);
/**
* We need to reload product in this place, because products
* with the same id may have different sets of order attributes.
*/
$product = $this->productRepository->getById($orderItem->getProductId(), false, $storeId, true);
} catch (NoSuchEntityException $e) {
return $this;
}
Expand Down

0 comments on commit 39229d6

Please sign in to comment.