Skip to content

Commit

Permalink
Merge pull request #478 from magento-mpi/MPI-regression
Browse files Browse the repository at this point in the history
[MPI] Bugfixes
  • Loading branch information
Yushkin, Dmytro committed Mar 25, 2016
2 parents 137733b + 0e31742 commit e03c5ae
Show file tree
Hide file tree
Showing 44 changed files with 523 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,8 @@ class AdvancedPricing extends \Magento\CatalogImportExport\Model\Export\Product
* @param \Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
* @param \Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
* @param ImportProduct\StoreResolver $storeResolver
* @param \Magento\Customer\Api\GroupRepositoryInterface $groupRepository
* @param \Magento\Framework\Model\Entity\MetadataPool $metadataPool
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
Expand All @@ -119,7 +117,6 @@ public function __construct(
\Magento\CatalogImportExport\Model\Export\Product\Type\Factory $_typeFactory,
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider,
\Magento\CatalogImportExport\Model\Export\RowCustomizerInterface $rowCustomizer,
\Magento\Framework\Model\Entity\MetadataPool $metadataPool,
\Magento\CatalogImportExport\Model\Import\Product\StoreResolver $storeResolver,
\Magento\Customer\Api\GroupRepositoryInterface $groupRepository
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,6 @@ class AdvancedPricingTest extends \PHPUnit_Framework_TestCase
*/
protected $groupRepository;

/**
* @var \Magento\Framework\Model\Entity\MetadataPool|\PHPUnit_Framework_MockObject_MockObject
*/
protected $metadataPool;

/**
* @var \Magento\ImportExport\Model\Export\Adapter\AbstractAdapter| \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -290,13 +285,6 @@ protected function setUp()
'',
false
);
$this->metadataPool = $this->getMock(
'\Magento\Framework\Model\Entity\MetadataPool',
[],
[],
'',
false
);
$this->writer = $this->getMock(
'Magento\ImportExport\Model\Export\Adapter\AbstractAdapter',
[
Expand Down Expand Up @@ -355,7 +343,6 @@ protected function setUp()
$this->typeFactory,
$this->linkTypeProvider,
$this->rowCustomizer,
$this->metadataPool,
$this->storeResolver,
$this->groupRepository
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ protected function placeCheckoutOrder()
);
} catch (\Exception $exception) {
$result->setData('error', true);
$result->setData('error_messages', __('Cannot place order.'));
$result->setData('error_messages', __('Unable to place order. Please try again later.'));
}
if ($response instanceof Http) {
$response->representJson($this->jsonHelper->jsonEncode($result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,20 @@
*/
namespace Magento\Authorizenet\Controller\Directpost\Payment;

use Magento\Framework\App\ObjectManager;
use Magento\Payment\Block\Transparent\Iframe;
use Magento\Framework\Escaper;

/**
* Class Redirect
*/
class Redirect extends \Magento\Authorizenet\Controller\Directpost\Payment
{
/**
* @var Escaper
*/
private $escaper;

/**
* Retrieve params and put javascript into iframe
*
Expand All @@ -19,7 +29,7 @@ public function execute()
{
$helper = $this->dataFactory->create('frontend');

$redirectParams = $this->getRequest()->getParams();
$redirectParams = $this->filterData($this->getRequest()->getParams());
$params = [];
if (!empty($redirectParams['success'])
&& isset($redirectParams['x_invoice_num'])
Expand All @@ -44,4 +54,30 @@ public function execute()
$this->_view->addPageLayoutHandles();
$this->_view->loadLayout(false)->renderLayout();
}

/**
* Escape xss in request data
* @param array $data
* @return array
*/
private function filterData(array $data)
{
$self = $this;
array_walk($data, function (&$item) use ($self) {
$item = $self->getEscaper()->escapeXssInUrl($item);
});
return $data;
}

/**
* Get Escaper instance
* @return Escaper
*/
private function getEscaper()
{
if (!$this->escaper) {
$this->escaper = ObjectManager::getInstance()->get(Escaper::class);
}
return $this->escaper;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ public function textExecuteFailedPlaceOrderDataProvider()
{
$objectFailed = new \Magento\Framework\DataObject();
$objectFailed->setData('error', true);
$objectFailed->setData('error_messages', __('Cannot place order.'));
$objectFailed->setData('error_messages', __('Unable to place order. Please try again later.'));

return [
[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Authorizenet\Test\Unit\Controller\Directpost\Payment;

use Magento\Authorizenet\Controller\Directpost\Payment\Redirect;
use Magento\Framework\App\RequestInterface;
use Magento\Framework\App\ViewInterface;
use Magento\Framework\Escaper;
use Magento\Framework\Registry;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Payment\Block\Transparent\Iframe;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* Class RedirectTest
*/
class RedirectTest extends \PHPUnit_Framework_TestCase
{
/**
* @var RequestInterface|MockObject
*/
private $request;

/**
* @var ViewInterface|MockObject
*/
private $view;

/**
* @var Registry|MockObject
*/
private $coreRegistry;

/**
* @var Escaper|MockObject
*/
private $escaper;

/**
* @var Redirect
*/
private $controller;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->request = static::getMockForAbstractClass(RequestInterface::class);

$this->view = static::getMockForAbstractClass(ViewInterface::class);

$this->coreRegistry = static::getMockBuilder(Registry::class)
->disableOriginalConstructor()
->setMethods(['register'])
->getMock();

$this->escaper = static::getMockBuilder(Escaper::class)
->disableOriginalConstructor()
->setMethods(['escapeXssInUrl'])
->getMock();

$this->controller = $objectManager->getObject(Redirect::class, [
'request' => $this->request,
'view' => $this->view,
'coreRegistry' => $this->coreRegistry
]);

$refClass = new \ReflectionClass(Redirect::class);
$refProperty = $refClass->getProperty('escaper');
$refProperty->setAccessible(true);
$refProperty->setValue($this->controller, $this->escaper);
}

/**
* @covers \Magento\Authorizenet\Controller\Directpost\Payment\Redirect::execute
*/
public function testExecute()
{
$url = 'http://test.com/redirect?=test';
$params = [
'order_success' => $url
];
$this->request->expects(static::once())
->method('getParams')
->willReturn($params);

$this->escaper->expects(static::once())
->method('escapeXssInUrl')
->with($url)
->willReturn($url);

$this->coreRegistry->expects(static::once())
->method('register')
->with(Iframe::REGISTRY_KEY, $params);

$this->view->expects(static::once())
->method('addPageLayoutHandles');
$this->view->expects(static::once())
->method('loadLayout')
->with(false)
->willReturnSelf();
$this->view->expects(static::once())
->method('renderLayout');

$this->controller->execute();
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Authorizenet/i18n/en_US.csv
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"Order saving error: %1","Order saving error: %1"
"Please choose a payment method.","Please choose a payment method."
"We can\'t process your order right now. Please try again later.","We can\'t process your order right now. Please try again later."
"Cannot place order.","Cannot place order."
"Unable to place order. Please try again later.","Unable to place order. Please try again later."
"Credit Card: xxxx-%1","Credit Card: xxxx-%1"
"amount %1","amount %1"
failed.,failed.
Expand Down
32 changes: 16 additions & 16 deletions app/code/Magento/Braintree/view/adminhtml/web/js/vault.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
define([
'jquery',
'uiComponent',
'Magento_Ui/js/modal/alert'
], function ($, Class, alert) {
'Magento_Ui/js/modal/alert',
'Magento_Checkout/js/model/full-screen-loader'
], function ($, Class, alert, fullScreenLoader) {
'use strict';

return Class.extend({
Expand Down Expand Up @@ -83,7 +84,7 @@ define([
submitOrder: function () {
this.$selector.validate().form();
this.$selector.trigger('afterValidate.beforeSubmit');
$('body').trigger('processStop');
fullScreenLoader.stopLoader();

// validate parent form
if (this.$selector.validate().errorList.length) {
Expand All @@ -105,21 +106,20 @@ define([
getPaymentMethodNonce: function () {
var self = this;

$('body').trigger('processStart');
fullScreenLoader.startLoader();

$.get(self.nonceUrl, {
'public_hash': self.publicHash
})
.done(function (response) {
$('body').trigger('processStop');
self.setPaymentDetails(response.paymentMethodNonce);
self.placeOrder();
})
.fail(function (response) {
var failed = JSON.parse(response.responseText);

$('body').trigger('processStop');
self.error(failed.message);
});
}).done(function (response) {
self.setPaymentDetails(response.paymentMethodNonce);
self.placeOrder();
}).fail(function (response) {
var failed = JSON.parse(response.responseText);

self.error(failed.message);
}).always(function () {
fullScreenLoader.stopLoader();
});
},

/**
Expand Down
26 changes: 18 additions & 8 deletions app/code/Magento/Bundle/Model/LinkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Framework\Exception\InputException;
use Magento\Framework\Model\Entity\MetadataPool;
Expand Down Expand Up @@ -50,7 +51,7 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
/**
* @var MetadataPool
*/
protected $metadataPool;
private $metadataPool;

/**
* @param ProductRepositoryInterface $productRepository
Expand All @@ -60,7 +61,6 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
* @param \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
* @param MetadataPool $metadataPool
*/
public function __construct(
ProductRepositoryInterface $productRepository,
Expand All @@ -69,8 +69,7 @@ public function __construct(
\Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory,
\Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
MetadataPool $metadataPool
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
) {
$this->productRepository = $productRepository;
$this->linkFactory = $linkFactory;
Expand All @@ -79,7 +78,6 @@ public function __construct(
$this->optionCollection = $optionCollection;
$this->storeManager = $storeManager;
$this->dataObjectHelper = $dataObjectHelper;
$this->metadataPool = $metadataPool;
}

/**
Expand Down Expand Up @@ -147,7 +145,7 @@ public function saveChild(
if (!$selectionModel->getId()) {
throw new InputException(__('Can not find product link with id "%1"', [$linkedProduct->getId()]));
}
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$selectionModel = $this->mapProductLinkToSelectionModel(
$selectionModel,
$linkedProduct,
Expand Down Expand Up @@ -231,7 +229,7 @@ public function addChild(
);
}

$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
$resource = $this->bundleFactory->create();
$selections = $resource->getSelectionsData($product->getData($linkField));
Expand Down Expand Up @@ -303,7 +301,7 @@ public function removeChild($sku, $optionId, $childSku)
__('Requested bundle option product doesn\'t exist')
);
}
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
$resource = $this->bundleFactory->create();
$resource->dropAllUnneededSelections($product->getData($linkField), $excludeSelectionIds);
Expand Down Expand Up @@ -366,4 +364,16 @@ private function getOptions(\Magento\Catalog\Api\Data\ProductInterface $product)
$options = $optionCollection->appendSelections($selectionCollection);
return $options;
}

/**
* Get MetadataPool instance
* @return MetadataPool
*/
private function getMetadataPool()
{
if (!$this->metadataPool) {
$this->metadataPool = ObjectManager::getInstance()->get(MetadataPool::class);
}
return $this->metadataPool;
}
}
Loading

0 comments on commit e03c5ae

Please sign in to comment.