Skip to content

Commit 3dfcd44

Browse files
author
Joan He
committed
Merge remote-tracking branch 'upstream/develop' into MAGETWO-72487-signifyd
2 parents ecdf63d + ad0299b commit 3dfcd44

File tree

32 files changed

+661
-57
lines changed

32 files changed

+661
-57
lines changed

app/code/Magento/Customer/Test/Unit/Ui/Component/DataProvider/DocumentTest.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
use Magento\Customer\Ui\Component\DataProvider\Document;
1414
use Magento\Framework\Api\AttributeValue;
1515
use Magento\Framework\Api\AttributeValueFactory;
16+
use Magento\Framework\App\Config\ScopeConfigInterface;
17+
use Magento\Framework\Phrase;
1618
use Magento\Store\Api\Data\WebsiteInterface;
1719
use Magento\Store\Model\StoreManagerInterface;
1820
use PHPUnit_Framework_MockObject_MockObject as MockObject;
@@ -44,6 +46,11 @@ class DocumentTest extends \PHPUnit\Framework\TestCase
4446
*/
4547
private $storeManager;
4648

49+
/**
50+
* @var ScopeConfigInterface|MockObject
51+
*/
52+
private $scopeConfig;
53+
4754
/**
4855
* @var Document
4956
*/
@@ -59,11 +66,14 @@ protected function setUp()
5966

6067
$this->storeManager = $this->getMockForAbstractClass(StoreManagerInterface::class);
6168

69+
$this->scopeConfig = $this->getMockForAbstractClass(ScopeConfigInterface::class);
70+
6271
$this->document = new Document(
6372
$this->attributeValueFactory,
6473
$this->groupRepository,
6574
$this->customerMetadata,
66-
$this->storeManager
75+
$this->storeManager,
76+
$this->scopeConfig
6777
);
6878
}
6979

@@ -156,6 +166,41 @@ public function testGetWebsiteAttribute()
156166
static::assertEquals('Main Website', $attribute->getValue());
157167
}
158168

169+
/**
170+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
171+
*/
172+
public function testGetConfirmationAttribute()
173+
{
174+
$websiteId = 1;
175+
$this->document->setData('original_website_id', $websiteId);
176+
177+
$this->scopeConfig->expects(static::once())
178+
->method('getValue')
179+
->with()
180+
->willReturn(true);
181+
182+
$this->document->setData('confirmation', null);
183+
$attribute = $this->document->getCustomAttribute('confirmation');
184+
185+
$value = $attribute->getValue();
186+
static::assertInstanceOf(Phrase::class, $value);
187+
static::assertEquals('Confirmed', (string)$value);
188+
}
189+
190+
/**
191+
* @covers \Magento\Customer\Ui\Component\DataProvider\Document::getCustomAttribute
192+
*/
193+
public function testGetAccountLockValue()
194+
{
195+
$this->document->setData('lock_expires', null);
196+
197+
$attribute = $this->document->getCustomAttribute('lock_expires');
198+
199+
$value = $attribute->getValue();
200+
static::assertInstanceOf(Phrase::class, $value);
201+
static::assertEquals('Unlocked', (string)$value);
202+
}
203+
159204
/**
160205
* Create mock for attribute value factory
161206
* @return void

app/code/Magento/Customer/Ui/Component/DataProvider/Document.php

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
namespace Magento\Customer\Ui\Component\DataProvider;
77

88
use Magento\Customer\Api\CustomerMetadataInterface;
9+
use Magento\Customer\Model\AccountManagement;
910
use Magento\Framework\Api\AttributeValueFactory;
11+
use Magento\Framework\App\Config\ScopeConfigInterface;
1012
use Magento\Framework\Exception\NoSuchEntityException;
1113
use Magento\Customer\Api\GroupRepositoryInterface;
14+
use Magento\Framework\App\ObjectManager;
15+
use Magento\Store\Model\ScopeInterface;
1216
use Magento\Store\Model\StoreManagerInterface;
1317

1418
/**
@@ -31,6 +35,21 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
3135
*/
3236
private static $websiteAttributeCode = 'website_id';
3337

38+
/**
39+
* @var string
40+
*/
41+
private static $websiteIdAttributeCode = 'original_website_id';
42+
43+
/**
44+
* @var string
45+
*/
46+
private static $confirmationAttributeCode = 'confirmation';
47+
48+
/**
49+
* @var string
50+
*/
51+
private static $accountLockAttributeCode = 'lock_expires';
52+
3453
/**
3554
* @var CustomerMetadataInterface
3655
*/
@@ -46,23 +65,31 @@ class Document extends \Magento\Framework\View\Element\UiComponent\DataProvider\
4665
*/
4766
private $storeManager;
4867

68+
/**
69+
* @var ScopeConfigInterface
70+
*/
71+
private $scopeConfig;
72+
4973
/**
5074
* Document constructor.
5175
* @param AttributeValueFactory $attributeValueFactory
5276
* @param GroupRepositoryInterface $groupRepository
5377
* @param CustomerMetadataInterface $customerMetadata
5478
* @param StoreManagerInterface $storeManager
79+
* @param ScopeConfigInterface $scopeConfig
5580
*/
5681
public function __construct(
5782
AttributeValueFactory $attributeValueFactory,
5883
GroupRepositoryInterface $groupRepository,
5984
CustomerMetadataInterface $customerMetadata,
60-
StoreManagerInterface $storeManager
85+
StoreManagerInterface $storeManager,
86+
ScopeConfigInterface $scopeConfig = null
6187
) {
6288
parent::__construct($attributeValueFactory);
6389
$this->customerMetadata = $customerMetadata;
6490
$this->groupRepository = $groupRepository;
6591
$this->storeManager = $storeManager;
92+
$this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->create(ScopeConfigInterface::class);
6693
}
6794

6895
/**
@@ -80,6 +107,12 @@ public function getCustomAttribute($attributeCode)
80107
case self::$websiteAttributeCode:
81108
$this->setWebsiteValue();
82109
break;
110+
case self::$confirmationAttributeCode:
111+
$this->setConfirmationValue();
112+
break;
113+
case self::$accountLockAttributeCode:
114+
$this->setAccountLockValue();
115+
break;
83116
}
84117
return parent::getCustomAttribute($attributeCode);
85118
}
@@ -133,5 +166,49 @@ private function setWebsiteValue()
133166
$value = $this->getData(self::$websiteAttributeCode);
134167
$list = $this->storeManager->getWebsites();
135168
$this->setCustomAttribute(self::$websiteAttributeCode, $list[$value]->getName());
169+
$this->setCustomAttribute(self::$websiteIdAttributeCode, $value);
170+
}
171+
172+
/**
173+
* Update confirmation value
174+
* Method set confirmation text value to match what is shown in grid
175+
* @return void
176+
*/
177+
private function setConfirmationValue()
178+
{
179+
$value = $this->getData(self::$confirmationAttributeCode);
180+
$websiteId = $this->getData(self::$websiteIdAttributeCode) ?: $this->getData(self::$websiteAttributeCode);
181+
$isConfirmationRequired = (bool)$this->scopeConfig->getValue(
182+
AccountManagement::XML_PATH_IS_CONFIRM,
183+
ScopeInterface::SCOPE_WEBSITES,
184+
$websiteId
185+
);
186+
187+
$valueText = __('Confirmation Not Required');
188+
if ($isConfirmationRequired) {
189+
$valueText = $value === null ? __('Confirmed') : __('Confirmation Required');
190+
}
191+
192+
$this->setCustomAttribute(self::$confirmationAttributeCode, $valueText);
193+
}
194+
195+
/**
196+
* Update lock expires value
197+
* Method set account lock text value to match what is shown in grid
198+
* @return void
199+
*/
200+
private function setAccountLockValue()
201+
{
202+
$value = $this->getDataByPath(self::$accountLockAttributeCode);
203+
204+
$valueText = __('Unlocked');
205+
if ($value !== null) {
206+
$lockExpires = new \DateTime($value);
207+
if ($lockExpires > new \DateTime()) {
208+
$valueText = __('Locked');
209+
}
210+
}
211+
212+
$this->setCustomAttribute(self::$accountLockAttributeCode, $valueText);
136213
}
137214
}

app/code/Magento/OfflineShipping/Model/ResourceModel/Carrier/Tablerate.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace Magento\OfflineShipping\Model\ResourceModel\Carrier;
1313

1414
use Magento\Framework\Filesystem;
15-
use Magento\Framework\Filesystem\DirectoryList;
1615
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Import;
1716
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQuery;
1817
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory;
@@ -321,9 +320,13 @@ public function getConditionName(\Magento\Framework\DataObject $object)
321320
*/
322321
private function getCsvFile($filePath)
323322
{
324-
$tmpDirectory = $this->filesystem->getDirectoryRead(DirectoryList::SYS_TMP);
325-
$path = $tmpDirectory->getRelativePath($filePath);
326-
return $tmpDirectory->openFile($path);
323+
$pathInfo = pathInfo($filePath);
324+
$dirName = isset($pathInfo['dirname']) ? $pathInfo['dirname'] : '';
325+
$fileName = isset($pathInfo['basename']) ? $pathInfo['basename'] : '';
326+
327+
$directoryRead = $this->filesystem->getDirectoryReadByPath($dirName);
328+
329+
return $directoryRead->openFile($fileName);
327330
}
328331

329332
/**
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\OfflineShipping\Test\Unit\Model\ResourceModel\Carrier;
8+
9+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate;
10+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\Import;
11+
use Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate\RateQueryFactory;
12+
13+
/**
14+
* Unit test for Magento\OfflineShipping\Model\ResourceModel\Carrier\Tablerate
15+
*
16+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
17+
*/
18+
class TablerateTest extends \PHPUnit\Framework\TestCase
19+
{
20+
/**
21+
* @var Tablerate
22+
*/
23+
private $model;
24+
25+
/**
26+
* @var \PHPUnit_Framework_MockObject_MockObject
27+
*/
28+
private $storeManagerMock;
29+
30+
/**
31+
* @var \PHPUnit_Framework_MockObject_MockObject
32+
*/
33+
private $filesystemMock;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
private $resource;
39+
40+
/**
41+
* @var \PHPUnit_Framework_MockObject_MockObject
42+
*/
43+
private $importMock;
44+
45+
protected function setUp()
46+
{
47+
$contextMock = $this->createMock(\Magento\Framework\Model\ResourceModel\Db\Context::class);
48+
$loggerMock = $this->createMock(\Psr\Log\LoggerInterface::class);
49+
$coreConfigMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
50+
$this->storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);
51+
$carrierTablerateMock = $this->createMock(\Magento\OfflineShipping\Model\Carrier\Tablerate::class);
52+
$this->filesystemMock = $this->createMock(\Magento\Framework\Filesystem::class);
53+
$this->importMock = $this->createMock(Import::class);
54+
$rateQueryFactoryMock = $this->createMock(RateQueryFactory::class);
55+
$this->resource = $this->createMock(\Magento\Framework\App\ResourceConnection::class);
56+
57+
$contextMock->expects($this->once())->method('getResources')->willReturn($this->resource);
58+
59+
$this->model = new Tablerate(
60+
$contextMock,
61+
$loggerMock,
62+
$coreConfigMock,
63+
$this->storeManagerMock,
64+
$carrierTablerateMock,
65+
$this->filesystemMock,
66+
$this->importMock,
67+
$rateQueryFactoryMock
68+
);
69+
}
70+
71+
public function testUploadAndImport()
72+
{
73+
$_FILES['groups']['tmp_name']['tablerate']['fields']['import']['value'] = 'some/path/to/file';
74+
$object = $this->createPartialMock(
75+
\Magento\OfflineShipping\Model\Config\Backend\Tablerate::class,
76+
['getScopeId']
77+
);
78+
79+
$websiteMock = $this->createMock(\Magento\Store\Api\Data\WebsiteInterface::class);
80+
$directoryReadMock = $this->createMock(\Magento\Framework\Filesystem\Directory\ReadInterface::class);
81+
$fileReadMock = $this->createMock(\Magento\Framework\Filesystem\File\ReadInterface::class);
82+
$connectionMock = $this->createMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
83+
84+
$this->storeManagerMock->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
85+
$object->expects($this->once())->method('getScopeId')->willReturn(1);
86+
$websiteMock->expects($this->once())->method('getId')->willReturn(1);
87+
88+
$this->filesystemMock->expects($this->once())->method('getDirectoryReadByPath')
89+
->with('some/path/to')->willReturn($directoryReadMock);
90+
$directoryReadMock->expects($this->once())->method('openFile')
91+
->with('file')->willReturn($fileReadMock);
92+
93+
$this->resource->expects($this->once())->method('getConnection')->willReturn($connectionMock);
94+
95+
$connectionMock->expects($this->once())->method('beginTransaction');
96+
$connectionMock->expects($this->once())->method('delete');
97+
$connectionMock->expects($this->once())->method('commit');
98+
99+
$this->importMock->expects($this->once())->method('getColumns')->willReturn([]);
100+
$this->importMock->expects($this->once())->method('getData')->willReturn([]);
101+
102+
$this->model->uploadAndImport($object);
103+
unset($_FILES['groups']);
104+
}
105+
}

app/code/Magento/Swatches/Model/Plugin/EavAttribute.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,17 @@ protected function setProperOptionsArray(Attribute $attribute)
130130
$swatchesArray = $attribute->getData('swatchtext');
131131
}
132132
if ($canReplace == true) {
133-
$attribute->setData('option', $optionsArray);
134-
$attribute->setData('default', $defaultValue);
135-
$attribute->setData('swatch', $swatchesArray);
133+
if (!empty($optionsArray)) {
134+
$attribute->setData('option', $optionsArray);
135+
}
136+
if (!empty($defaultValue)) {
137+
$attribute->setData('default', $defaultValue);
138+
} else {
139+
$attribute->setData('default', [0 => $attribute->getDefaultValue()]);
140+
}
141+
if (!empty($swatchesArray)) {
142+
$attribute->setData('swatch', $swatchesArray);
143+
}
136144
}
137145
}
138146

app/code/Magento/Tax/Model/Plugin/OrderSave.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,12 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
9797
} else {
9898
$percentSum = 0;
9999
foreach ($taxRates as $rate) {
100-
$realAmount = $rates['amount'] * $rate['percent'] / $rates['percent'];
101-
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $rates['percent'];
100+
$percentSum += $rate['percent'];
101+
}
102+
103+
foreach ($taxRates as $rate) {
104+
$realAmount = $rates['amount'] * $rate['percent'] / $percentSum;
105+
$realBaseAmount = $rates['base_amount'] * $rate['percent'] / $percentSum;
102106
$ratesIdQuoteItemId[$rates['id']][] = [
103107
'id' => $taxesArray['item_id'],
104108
'percent' => $rate['percent'],
@@ -110,7 +114,6 @@ protected function saveOrderTax(\Magento\Sales\Api\Data\OrderInterface $order)
110114
'real_amount' => $realAmount,
111115
'real_base_amount' => $realBaseAmount,
112116
];
113-
$percentSum += $rate['percent'];
114117
}
115118
}
116119
}

0 commit comments

Comments
 (0)