Skip to content

Commit

Permalink
Merge pull request #593 from magento-tsg/2.1-develop-pr1
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.1
  • Loading branch information
Volodymyr Klymenko authored Nov 15, 2016
2 parents bf41d40 + ec290c3 commit 8714292
Show file tree
Hide file tree
Showing 30 changed files with 1,110 additions and 341 deletions.
16 changes: 8 additions & 8 deletions app/code/Magento/Braintree/Helper/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Braintree\Helper;

use Magento\Braintree\Model\Adminhtml\System\Config\Country as CountryConfig;
use Magento\Directory\Model\ResourceModel\Country\CollectionFactory;

/**
Expand All @@ -13,12 +14,12 @@
class Country
{
/**
* @var \Magento\Directory\Model\ResourceModel\Country\CollectionFactory
* @var CollectionFactory
*/
private $collectionFactory;

/**
* @var \Magento\Braintree\Model\Adminhtml\System\Config\Country
* @var CountryConfig
*/
private $countryConfig;

Expand All @@ -28,13 +29,11 @@ class Country
private $countries;

/**
* @param \Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory
* @param \Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
* @param CollectionFactory $factory
* @param CountryConfig $countryConfig
*/
public function __construct(
\Magento\Directory\Model\ResourceModel\Country\CollectionFactory $factory,
\Magento\Braintree\Model\Adminhtml\System\Config\Country $countryConfig
) {
public function __construct(CollectionFactory $factory, CountryConfig $countryConfig)
{
$this->collectionFactory = $factory;
$this->countryConfig = $countryConfig;
}
Expand All @@ -52,6 +51,7 @@ public function getCountries()
->loadData()
->toOptionArray(false);
}

return $this->countries;
}
}
19 changes: 18 additions & 1 deletion app/code/Magento/Braintree/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<argument name="code" xsi:type="const">Magento\Braintree\Model\Ui\ConfigProvider::PAYPAL_CODE</argument>
<argument name="infoBlockType" xsi:type="string">BraintreePayPalInfo</argument>
<argument name="valueHandlerPool" xsi:type="object">BraintreePayPalValueHandlerPool</argument>
<argument name="validatorPool" xsi:type="object">BraintreePayPalValidatorPool</argument>
<argument name="commandPool" xsi:type="object">BraintreePayPalCommandPool</argument>
</arguments>
</virtualType>
Expand Down Expand Up @@ -379,7 +380,7 @@
</arguments>
</virtualType>

<!-- Value validators infrastructure -->
<!-- Braintree validators infrastructure -->
<virtualType name="BraintreeCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\Config</argument>
Expand All @@ -392,6 +393,22 @@
</argument>
</arguments>
</virtualType>
<!-- Braintree validators infrastructure -->

<!-- Braintree PayPal validators -->
<virtualType name="BraintreePayPalCountryValidator" type="Magento\Payment\Gateway\Validator\CountryValidator">
<arguments>
<argument name="config" xsi:type="object">Magento\Braintree\Gateway\Config\PayPal\Config</argument>
</arguments>
</virtualType>
<virtualType name="BraintreePayPalValidatorPool" type="Magento\Payment\Gateway\Validator\ValidatorPool">
<arguments>
<argument name="validators" xsi:type="array">
<item name="country" xsi:type="string">BraintreePayPalCountryValidator</item>
</argument>
</arguments>
</virtualType>
<!-- END Braintree PayPal validators -->

<type name="Magento\Braintree\Block\Info">
<arguments>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,18 @@ define([
'Magento_Braintree/js/view/payment/adapter',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/full-screen-loader',
'Magento_Checkout/js/model/payment/additional-validators'
], function ($, _, Component, Braintree, quote, fullScreenLoader, additionalValidators) {
'Magento_Checkout/js/model/payment/additional-validators',
'Magento_Checkout/js/action/create-billing-address'
], function (
$,
_,
Component,
Braintree,
quote,
fullScreenLoader,
additionalValidators,
createBillingAddress
) {
'use strict';

return Component.extend({
Expand Down Expand Up @@ -152,14 +162,16 @@ define([
var billingAddress = {
street: [address.streetAddress],
city: address.locality,
regionCode: address.region,
postcode: address.postalCode,
countryId: address.countryCodeAlpha2,
email: customer.email,
firstname: customer.firstName,
lastname: customer.lastName,
telephone: customer.phone
};

billingAddress['region_code'] = address.region;
billingAddress = createBillingAddress(billingAddress);
quote.billingAddress(billingAddress);
},

Expand Down
14 changes: 9 additions & 5 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1905,14 +1905,18 @@ public function addOption(Product\Option $option)
*/
public function getOptionById($optionId)
{
/** @var \Magento\Catalog\Model\Product\Option $option */
foreach ($this->getOptions() as $option) {
if ($option->getId() == $optionId) {
return $option;
$result = null;
if (is_array($this->getOptions())) {
/** @var \Magento\Catalog\Model\Product\Option $option */
foreach ($this->getOptions() as $option) {
if ($option->getId() == $optionId) {
$result = $option;
break;
}
}
}

return null;
return $result;
}

/**
Expand Down
17 changes: 13 additions & 4 deletions app/code/Magento/Catalog/Model/Product/Option/Type/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\Catalog\Model\Product\Option\Type;

use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Exception\LocalizedException;
use Magento\Catalog\Model\Product\Exception as ProductException;
Expand Down Expand Up @@ -69,17 +70,22 @@ class File extends \Magento\Catalog\Model\Product\Option\Type\DefaultType
*/
protected $validatorFile;

/**
* @var Filesystem
*/
private $filesystem;

/**
* @param \Magento\Checkout\Model\Session $checkoutSession
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Quote\Model\Quote\Item\OptionFactory $itemOptionFactory
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
* @param \Magento\Framework\Escaper $escaper
* @param \Magento\MediaStorage\Helper\File\Storage\Database $coreFileStorageDatabase
* @param File\ValidatorInfo $validatorInfo
* @param File\ValidatorFile $validatorFile
* @param \Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder
* @param \Magento\Framework\Escaper $escaper
* @param array $data
* @throws \Magento\Framework\Exception\FileSystemException
* @param Filesystem $filesystem
*/
public function __construct(
\Magento\Checkout\Model\Session $checkoutSession,
Expand All @@ -90,12 +96,15 @@ public function __construct(
\Magento\Catalog\Model\Product\Option\Type\File\ValidatorFile $validatorFile,
\Magento\Catalog\Model\Product\Option\UrlBuilder $urlBuilder,
\Magento\Framework\Escaper $escaper,
array $data = []
array $data = [],
Filesystem $filesystem = null
) {
$this->_itemOptionFactory = $itemOptionFactory;
$this->_urlBuilder = $urlBuilder;
$this->_escaper = $escaper;
$this->_coreFileStorageDatabase = $coreFileStorageDatabase;
$this->filesystem = $filesystem ?: \Magento\Framework\App\ObjectManager::getInstance()->get(Filesystem::class);
$this->_rootDirectory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$this->validatorInfo = $validatorInfo;
$this->validatorFile = $validatorFile;
parent::__construct($checkoutSession, $scopeConfig, $data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
*/
namespace Magento\Catalog\Test\Unit\Model\Product\Option\Type;

use Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface;
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Filesystem;
use Magento\Framework\Filesystem\Directory\ReadInterface;
use Magento\Framework\Filesystem\DriverPool;

class FileTest extends \PHPUnit_Framework_TestCase
{
/**
Expand All @@ -13,7 +19,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
protected $objectManager;

/**
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
* @var ReadInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $rootDirectory;

Expand All @@ -22,17 +28,29 @@ class FileTest extends \PHPUnit_Framework_TestCase
*/
protected $coreFileStorageDatabase;

/**
* @var Filesystem|\PHPUnit_Framework_MockObject_MockObject
*/
private $filesystemMock;

protected function setUp()
{
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);

$this->rootDirectory = $this->getMockBuilder('Magento\Framework\Filesystem\Directory\ReadInterface')
$this->filesystemMock = $this->getMockBuilder(Filesystem::class)
->disableOriginalConstructor()
->setMethods(['isFile', 'isReadable', 'getAbsolutePath'])
->getMockForAbstractClass();
->getMock();

$this->rootDirectory = $this->getMockBuilder(ReadInterface::class)
->getMock();

$this->filesystemMock->expects($this->once())
->method('getDirectoryRead')
->with(DirectoryList::MEDIA, DriverPool::FILE)
->willReturn($this->rootDirectory);

$this->coreFileStorageDatabase = $this->getMock(
'Magento\MediaStorage\Helper\File\Storage\Database',
\Magento\MediaStorage\Helper\File\Storage\Database::class,
['copyFile'],
[],
'',
Expand All @@ -46,28 +64,29 @@ protected function setUp()
protected function getFileObject()
{
return $this->objectManager->getObject(
'Magento\Catalog\Model\Product\Option\Type\File',
\Magento\Catalog\Model\Product\Option\Type\File::class,
[
'saleableItem' => $this->rootDirectory,
'priceCurrency' => $this->coreFileStorageDatabase
'filesystem' => $this->filesystemMock,
'coreFileStorageDatabase' => $this->coreFileStorageDatabase
]
);
}

public function testCopyQuoteToOrder()
{
$optionMock = $this->getMockBuilder(
'Magento\Catalog\Model\Product\Configuration\Item\Option\OptionInterface'
)->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
$optionMock = $this->getMockBuilder(OptionInterface::class)
->disableOriginalConstructor()
->setMethods(['getValue'])
->getMockForAbstractClass();

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

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

$this->rootDirectory->expects($this->any())
$this->rootDirectory->expects($this->once())
->method('isFile')
->with($this->equalTo($quotePath))
->will($this->returnValue(true));
Expand All @@ -89,7 +108,7 @@ public function testCopyQuoteToOrder()
$fileObject->setData('configuration_item_option', $optionMock);

$this->assertInstanceOf(
'Magento\Catalog\Model\Product\Option\Type\File',
\Magento\Catalog\Model\Product\Option\Type\File::class,
$fileObject->copyQuoteToOrder()
);
}
Expand Down
23 changes: 23 additions & 0 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1332,4 +1332,27 @@ public function testGetTypeId()
$this->model->setTypeId('typeId');
$this->model->getTypeInstance();
}

public function testGetOptionById()
{
$optionId = 100;
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
$this->model->setOptions([$optionMock]);
$optionMock->expects($this->once())->method('getId')->willReturn($optionId);
$this->assertEquals($optionMock, $this->model->getOptionById($optionId));
}

public function testGetOptionByIdWithWrongOptionId()
{
$optionId = 100;
$optionMock = $this->getMock(\Magento\Catalog\Model\Product\Option::class, [], [], '', false);
$this->model->setOptions([$optionMock]);
$optionMock->expects($this->once())->method('getId')->willReturn(200);
$this->assertNull($this->model->getOptionById($optionId));
}

public function testGetOptionByIdForProductWithoutOptions()
{
$this->assertNull($this->model->getOptionById(100));
}
}
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
</type>
</config>
3 changes: 0 additions & 3 deletions app/code/Magento/Catalog/etc/frontend/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
<argument name="fetchStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Category\Collection\FetchStrategy</argument>
</arguments>
</type>
<type name="Magento\Quote\Model\Quote\Item\ToOrderItem">
<plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
</type>
<type name="Magento\Catalog\Model\Indexer\AbstractFlatState">
<arguments>
<argument name="isAvailable" xsi:type="boolean">true</argument>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,17 @@ public function create(array $data = [])
$indexer = $this->_objectManager->create($this->handlers[$currentHandler], $data);

if (!$indexer instanceof IndexerInterface) {
throw new \InvalidArgumentException($indexer . ' doesn\'t implement \Magento\Framework\IndexerInterface');
throw new \InvalidArgumentException(
$currentHandler . ' indexer handler doesn\'t implement ' . IndexerInterface::class
);
}

if ($indexer && !$indexer->isAvailable()) {
throw new \LogicException(
'Indexer handler is not available: ' . $indexer
'Indexer handler is not available: ' . $currentHandler
);
}

return $indexer;
}
}
Loading

0 comments on commit 8714292

Please sign in to comment.