Skip to content

Commit 6829b27

Browse files
committed
Merge remote-tracking branch 'origin/2.1-develop' into MAGETWO-84432-magento-magento2-12368
* origin/2.1-develop: Duplicate array key MAGETWO-84822: Mock ObjectManager for each test to keep from failing when run individually but not as part of suite MAGETWO-69577: [Backport for 2.1.x] Auto-generated classes behave differently in unit tests and application Fixed static tests failure Fixed static tests and backported unit test Generate new FormKey and replace for oldRequestParams MAGETWO-69213: [Backport] - Braintree saved credit card error for reorder between $2001-$3000 does not display error to customer - for 2.1 #10765 add confirmation and lock_expires labels to customer grid CSV export # This is a combination of 3 commits. # This is the 1st commit message: #10765 add confirmation and lock_expires labels to customer grid CSV export MAGETWO-69213: [Backport] - Braintree saved credit card error for reorder between $2001-$3000 does not display error to customer - for 2.1 Update Ajax LoginTest Clear `mage-cache-sessid` on Ajax Login 9768: Admin dashboard Most Viewed Products Tab only gives default attribute set's products(backport for 2.1) 10210: Transport variable can not be altered in email_invoice_set_template_vars_before Event (backport MAGETWO-69482 to 2.1) [Backport 2.1] add swatch option: prevent loosing data and default value if data is not populated via adminhtml Fix to dont show current date in empty date attr backport 2.1
2 parents 0081481 + 6415e3d commit 6829b27

File tree

61 files changed

+1582
-467
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1582
-467
lines changed

app/autoload.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,3 @@
3535
}
3636

3737
AutoloaderRegistry::registerAutoloader(new ClassLoaderWrapper($composerAutoloader));
38-
39-
// Sets default autoload mappings, may be overridden in Bootstrap::create
40-
\Magento\Framework\App\Bootstrap::populateAutoloader(BP, []);

app/bootstrap.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@
2828
}
2929

3030
require_once __DIR__ . '/autoload.php';
31+
// Sets default autoload mappings, may be overridden in Bootstrap::create
32+
\Magento\Framework\App\Bootstrap::populateAutoloader(BP, []);
33+
3134
require_once BP . '/app/functions.php';
3235

3336
/* Custom umask value may be provided in optional mage_umask file in root */

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

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ define(
3636
braintreeDeviceData: null,
3737
paymentMethodNonce: null,
3838
lastBillingAddress: null,
39+
ccCode: null,
40+
ccMessageContainer: null,
3941
validatorManager: validatorManager,
4042
code: 'braintree',
4143

@@ -138,9 +140,39 @@ define(
138140
return;
139141
}
140142

143+
this.restoreMessageContainer();
144+
this.restoreCode();
145+
146+
/**
147+
* Define onReady callback
148+
*/
149+
braintree.onReady = function () {};
141150
this.initBraintree();
142151
},
143152

153+
/**
154+
* Restore original message container for cc-form component
155+
*/
156+
restoreMessageContainer: function () {
157+
this.messageContainer = this.ccMessageContainer;
158+
},
159+
160+
/**
161+
* Restore original code for cc-form component
162+
*/
163+
restoreCode: function () {
164+
this.code = this.ccCode;
165+
},
166+
167+
/** @inheritdoc */
168+
initChildren: function () {
169+
this._super();
170+
this.ccMessageContainer = this.messageContainer;
171+
this.ccCode = this.code;
172+
173+
return this;
174+
},
175+
144176
/**
145177
* Init config
146178
*/

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ define([
5252
var self = this;
5353

5454
/**
55-
* Define already callback
55+
* Define onReady callback
5656
*/
5757
Braintree.onReady = function () {
5858
self.getPaymentMethodNonce();
@@ -78,6 +78,7 @@ define([
7878
formComponent.setPaymentMethodNonce(response.paymentMethodNonce);
7979
formComponent.additionalData['public_hash'] = self.publicHash;
8080
formComponent.code = self.code;
81+
formComponent.messageContainer = self.messageContainer;
8182
formComponent.placeOrder();
8283
});
8384
})

app/code/Magento/Bundle/Block/Adminhtml/Catalog/Product/Edit/Tab/Attributes/Extend.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ public function getExtendedElement($switchAttributeCode)
143143
[
144144
'name' => "product[{$switchAttributeCode}]",
145145
'values' => $this->getOptions(),
146-
'value' => $switchAttributeCode,
147146
'class' => 'required-entry next-toinput',
148147
'no_span' => true,
149148
'disabled' => $this->isDisabledField(),

app/code/Magento/Catalog/Block/Product/View/Attributes.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ public function getAdditionalData(array $excludeAttr = [])
8181
$attributes = $product->getAttributes();
8282
foreach ($attributes as $attribute) {
8383
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
84-
$value = $attribute->getFrontend()->getValue($product);
85-
84+
if (is_array($value = $attribute->getFrontend()->getValue($product))) {
85+
continue;
86+
}
8687
if (!$product->hasData($attribute->getAttributeCode())) {
8788
$value = __('N/A');
8889
} elseif ((string)$value == '') {

app/code/Magento/CatalogInventory/Test/Unit/Model/Plugin/AfterProductLoadTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function setUp()
5252
->with($productId)
5353
->willReturn($stockItemMock);
5454

55-
$this->productExtensionMock = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtension')
55+
$this->productExtensionMock = $this->getMockBuilder('\Magento\Catalog\Api\Data\ProductExtensionInterface')
5656
->setMethods(['setStockItem'])
5757
->getMock();
5858
$this->productExtensionMock->expects($this->once())

app/code/Magento/Customer/Controller/Ajax/Login.php

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Customer\Model\Account\Redirect as AccountRedirect;
1414
use Magento\Framework\App\Config\ScopeConfigInterface;
1515
use Magento\Framework\Exception\LocalizedException;
16+
use Magento\Framework\Stdlib\Cookie\CookieMetadataFactory;
17+
use Magento\Framework\Stdlib\CookieManagerInterface;
1618

1719
/**
1820
* Login controller
@@ -58,6 +60,16 @@ class Login extends \Magento\Framework\App\Action\Action
5860
*/
5961
protected $scopeConfig;
6062

63+
/**
64+
* @var CookieManagerInterface
65+
*/
66+
private $cookieManager;
67+
68+
/**
69+
* @var CookieMetadataFactory
70+
*/
71+
private $cookieMetadataFactory;
72+
6173
/**
6274
* Initialize Login controller
6375
*
@@ -67,21 +79,29 @@ class Login extends \Magento\Framework\App\Action\Action
6779
* @param AccountManagementInterface $customerAccountManagement
6880
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
6981
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
82+
* @param CookieManagerInterface $cookieManager
83+
* @param CookieMetadataFactory $cookieMetadataFactory
7084
*/
7185
public function __construct(
7286
\Magento\Framework\App\Action\Context $context,
7387
\Magento\Customer\Model\Session $customerSession,
7488
\Magento\Framework\Json\Helper\Data $helper,
7589
AccountManagementInterface $customerAccountManagement,
7690
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
77-
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory
91+
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
92+
CookieManagerInterface $cookieManager = null,
93+
CookieMetadataFactory $cookieMetadataFactory = null
7894
) {
7995
parent::__construct($context);
8096
$this->customerSession = $customerSession;
8197
$this->helper = $helper;
8298
$this->customerAccountManagement = $customerAccountManagement;
8399
$this->resultJsonFactory = $resultJsonFactory;
84100
$this->resultRawFactory = $resultRawFactory;
101+
$this->cookieManager = $cookieManager ?:
102+
ObjectManager::getInstance()->get(CookieManagerInterface::class);
103+
$this->cookieMetadataFactory = $cookieMetadataFactory ?:
104+
ObjectManager::getInstance()->get(CookieMetadataFactory::class);
85105
}
86106

87107
/**
@@ -169,6 +189,11 @@ public function execute()
169189
$this->customerSession->setCustomerDataAsLoggedIn($customer);
170190
$this->customerSession->regenerateId();
171191
$redirectRoute = $this->getAccountRedirect()->getRedirectCookie();
192+
if ($this->cookieManager->getCookie('mage-cache-sessid')) {
193+
$metadata = $this->cookieMetadataFactory->createCookieMetadata();
194+
$metadata->setPath('/');
195+
$this->cookieManager->deleteCookie('mage-cache-sessid', $metadata);
196+
}
172197
if (!$this->getScopeConfig()->getValue('customer/startup/redirect_dashboard') && $redirectRoute) {
173198
$response['redirectUrl'] = $this->_redirect->success($redirectRoute);
174199
$this->getAccountRedirect()->clearRedirectCookie();
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Model\Plugin;
7+
8+
use Magento\Customer\Model\Session;
9+
use Magento\Framework\Data\Form\FormKey as DataFormKey;
10+
use \Magento\Framework\Event\Observer;
11+
use Magento\PageCache\Observer\FlushFormKey;
12+
13+
class CustomerFlushFormKey
14+
{
15+
/**
16+
* @var Session
17+
*/
18+
private $session;
19+
20+
/**
21+
* @var DataFormKey
22+
*/
23+
private $dataFormKey;
24+
25+
/**
26+
* Initialize dependencies.
27+
*
28+
* @param Session $session
29+
* @param DataFormKey $dataFormKey
30+
*/
31+
public function __construct(Session $session, DataFormKey $dataFormKey)
32+
{
33+
$this->session = $session;
34+
$this->dataFormKey = $dataFormKey;
35+
}
36+
37+
/**
38+
* @param FlushFormKey $subject
39+
* @param callable $proceed
40+
* @param Observer $observer
41+
* @return void
42+
*
43+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
44+
*/
45+
public function aroundExecute(FlushFormKey $subject, callable $proceed, Observer $observer)
46+
{
47+
$currentFormKey = $this->dataFormKey->getFormKey();
48+
$proceed($observer);
49+
$beforeParams = $this->session->getBeforeRequestParams();
50+
if ($beforeParams['form_key'] == $currentFormKey) {
51+
$beforeParams['form_key'] = $this->dataFormKey->getFormKey();
52+
$this->session->setBeforeRequestParams($beforeParams);
53+
}
54+
}
55+
}

app/code/Magento/Customer/Test/Unit/Controller/Ajax/LoginTest.php

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,21 @@ class LoginTest extends \PHPUnit_Framework_TestCase
7373
*/
7474
protected $redirectMock;
7575

76+
/**
77+
* @var \Magento\Framework\Stdlib\CookieManagerInterface| \PHPUnit_Framework_MockObject_MockObject
78+
*/
79+
private $cookieManager;
80+
81+
/**
82+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory| \PHPUnit_Framework_MockObject_MockObject
83+
*/
84+
private $cookieMetadataFactory;
85+
86+
/**
87+
* @var \Magento\Framework\Stdlib\Cookie\CookieMetadata| \PHPUnit_Framework_MockObject_MockObject
88+
*/
89+
private $cookieMetadata;
90+
7691
protected function setUp()
7792
{
7893
$this->request = $this->getMockBuilder('Magento\Framework\App\Request\Http')
@@ -105,14 +120,13 @@ protected function setUp()
105120
'',
106121
false
107122
);
108-
$this->customerAccountManagementMock =
109-
$this->getMock(
110-
'\Magento\Customer\Model\AccountManagement',
111-
['authenticate'],
112-
[],
113-
'',
114-
false
115-
);
123+
$this->customerAccountManagementMock = $this->getMock(
124+
'\Magento\Customer\Model\AccountManagement',
125+
['authenticate'],
126+
[],
127+
'',
128+
false
129+
);
116130

117131
$this->jsonHelperMock = $this->getMock(
118132
'\Magento\Framework\Json\Helper\Data',
@@ -130,6 +144,16 @@ protected function setUp()
130144
->setMethods(['create'])
131145
->getMock();
132146

147+
$this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\CookieManagerInterface::class)
148+
->setMethods(['getCookie', 'deleteCookie'])
149+
->getMockForAbstractClass();
150+
$this->cookieMetadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
151+
->disableOriginalConstructor()
152+
->getMock();
153+
$this->cookieMetadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
154+
->disableOriginalConstructor()
155+
->getMock();
156+
133157
$this->resultRaw = $this->getMockBuilder('Magento\Framework\Controller\Result\Raw')
134158
->disableOriginalConstructor()
135159
->getMock();
@@ -158,6 +182,8 @@ protected function setUp()
158182
'resultJsonFactory' => $this->resultJsonFactory,
159183
'objectManager' => $this->objectManager,
160184
'customerAccountManagement' => $this->customerAccountManagementMock,
185+
'cookieManager' => $this->cookieManager,
186+
'cookieMetadataFactory' => $this->cookieMetadataFactory
161187
]
162188
);
163189
}
@@ -209,6 +235,22 @@ public function testLogin()
209235
$this->object->setAccountRedirect($redirectMock);
210236
$redirectMock->expects($this->once())->method('getRedirectCookie')->willReturn('some_url1');
211237

238+
$this->cookieManager->expects($this->once())
239+
->method('getCookie')
240+
->with('mage-cache-sessid')
241+
->willReturn(true);
242+
$this->cookieMetadataFactory->expects($this->once())
243+
->method('createCookieMetadata')
244+
->willReturn($this->cookieMetadata);
245+
$this->cookieMetadata->expects($this->once())
246+
->method('setPath')
247+
->with('/')
248+
->willReturnSelf();
249+
$this->cookieManager->expects($this->once())
250+
->method('deleteCookie')
251+
->with('mage-cache-sessid', $this->cookieMetadata)
252+
->willReturnSelf();
253+
212254
$scopeConfigMock = $this->getMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
213255
$this->object->setScopeConfig($scopeConfigMock);
214256
$scopeConfigMock->expects($this->once())->method('getValue')

0 commit comments

Comments
 (0)