-
Notifications
You must be signed in to change notification settings - Fork 9.4k
10058: Tablerate->getCsvFile() fails with non-default PHP upload_tmp_dir #12275
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
app/code/Magento/OfflineShipping/Test/Unit/Model/ResourceModel/Carrier/TablerateTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
namespace Magento\OfflineShipping\Test\Unit\Model\ResourceModel\Carrier; | ||
|
||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate; | ||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Import; | ||
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory; | ||
|
||
/** | ||
* Unit test for Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate | ||
* | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
class TablerateTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
/** | ||
* @var Tablerate | ||
*/ | ||
private $model; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $storeManagerMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $filesystemMock; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $resource; | ||
|
||
/** | ||
* @var \PHPUnit_Framework_MockObject_MockObject | ||
*/ | ||
private $importMock; | ||
|
||
protected function setUp() | ||
{ | ||
$contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class); | ||
$loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class); | ||
$coreConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class); | ||
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class); | ||
$carrierTablerateMock = $this->createMock(\Magento\OfflineShipping\Model\Carrier\Tablerate::class); | ||
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class); | ||
$this->importMock = $this->createMock(Import::class); | ||
$rateQueryFactoryMock = $this->createMock(RateQueryFactory::class); | ||
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class); | ||
|
||
$contextMock->expects($this->once())->method('getResources')->willReturn($this->resource); | ||
|
||
$this->model = new Tablerate( | ||
$contextMock, | ||
$loggerMock, | ||
$coreConfigMock, | ||
$this->storeManagerMock, | ||
$carrierTablerateMock, | ||
$this->filesystemMock, | ||
$this->importMock, | ||
$rateQueryFactoryMock | ||
); | ||
} | ||
|
||
public function testUploadAndImport() | ||
{ | ||
$_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'] = 'some/path/to/file'; | ||
$object = $this->createPartialMock( | ||
\Magento\OfflineShipping\Model\Config\Backend\Tablerate::class, | ||
['getScopeId'] | ||
); | ||
|
||
$websiteMock = $this->createMock(\Magento\Store\Api\Data\WebsiteInterface::class); | ||
$directoryReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class); | ||
$fileReadMock = $this->createMock(\Magento\Framework\Filesystem\File\ReadInterface::class); | ||
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class); | ||
|
||
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($websiteMock); | ||
$object->expects($this->once())->method('getScopeId')->willReturn(1); | ||
$websiteMock->expects($this->once())->method('getId')->willReturn(1); | ||
|
||
$this->filesystemMock->expects($this->once())->method('getDirectoryReadByPath') | ||
->with('some/path/to')->willReturn($directoryReadMock); | ||
$directoryReadMock->expects($this->once())->method('openFile') | ||
->with('file')->willReturn($fileReadMock); | ||
|
||
$this->resource->expects($this->once())->method('getConnection')->willReturn($connectionMock); | ||
|
||
$connectionMock->expects($this->once())->method('beginTransaction'); | ||
$connectionMock->expects($this->once())->method('delete'); | ||
$connectionMock->expects($this->once())->method('commit'); | ||
|
||
$this->importMock->expects($this->once())->method('getColumns')->willReturn([]); | ||
$this->importMock->expects($this->once())->method('getData')->willReturn([]); | ||
|
||
$this->model->uploadAndImport($object); | ||
unset($_FILES['groups']); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately we cannot add new public methods to this class as it has been marked with
@api
would it work if we calledgetDirectoryRead
here instead of making the new call?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmanners, no it wouldn't. It checks it suggested path is one of the /Magento/Framework/App/Filesystem/DirectoryList::getDefaultConfig().
And what if I'll create the pr with a same code to 2.3?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm ok, If that is not possible then I would suggest that 2.3 would be fine for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dmanners,link for the pr to 2.3: #12376.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about creating a new class (something like
\Magento\Framework\FilesystemV2
) and using that one instead (by injecting it as an extra optional parameter atMagento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate::__construct()
) and deprecating the old one? Would that be deemed acceptable in such a case?