Skip to content

Commit ce68a6d

Browse files
committed
Merge pull request #493 from magento-south/BUGS
[SOUTH] Bugfixes
2 parents 6f5de44 + 179b774 commit ce68a6d

File tree

16 files changed

+541
-52
lines changed

16 files changed

+541
-52
lines changed

app/code/Magento/Catalog/view/adminhtml/web/js/options.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ define([
5454

5555
if (render) {
5656
this.render();
57+
this.updateItemsCountField();
5758
}
5859
},
5960
remove: function (event) {
@@ -136,10 +137,7 @@ define([
136137
}
137138
};
138139

139-
if ($('add_new_option_button')) {
140-
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true));
141-
}
142-
140+
Event.observe('add_new_option_button', 'click', attributeOption.add.bind(attributeOption, {}, true));
143141
$('manage-options-panel').on('click', '.delete-option', function (event) {
144142
attributeOption.remove(event);
145143
});

app/code/Magento/Customer/Model/AccountManagement.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -632,10 +632,10 @@ public function getConfirmationStatus($customerId)
632632
{
633633
// load customer by id
634634
$customer = $this->customerRepository->getById($customerId);
635-
if (!$customer->getConfirmation()) {
636-
return self::ACCOUNT_CONFIRMED;
637-
}
638635
if ($this->isConfirmationRequired($customer)) {
636+
if (!$customer->getConfirmation()) {
637+
return self::ACCOUNT_CONFIRMED;
638+
}
639639
return self::ACCOUNT_CONFIRMATION_REQUIRED;
640640
}
641641
return self::ACCOUNT_CONFIRMATION_NOT_REQUIRED;
@@ -1084,9 +1084,12 @@ protected function isConfirmationRequired($customer)
10841084
if ($this->canSkipConfirmation($customer)) {
10851085
return false;
10861086
}
1087-
$storeId = $customer->getStoreId() ? $customer->getStoreId() : null;
10881087

1089-
return (bool)$this->scopeConfig->getValue(self::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_STORE, $storeId);
1088+
return (bool)$this->scopeConfig->getValue(
1089+
self::XML_PATH_IS_CONFIRM,
1090+
ScopeInterface::SCOPE_WEBSITES,
1091+
$customer->getWebsiteId()
1092+
);
10901093
}
10911094

10921095
/**

app/code/Magento/Customer/Model/Customer.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Magento\Framework\Exception\InvalidEmailOrPasswordException;
1818
use Magento\Framework\Exception\AuthenticationException;
1919
use Magento\Framework\Indexer\StateInterface;
20+
use Magento\Store\Model\ScopeInterface;
2021

2122
/**
2223
* Customer model
@@ -774,12 +775,13 @@ public function isConfirmationRequired()
774775
if ($this->canSkipConfirmation()) {
775776
return false;
776777
}
777-
$storeId = $this->getStoreId() ? $this->getStoreId() : null;
778+
779+
$websiteId = $this->getWebsiteId() ? $this->getWebsiteId() : null;
778780

779781
return (bool)$this->_scopeConfig->getValue(
780782
self::XML_PATH_IS_CONFIRM,
781-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
782-
$storeId
783+
ScopeInterface::SCOPE_WEBSITES,
784+
$websiteId
783785
);
784786
}
785787

@@ -823,13 +825,13 @@ protected function _sendEmailTemplate($template, $sender, $templateParams = [],
823825
{
824826
/** @var \Magento\Framework\Mail\TransportInterface $transport */
825827
$transport = $this->_transportBuilder->setTemplateIdentifier(
826-
$this->_scopeConfig->getValue($template, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
828+
$this->_scopeConfig->getValue($template, ScopeInterface::SCOPE_STORE, $storeId)
827829
)->setTemplateOptions(
828830
['area' => \Magento\Framework\App\Area::AREA_FRONTEND, 'store' => $storeId]
829831
)->setTemplateVars(
830832
$templateParams
831833
)->setFrom(
832-
$this->_scopeConfig->getValue($sender, \Magento\Store\Model\ScopeInterface::SCOPE_STORE, $storeId)
834+
$this->_scopeConfig->getValue($sender, ScopeInterface::SCOPE_STORE, $storeId)
833835
)->addTo(
834836
$this->getEmail(),
835837
$this->getName()
@@ -872,7 +874,7 @@ public function getGroupId()
872874
$storeId = $this->getStoreId() ? $this->getStoreId() : $this->_storeManager->getStore()->getId();
873875
$groupId = $this->_scopeConfig->getValue(
874876
GroupManagement::XML_PATH_DEFAULT_ID,
875-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE,
877+
ScopeInterface::SCOPE_STORE,
876878
$storeId
877879
);
878880
$this->setData('group_id', $groupId);

app/code/Magento/Customer/Test/Unit/Model/AccountManagementTest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,4 +1464,69 @@ public function testAuthenticate()
14641464

14651465
$this->assertEquals($customerData, $this->accountManagement->authenticate($username, $password));
14661466
}
1467+
1468+
/**
1469+
* @param string|null $skipConfirmationIfEmail
1470+
* @param int $isConfirmationRequired
1471+
* @param string|null $confirmation
1472+
* @param string $expected
1473+
* @dataProvider dataProviderGetConfirmationStatus
1474+
*/
1475+
public function testGetConfirmationStatus(
1476+
$skipConfirmationIfEmail,
1477+
$isConfirmationRequired,
1478+
$confirmation,
1479+
$expected
1480+
) {
1481+
$websiteId = 1;
1482+
$customerId = 1;
1483+
$customerEmail = 'test1@example.com';
1484+
1485+
$customerMock = $this->getMockBuilder('Magento\Customer\Api\Data\CustomerInterface')
1486+
->disableOriginalConstructor()
1487+
->getMock();
1488+
$customerMock->expects($this->once())
1489+
->method('getId')
1490+
->willReturn($customerId);
1491+
$customerMock->expects($this->any())
1492+
->method('getConfirmation')
1493+
->willReturn($confirmation);
1494+
$customerMock->expects($this->any())
1495+
->method('getEmail')
1496+
->willReturn($customerEmail);
1497+
$customerMock->expects($this->any())
1498+
->method('getWebsiteId')
1499+
->willReturn($websiteId);
1500+
1501+
$this->registry->expects($this->once())
1502+
->method('registry')
1503+
->with('skip_confirmation_if_email')
1504+
->willReturn($skipConfirmationIfEmail);
1505+
1506+
$this->scopeConfig->expects($this->any())
1507+
->method('getValue')
1508+
->with(AccountManagement::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId)
1509+
->willReturn($isConfirmationRequired);
1510+
1511+
$this->customerRepository->expects($this->once())
1512+
->method('getById')
1513+
->with($customerId)
1514+
->willReturn($customerMock);
1515+
1516+
$this->assertEquals($expected, $this->accountManagement->getConfirmationStatus($customerId));
1517+
}
1518+
1519+
/**
1520+
* @return array
1521+
*/
1522+
public function dataProviderGetConfirmationStatus()
1523+
{
1524+
return [
1525+
[null, 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED],
1526+
['test1@example.com', 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED],
1527+
['test2@example.com', 0, null, AccountManagement::ACCOUNT_CONFIRMATION_NOT_REQUIRED],
1528+
['test2@example.com', 1, null, AccountManagement::ACCOUNT_CONFIRMED],
1529+
['test2@example.com', 1, 'test', AccountManagement::ACCOUNT_CONFIRMATION_REQUIRED],
1530+
];
1531+
}
14671532
}

app/code/Magento/Customer/Test/Unit/Model/CustomerTest.php

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@
1111
*/
1212
namespace Magento\Customer\Test\Unit\Model;
1313

14+
use Magento\Customer\Model\Customer;
15+
use Magento\Store\Model\ScopeInterface;
16+
1417
/**
1518
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1619
*/
1720
class CustomerTest extends \PHPUnit_Framework_TestCase
1821
{
19-
/** @var \Magento\Customer\Model\Customer */
22+
/** @var Customer */
2023
protected $_model;
2124

2225
/** @var \Magento\Store\Model\Website|\PHPUnit_Framework_MockObject_MockObject */
@@ -264,4 +267,51 @@ public function isCustomerLockedDataProvider()
264267
['lockExpirationDate' => date("F j, Y", strtotime('+1 days')), 'expectedResult' => true]
265268
];
266269
}
270+
271+
/**
272+
* @param int $customerId
273+
* @param int $websiteId
274+
* @param string|null $skipConfirmationIfEmail
275+
* @param bool $expected
276+
* @dataProvider dataProviderIsConfirmationRequired
277+
*/
278+
public function testIsConfirmationRequired(
279+
$customerId,
280+
$websiteId,
281+
$skipConfirmationIfEmail,
282+
$expected
283+
) {
284+
$customerEmail = 'test1@example.com';
285+
286+
$this->registryMock->expects($this->any())
287+
->method('registry')
288+
->with('skip_confirmation_if_email')
289+
->willReturn($skipConfirmationIfEmail);
290+
291+
$this->_scopeConfigMock->expects($this->any())
292+
->method('getValue')
293+
->with(Customer::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId)
294+
->willReturn($expected);
295+
296+
$this->_model->setData('id', $customerId);
297+
$this->_model->setData('website_id', $websiteId);
298+
$this->_model->setData('email', $customerEmail);
299+
300+
$this->assertEquals($expected, $this->_model->isConfirmationRequired());
301+
}
302+
303+
/**
304+
* @return array
305+
*/
306+
public function dataProviderIsConfirmationRequired()
307+
{
308+
return [
309+
[null, null, null, false],
310+
[1, 1, null, false],
311+
[1, 1, 'test1@example.com', false],
312+
[1, 1, 'test2@example.com', true],
313+
[1, 0, 'test2@example.com', true],
314+
[1, null, 'test2@example.com', true],
315+
];
316+
}
267317
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Ui\Component\Listing\Column;
7+
8+
use Magento\Customer\Model\AccountManagement;
9+
use Magento\Customer\Ui\Component\Listing\Column\Confirmation;
10+
use Magento\Framework\App\Config\ScopeConfigInterface;
11+
use Magento\Framework\View\Element\UiComponent\ContextInterface;
12+
use Magento\Framework\View\Element\UiComponent\Processor;
13+
use Magento\Framework\View\Element\UiComponentFactory;
14+
use Magento\Store\Model\ScopeInterface;
15+
16+
class ConfirmationTest extends \PHPUnit_Framework_TestCase
17+
{
18+
/**
19+
* @var Confirmation
20+
*/
21+
protected $confirmation;
22+
23+
/**
24+
* @var ContextInterface|\PHPUnit_Framework_MockObject_MockObject
25+
*/
26+
protected $context;
27+
28+
/**
29+
* @var UiComponentFactory|\PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
protected $uiComponentFactory;
32+
33+
/**
34+
* @var ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
35+
*/
36+
protected $scopeConfig;
37+
38+
/**
39+
* @var Processor|\PHPUnit_Framework_MockObject_MockObject
40+
*/
41+
protected $processor;
42+
43+
public function setup()
44+
{
45+
$this->processor = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\Processor')
46+
->disableOriginalConstructor()
47+
->getMock();
48+
49+
$this->context = $this->getMockBuilder('Magento\Framework\View\Element\UiComponent\ContextInterface')
50+
->getMockForAbstractClass();
51+
52+
$this->context->expects($this->once())
53+
->method('getProcessor')
54+
->willReturn($this->processor);
55+
56+
$this->uiComponentFactory = $this->getMockBuilder('Magento\Framework\View\Element\UiComponentFactory')
57+
->disableOriginalConstructor()
58+
->getMock();
59+
60+
$this->scopeConfig = $this->getMockBuilder('Magento\Framework\App\Config\ScopeConfigInterface')
61+
->getMockForAbstractClass();
62+
63+
$this->confirmation = new Confirmation(
64+
$this->context,
65+
$this->uiComponentFactory,
66+
$this->scopeConfig,
67+
[],
68+
[]
69+
);
70+
}
71+
72+
/**
73+
* @param int $isConfirmationRequired
74+
* @param string|null $confirmation
75+
* @param \Magento\Framework\Phrase $expected
76+
* @dataProvider dataProviderPrepareDataSource
77+
*/
78+
public function testPrepareDataSource(
79+
$isConfirmationRequired,
80+
$confirmation,
81+
$expected
82+
) {
83+
$websiteId = 1;
84+
85+
$dataSource = [
86+
'data' => [
87+
'items' => [
88+
[
89+
'confirmation' => $confirmation,
90+
'website_id' => [
91+
$websiteId,
92+
],
93+
],
94+
],
95+
],
96+
];
97+
98+
$this->processor->expects($this->any())
99+
->method('register')
100+
->with($this->confirmation)
101+
->willReturnSelf();
102+
103+
$this->scopeConfig->expects($this->once())
104+
->method('getValue')
105+
->with(AccountManagement::XML_PATH_IS_CONFIRM, ScopeInterface::SCOPE_WEBSITES, $websiteId)
106+
->willReturn($isConfirmationRequired);
107+
108+
$this->confirmation->setData('name', 'confirmation');
109+
$result = $this->confirmation->prepareDataSource($dataSource);
110+
111+
$this->assertEquals($result['data']['items'][0]['confirmation'], $expected);
112+
}
113+
114+
/**
115+
* @return array
116+
*/
117+
public function dataProviderPrepareDataSource()
118+
{
119+
return [
120+
[false, 'confirmation', __('Confirmation Not Required')],
121+
[true, 'confirmation', __('Confirmation Required')],
122+
[true, null, __('Confirmed')],
123+
];
124+
}
125+
}

0 commit comments

Comments
 (0)