Skip to content

Commit 9353da7

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-56370' into BUGS
2 parents 2856945 + f182b04 commit 9353da7

File tree

4 files changed

+47
-18
lines changed

4 files changed

+47
-18
lines changed

app/code/Magento/Catalog/Model/Product/Option/Type/File.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Catalog\Model\Product\Option\Type;
77

8+
use Magento\Framework\App\Filesystem\DirectoryList;
89
use Magento\Framework\Filesystem;
910
use Magento\Framework\Exception\LocalizedException;
1011
use Magento\Catalog\Model\Product\Exception as ProductException;
@@ -69,17 +70,23 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
6970
*/
7071
protected $validatorFile;
7172

73+
/**
74+
* @var Filesystem
75+
*/
76+
private $filesystem;
77+
7278
/**
7379
* @param \Magento\Checkout\Model\Session $checkoutSession
7480
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
7581
* @param \Magento\Quote\Model\Quote\Item\OptionFactory $itemOptionFactory
76-
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
77-
* @param \Magento\Framework\Escaper $escaper
7882
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
7983
* @param File\ValidatorInfo $validatorInfo
8084
* @param File\ValidatorFile $validatorFile
85+
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
86+
* @param \Magento\Framework\Escaper $escaper
8187
* @param array $data
82-
* @throws \Magento\Framework\Exception\FileSystemException
88+
* @param Filesystem $filesystem
89+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
8390
*/
8491
public function __construct(
8592
\Magento\Checkout\Model\Session $checkoutSession,
@@ -90,12 +97,15 @@ public function __construct(
9097
\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile,
9198
\Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder,
9299
\Magento\Framework\Escaper $escaper,
93-
array $data = []
100+
array $data = [],
101+
Filesystem $filesystem = null
94102
) {
95103
$this->_itemOptionFactory = $itemOptionFactory;
96104
$this->_urlBuilder = $urlBuilder;
97105
$this->_escaper = $escaper;
98106
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
107+
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
108+
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
99109
$this->validatorInfo = $validatorInfo;
100110
$this->validatorFile = $validatorFile;
101111
parent::__construct($checkoutSession, $scopeConfig, $data);

app/code/Magento/Catalog/Test/Unit/Model/Product/Option/Type/FileTest.php

Lines changed: 30 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
*/
66
namespace Magento\Catalog\Test\Unit\Model\Product\Option\Type;
77

8+
use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
9+
use Magento\Framework\App\Filesystem\DirectoryList;
10+
use Magento\Framework\Filesystem;
11+
use Magento\Framework\Filesystem\Directory\ReadInterface;
12+
use Magento\Framework\Filesystem\DriverPool;
13+
814
class FileTest extends \PHPUnit_Framework_TestCase
915
{
1016
/**
@@ -13,7 +19,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
1319
protected $objectManager;
1420

1521
/**
16-
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
22+
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
1723
*/
1824
protected $rootDirectory;
1925

@@ -22,14 +28,26 @@ class FileTest extends \PHPUnit_Framework_TestCase
2228
*/
2329
protected $coreFileStorageDatabase;
2430

31+
/**
32+
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
33+
*/
34+
private $filesystemMock;
35+
2536
protected function setUp()
2637
{
2738
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
2839

29-
$this->rootDirectory = $this->getMockBuilder(\Magento\Framework\Filesystem\Directory\ReadInterface::class)
40+
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
3041
->disableOriginalConstructor()
31-
->setMethods(['isFile', 'isReadable', 'getAbsolutePath'])
32-
->getMockForAbstractClass();
42+
->getMock();
43+
44+
$this->rootDirectory = $this->getMockBuilder(ReadInterface::class)
45+
->getMock();
46+
47+
$this->filesystemMock->expects($this->once())
48+
->method('getDirectoryRead')
49+
->with(DirectoryList::MEDIA, DriverPool::FILE)
50+
->willReturn($this->rootDirectory);
3351

3452
$this->coreFileStorageDatabase = $this->getMock(
3553
\Magento\MediaStorage\Helper\File\Storage\Database::class,
@@ -48,26 +66,27 @@ protected function getFileObject()
4866
return $this->objectManager->getObject(
4967
\Magento\Catalog\Model\Product\Option\Type\File::class,
5068
[
51-
'saleableItem' => $this->rootDirectory,
52-
'priceCurrency' => $this->coreFileStorageDatabase
69+
'filesystem' => $this->filesystemMock,
70+
'coreFileStorageDatabase' => $this->coreFileStorageDatabase
5371
]
5472
);
5573
}
5674

5775
public function testCopyQuoteToOrder()
5876
{
59-
$optionMock = $this->getMockBuilder(
60-
\Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface::class
61-
)->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
77+
$optionMock = $this->getMockBuilder(OptionInterface::class)
78+
->disableOriginalConstructor()
79+
->setMethods(['getValue'])
80+
->getMockForAbstractClass();
6281

6382
$quotePath = '/quote/path/path/uploaded.file';
6483
$orderPath = '/order/path/path/uploaded.file';
6584

6685
$optionMock->expects($this->any())
6786
->method('getValue')
68-
->will($this->returnValue(['quote_path' => $quotePath, 'order_path' => $orderPath]));
87+
->will($this->returnValue(serialize(['quote_path' => $quotePath, 'order_path' => $orderPath])));
6988

70-
$this->rootDirectory->expects($this->any())
89+
$this->rootDirectory->expects($this->once())
7190
->method('isFile')
7291
->with($this->equalTo($quotePath))
7392
->will($this->returnValue(true));

app/code/Magento/Catalog/etc/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -834,4 +834,7 @@
834834
<argument name="collectionProcessor" xsi:type="object">Magento\Eav\Model\Api\SearchCriteria\CollectionProcessor</argument>
835835
</arguments>
836836
</type>
837+
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
838+
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
839+
</type>
837840
</config>

app/code/Magento/Catalog/etc/frontend/di.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@
1818
<argument name="fetchStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection\FetchStrategy</argument>
1919
</arguments>
2020
</type>
21-
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
22-
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
23-
</type>
2421
<type name="Magento\Catalog\Model\Indexer\AbstractFlatState">
2522
<arguments>
2623
<argument name="isAvailable" xsi:type="boolean">true</argument>

0 commit comments

Comments
 (0)