diff --git a/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php b/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php index 4dfde3887df85..fcc544f4cb805 100644 --- a/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php +++ b/app/code/Magento/CatalogImportExport/Model/Import/Uploader.php @@ -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; } @@ -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; } diff --git a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php index ef40216ddf924..48de57fa0aa10 100644 --- a/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php +++ b/app/code/Magento/CatalogImportExport/Test/Unit/Model/Import/UploaderTest.php @@ -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(); @@ -92,6 +93,7 @@ protected function setUp() $this->filesystem, $this->readFactory, ]) + ->setMethods(['_setUploadFile', 'save', 'getTmpDir']) ->getMock(); } @@ -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') @@ -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() diff --git a/app/code/Magento/Checkout/Model/Cart.php b/app/code/Magento/Checkout/Model/Cart.php index 759ce84ce8fc3..bfb8f6be5d022 100644 --- a/app/code/Magento/Checkout/Model/Cart.php +++ b/app/code/Magento/Checkout/Model/Cart.php @@ -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; }