Skip to content

Commit 8714292

Browse files
author
Volodymyr Klymenko
authored
Merge pull request #593 from magento-tsg/2.1-develop-pr1
[TSG] Backporting for 2.1
2 parents bf41d40 + ec290c3 commit 8714292

File tree

30 files changed

+1110
-341
lines changed

30 files changed

+1110
-341
lines changed

app/code/Magento/Braintree/Helper/Country.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
*/
66
namespace Magento\Braintree\Helper;
77

8+
use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig;
89
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;
910

1011
/**
@@ -13,12 +14,12 @@
1314
class Country
1415
{
1516
/**
16-
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
17+
* @var CollectionFactory
1718
*/
1819
private $collectionFactory;
1920

2021
/**
21-
* @var \Magento\Braintree\Model\Adminhtml\System\Config\Country
22+
* @var CountryConfig
2223
*/
2324
private $countryConfig;
2425

@@ -28,13 +29,11 @@ class Country
2829
private $countries;
2930

3031
/**
31-
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory
32-
* @param \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
32+
* @param CollectionFactory $factory
33+
* @param CountryConfig $countryConfig
3334
*/
34-
public function __construct(
35-
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory,
36-
\Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
37-
) {
35+
public function __construct(CollectionFactory $factory, CountryConfig $countryConfig)
36+
{
3837
$this->collectionFactory = $factory;
3938
$this->countryConfig = $countryConfig;
4039
}
@@ -52,6 +51,7 @@ public function getCountries()
5251
->loadData()
5352
->toOptionArray(false);
5453
}
54+
5555
return $this->countries;
5656
}
5757
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::PAYPAL_CODE</argument>
2323
<argument name="infoBlockType" xsi:type="string">BraintreePayPalInfo</argument>
2424
<argument name="valueHandlerPool" xsi:type="object">BraintreePayPalValueHandlerPool</argument>
25+
<argument name="validatorPool" xsi:type="object">BraintreePayPalValidatorPool</argument>
2526
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
2627
</arguments>
2728
</virtualType>
@@ -379,7 +380,7 @@
379380
</arguments>
380381
</virtualType>
381382

382-
<!-- Value validators infrastructure -->
383+
<!-- Braintree validators infrastructure -->
383384
<virtualType name="BraintreeCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
384385
<arguments>
385386
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
@@ -392,6 +393,22 @@
392393
</argument>
393394
</arguments>
394395
</virtualType>
396+
<!-- Braintree validators infrastructure -->
397+
398+
<!-- Braintree PayPal validators -->
399+
<virtualType name="BraintreePayPalCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
400+
<arguments>
401+
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\PayPal\Config</argument>
402+
</arguments>
403+
</virtualType>
404+
<virtualType name="BraintreePayPalValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
405+
<arguments>
406+
<argument name="validators" xsi:type="array">
407+
<item name="country" xsi:type="string">BraintreePayPalCountryValidator</item>
408+
</argument>
409+
</arguments>
410+
</virtualType>
411+
<!-- END Braintree PayPal validators -->
395412

396413
<type name="Magento\Braintree\Block\Info">
397414
<arguments>

app/code/Magento/Braintree/view/frontend/web/js/view/payment/method-renderer/paypal.js

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,18 @@ define([
1111
'Magento_Braintree/js/view/payment/adapter',
1212
'Magento_Checkout/js/model/quote',
1313
'Magento_Checkout/js/model/full-screen-loader',
14-
'Magento_Checkout/js/model/payment/additional-validators'
15-
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
14+
'Magento_Checkout/js/model/payment/additional-validators',
15+
'Magento_Checkout/js/action/create-billing-address'
16+
], function (
17+
$,
18+
_,
19+
Component,
20+
Braintree,
21+
quote,
22+
fullScreenLoader,
23+
additionalValidators,
24+
createBillingAddress
25+
) {
1626
'use strict';
1727

1828
return Component.extend({
@@ -152,14 +162,16 @@ define([
152162
var billingAddress = {
153163
street: [address.streetAddress],
154164
city: address.locality,
155-
regionCode: address.region,
156165
postcode: address.postalCode,
157166
countryId: address.countryCodeAlpha2,
167+
email: customer.email,
158168
firstname: customer.firstName,
159169
lastname: customer.lastName,
160170
telephone: customer.phone
161171
};
162172

173+
billingAddress['region_code'] = address.region;
174+
billingAddress = createBillingAddress(billingAddress);
163175
quote.billingAddress(billingAddress);
164176
},
165177

app/code/Magento/Catalog/Model/Product.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,14 +1905,18 @@ public function addOption(Product\Option $option)
19051905
*/
19061906
public function getOptionById($optionId)
19071907
{
1908-
/** @var \Magento\Catalog\Model\Product\Option $option */
1909-
foreach ($this->getOptions() as $option) {
1910-
if ($option->getId() == $optionId) {
1911-
return $option;
1908+
$result = null;
1909+
if (is_array($this->getOptions())) {
1910+
/** @var \Magento\Catalog\Model\Product\Option $option */
1911+
foreach ($this->getOptions() as $option) {
1912+
if ($option->getId() == $optionId) {
1913+
$result = $option;
1914+
break;
1915+
}
19121916
}
19131917
}
19141918

1915-
return null;
1919+
return $result;
19161920
}
19171921

19181922
/**

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/Test/Unit/Model/ProductTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,4 +1332,27 @@ public function testGetTypeId()
13321332
$this->model->setTypeId('typeId');
13331333
$this->model->getTypeInstance();
13341334
}
1335+
1336+
public function testGetOptionById()
1337+
{
1338+
$optionId = 100;
1339+
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
1340+
$this->model->setOptions([$optionMock]);
1341+
$optionMock->expects($this->once())->method('getId')->willReturn($optionId);
1342+
$this->assertEquals($optionMock, $this->model->getOptionById($optionId));
1343+
}
1344+
1345+
public function testGetOptionByIdWithWrongOptionId()
1346+
{
1347+
$optionId = 100;
1348+
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
1349+
$this->model->setOptions([$optionMock]);
1350+
$optionMock->expects($this->once())->method('getId')->willReturn(200);
1351+
$this->assertNull($this->model->getOptionById($optionId));
1352+
}
1353+
1354+
public function testGetOptionByIdForProductWithoutOptions()
1355+
{
1356+
$this->assertNull($this->model->getOptionById(100));
1357+
}
13351358
}

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

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

app/code/Magento/CatalogSearch/Model/Indexer/IndexerHandlerFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,17 @@ public function create(array $data = [])
7575
$indexer = $this->_objectManager->create($this->handlers[$currentHandler], $data);
7676

7777
if (!$indexer instanceof IndexerInterface) {
78-
throw new \InvalidArgumentException($indexer . ' doesn\'t implement \Magento\Framework\IndexerInterface');
78+
throw new \InvalidArgumentException(
79+
$currentHandler . ' indexer handler doesn\'t implement ' . IndexerInterface::class
80+
);
7981
}
8082

8183
if ($indexer && !$indexer->isAvailable()) {
8284
throw new \LogicException(
83-
'Indexer handler is not available: ' . $indexer
85+
'Indexer handler is not available: ' . $currentHandler
8486
);
8587
}
88+
8689
return $indexer;
8790
}
8891
}

0 commit comments

Comments
 (0)