Skip to content

Commit 318d829

Browse files
author
diana
committed
Merge branch 'MAGETWO-59036' into 2.1-develop-pr1
2 parents 163efae + e2ebb82 commit 318d829

File tree

4 files changed

+49
-21
lines changed

4 files changed

+49
-21
lines changed

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

Lines changed: 13 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,22 @@ 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
8389
*/
8490
public function __construct(
8591
\Magento\Checkout\Model\Session $checkoutSession,
@@ -90,12 +96,15 @@ public function __construct(
9096
\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile,
9197
\Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder,
9298
\Magento\Framework\Escaper $escaper,
93-
array $data = []
99+
array $data = [],
100+
Filesystem $filesystem = null
94101
) {
95102
$this->_itemOptionFactory = $itemOptionFactory;
96103
$this->_urlBuilder = $urlBuilder;
97104
$this->_escaper = $escaper;
98105
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
106+
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
107+
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
99108
$this->validatorInfo = $validatorInfo;
100109
$this->validatorFile = $validatorFile;
101110
parent::__construct($checkoutSession, $scopeConfig, $data);

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

Lines changed: 33 additions & 14 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,17 +28,29 @@ 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')
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(
35-
'Magento\MediaStorage\Helper\File\Storage\Database',
53+
\Magento\MediaStorage\Helper\File\Storage\Database::class,
3654
['copyFile'],
3755
[],
3856
'',
@@ -46,28 +64,29 @@ protected function setUp()
4664
protected function getFileObject()
4765
{
4866
return $this->objectManager->getObject(
49-
'Magento\Catalog\Model\Product\Option\Type\File',
67+
\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'
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));
@@ -89,7 +108,7 @@ public function testCopyQuoteToOrder()
89108
$fileObject->setData('configuration_item_option', $optionMock);
90109

91110
$this->assertInstanceOf(
92-
'Magento\Catalog\Model\Product\Option\Type\File',
111+
\Magento\Catalog\Model\Product\Option\Type\File::class,
93112
$fileObject->copyQuoteToOrder()
94113
);
95114
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,4 +800,7 @@
800800
</argument>
801801
</arguments>
802802
</type>
803+
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
804+
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
805+
</type>
803806
</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)