Skip to content

Commit 11429cd

Browse files
author
Magento CICD
authored
merge magento/develop into magento-eqp/MM-2551-EQP-Sniffs-To-Magento
2 parents 6d728a5 + 79e788c commit 11429cd

File tree

6 files changed

+266
-22
lines changed

6 files changed

+266
-22
lines changed

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,13 @@ public function getAdditionalData(array $excludeAttr = [])
8383
if ($attribute->getIsVisibleOnFront() && !in_array($attribute->getAttributeCode(), $excludeAttr)) {
8484
$value = $attribute->getFrontend()->getValue($product);
8585

86-
if (!$product->hasData($attribute->getAttributeCode())) {
87-
$value = __('N/A');
88-
} elseif ((string)$value == '') {
89-
$value = __('No');
86+
if ($value instanceof Phrase) {
87+
$value = (string)$value;
9088
} elseif ($attribute->getFrontendInput() == 'price' && is_string($value)) {
9189
$value = $this->priceCurrency->convertAndFormat($value);
9290
}
9391

94-
if ($value instanceof Phrase || (is_string($value) && strlen($value))) {
92+
if (is_string($value) && strlen($value)) {
9593
$data[$attribute->getAttributeCode()] = [
9694
'label' => __($attribute->getStoreLabel()),
9795
'value' => $value,
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Block\Product\View;
8+
9+
use \PHPUnit\Framework\TestCase;
10+
use \Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
11+
use \Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend;
12+
use \Magento\Catalog\Model\Product;
13+
use \Magento\Framework\View\Element\Template\Context;
14+
use \Magento\Framework\Registry;
15+
use \Magento\Framework\Pricing\PriceCurrencyInterface;
16+
use \Magento\Catalog\Block\Product\View\Attributes as AttributesBlock;
17+
18+
/**
19+
* Test class for \Magento\Catalog\Block\Product\View\Attributes
20+
*
21+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
22+
*/
23+
class AttributesTest extends TestCase
24+
{
25+
/**
26+
* @var \Magento\Framework\Phrase
27+
*/
28+
private $phrase;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\AbstractAttribute
32+
*/
33+
private $attribute;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Eav\Model\Entity\Attribute\Frontend\AbstractFrontend
37+
*/
38+
private $frontendAttribute;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Catalog\Model\Product
42+
*/
43+
private $product;
44+
45+
/**
46+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\View\Element\Template\Context
47+
*/
48+
private $context;
49+
50+
/**
51+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Registry
52+
*/
53+
private $registry;
54+
55+
/**
56+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Pricing\PriceCurrencyInterface
57+
*/
58+
private $priceCurrencyInterface;
59+
60+
/**
61+
* @var \Magento\Catalog\Block\Product\View\Attributes
62+
*/
63+
private $attributesBlock;
64+
65+
protected function setUp()
66+
{
67+
$this->attribute = $this
68+
->getMockBuilder(AbstractAttribute::class)
69+
->disableOriginalConstructor()
70+
->getMock();
71+
$this->attribute
72+
->expects($this->any())
73+
->method('getIsVisibleOnFront')
74+
->willReturn(true);
75+
$this->attribute
76+
->expects($this->any())
77+
->method('getAttributeCode')
78+
->willReturn('phrase');
79+
$this->frontendAttribute = $this
80+
->getMockBuilder(AbstractFrontend::class)
81+
->disableOriginalConstructor()
82+
->getMock();
83+
$this->attribute
84+
->expects($this->any())
85+
->method('getFrontendInput')
86+
->willReturn('phrase');
87+
$this->attribute
88+
->expects($this->any())
89+
->method('getFrontend')
90+
->willReturn($this->frontendAttribute);
91+
$this->product = $this
92+
->getMockBuilder(Product::class)
93+
->disableOriginalConstructor()
94+
->getMock();
95+
$this->product
96+
->expects($this->any())
97+
->method('getAttributes')
98+
->willReturn([$this->attribute]);
99+
$this->product
100+
->expects($this->any())
101+
->method('hasData')
102+
->willReturn(true);
103+
$this->context = $this
104+
->getMockBuilder(Context::class)
105+
->disableOriginalConstructor()
106+
->getMock();
107+
$this->registry = $this
108+
->getMockBuilder(Registry::class)
109+
->disableOriginalConstructor()
110+
->getMock();
111+
$this->registry
112+
->expects($this->any())
113+
->method('registry')
114+
->willReturn($this->product);
115+
$this->priceCurrencyInterface = $this
116+
->getMockBuilder(PriceCurrencyInterface::class)
117+
->disableOriginalConstructor()
118+
->getMock();
119+
$this->attributesBlock = new AttributesBlock(
120+
$this->context,
121+
$this->registry,
122+
$this->priceCurrencyInterface
123+
);
124+
}
125+
126+
/**
127+
* @return void
128+
*/
129+
public function testGetAttributeNoValue()
130+
{
131+
$this->phrase = '';
132+
$this->frontendAttribute
133+
->expects($this->any())
134+
->method('getValue')
135+
->willReturn($this->phrase);
136+
$attributes = $this->attributesBlock->getAdditionalData();
137+
$this->assertTrue(empty($attributes['phrase']));
138+
}
139+
140+
/**
141+
* @return void
142+
*/
143+
public function testGetAttributeHasValue()
144+
{
145+
$this->phrase = __('Yes');
146+
$this->frontendAttribute
147+
->expects($this->any())
148+
->method('getValue')
149+
->willReturn($this->phrase);
150+
$attributes = $this->attributesBlock->getAdditionalData();
151+
$this->assertNotTrue(empty($attributes['phrase']));
152+
$this->assertNotTrue(empty($attributes['phrase']['value']));
153+
$this->assertEquals('Yes', $attributes['phrase']['value']);
154+
}
155+
}

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();

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

Lines changed: 43 additions & 0 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::class)
@@ -100,6 +115,16 @@ protected function setUp()
100115
->setMethods(['create'])
101116
->getMock();
102117

118+
$this->cookieManager = $this->getMockBuilder(\Magento\Framework\Stdlib\CookieManagerInterface::class)
119+
->setMethods(['getCookie', 'deleteCookie'])
120+
->getMockForAbstractClass();
121+
$this->cookieMetadataFactory = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory::class)
122+
->disableOriginalConstructor()
123+
->getMock();
124+
$this->cookieMetadata = $this->getMockBuilder(\Magento\Framework\Stdlib\Cookie\CookieMetadata::class)
125+
->disableOriginalConstructor()
126+
->getMock();
127+
103128
$this->resultRaw = $this->getMockBuilder(\Magento\Framework\Controller\Result\Raw::class)
104129
->disableOriginalConstructor()
105130
->getMock();
@@ -128,6 +153,8 @@ protected function setUp()
128153
'resultJsonFactory' => $this->resultJsonFactory,
129154
'objectManager' => $this->objectManager,
130155
'customerAccountManagement' => $this->customerAccountManagementMock,
156+
'cookieManager' => $this->cookieManager,
157+
'cookieMetadataFactory' => $this->cookieMetadataFactory
131158
]
132159
);
133160
}
@@ -179,6 +206,22 @@ public function testLogin()
179206
$this->object->setAccountRedirect($redirectMock);
180207
$redirectMock->expects($this->once())->method('getRedirectCookie')->willReturn('some_url1');
181208

209+
$this->cookieManager->expects($this->once())
210+
->method('getCookie')
211+
->with('mage-cache-sessid')
212+
->willReturn(true);
213+
$this->cookieMetadataFactory->expects($this->once())
214+
->method('createCookieMetadata')
215+
->willReturn($this->cookieMetadata);
216+
$this->cookieMetadata->expects($this->once())
217+
->method('setPath')
218+
->with('/')
219+
->willReturnSelf();
220+
$this->cookieManager->expects($this->once())
221+
->method('deleteCookie')
222+
->with('mage-cache-sessid', $this->cookieMetadata)
223+
->willReturnSelf();
224+
182225
$scopeConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
183226
$this->object->setScopeConfig($scopeConfigMock);
184227
$scopeConfigMock->expects($this->once())->method('getValue')

app/code/Magento/Newsletter/Model/Subscriber.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,8 @@ public function confirm($code)
621621
$this->setStatus(self::STATUS_SUBSCRIBED)
622622
->setStatusChanged(true)
623623
->save();
624+
625+
$this->sendConfirmationSuccessEmail();
624626
return true;
625627
}
626628

0 commit comments

Comments
 (0)