Skip to content

Commit 583eeda

Browse files
author
Robert He
committed
MAGETWO-52891: [FT] CreateSimpleProductEntityTest failed to recognize a comma and a dot in the product price
- fix error without changing constructor
1 parent 49fe79c commit 583eeda

File tree

4 files changed

+98
-30
lines changed

4 files changed

+98
-30
lines changed

app/code/Magento/Catalog/Test/Unit/Ui/DataProvider/Product/Form/Modifier/EavTest.php

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
3232
use Magento\Framework\Currency;
3333
use Magento\Framework\Locale\Currency as CurrencyLocale;
34+
Use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
3435

3536
/**
3637
* Class EavTest
@@ -156,9 +157,20 @@ class EavTest extends AbstractModifierTest
156157
*/
157158
protected $currencyLocaleMock;
158159

160+
/**
161+
* @var ObjectManager
162+
*/
163+
protected $objectManager;
164+
165+
/**
166+
* @var Eav
167+
*/
168+
protected $eav;
169+
159170
protected function setUp()
160171
{
161172
parent::setUp();
173+
$this->objectManager = new ObjectManager($this);
162174
$this->eavConfigMock = $this->getMockBuilder(Config::class)
163175
->disableOriginalConstructor()
164176
->getMock();
@@ -265,6 +277,13 @@ protected function setUp()
265277
->disableOriginalConstructor()
266278
->setMethods(['getCurrency'])
267279
->getMock();
280+
281+
$this->eav =$this->getModel();
282+
$this->objectManager->setBackwardCompatibleProperty(
283+
$this->eav,
284+
'localeCurrency',
285+
$this->currencyLocaleMock
286+
);
268287
}
269288

270289
/**
@@ -285,7 +304,6 @@ protected function createModel()
285304
'attributeGroupRepository' => $this->attributeGroupRepositoryMock,
286305
'sortOrderBuilder' => $this->sortOrderBuilderMock,
287306
'attributeRepository' => $this->attributeRepositoryMock,
288-
'localeCurrency' => $this->currencyLocaleMock,
289307
]);
290308
}
291309

@@ -379,6 +397,6 @@ public function testModifyData()
379397
->method('getCurrency')
380398
->willReturn($this->currencyMock);
381399

382-
$this->assertEquals($sourceData, $this->getModel()->modifyData([]));
400+
$this->assertEquals($sourceData, $this->eav->modifyData([]));
383401
}
384402
}

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,7 @@ class CustomOptions extends AbstractModifier
112112
* @var UrlInterface
113113
*/
114114
protected $urlBuilder;
115-
116-
/**
117-
* @var CurrencyInterface
118-
*/
119-
protected $localeCurrency;
120-
115+
121116
/**
122117
* @var ArrayManager
123118
*/
@@ -128,13 +123,17 @@ class CustomOptions extends AbstractModifier
128123
*/
129124
protected $meta = [];
130125

126+
/**
127+
* @var CurrencyInterface
128+
*/
129+
private $localeCurrency;
130+
131131
/**
132132
* @param LocatorInterface $locator
133133
* @param StoreManagerInterface $storeManager
134134
* @param ConfigInterface $productOptionsConfig
135135
* @param ProductOptionsPrice $productOptionsPrice
136136
* @param UrlInterface $urlBuilder
137-
* @param CurrencyInterface $localeCurrency
138137
* @param ArrayManager $arrayManager
139138
*/
140139
public function __construct(
@@ -143,15 +142,13 @@ public function __construct(
143142
ConfigInterface $productOptionsConfig,
144143
ProductOptionsPrice $productOptionsPrice,
145144
UrlInterface $urlBuilder,
146-
CurrencyInterface $localeCurrency,
147145
ArrayManager $arrayManager
148146
) {
149147
$this->locator = $locator;
150148
$this->storeManager = $storeManager;
151149
$this->productOptionsConfig = $productOptionsConfig;
152150
$this->productOptionsPrice = $productOptionsPrice;
153151
$this->urlBuilder = $urlBuilder;
154-
$this->localeCurrency = $localeCurrency;
155152
$this->arrayManager = $arrayManager;
156153
}
157154

@@ -1079,6 +1076,21 @@ protected function getCurrencySymbol()
10791076
return $this->storeManager->getStore()->getBaseCurrency()->getCurrencySymbol();
10801077
}
10811078

1079+
/**
1080+
* The getter function to get the locale currency for real application code
1081+
*
1082+
* @return \Magento\Framework\Locale\CurrencyInterface
1083+
*
1084+
* @deprecated
1085+
*/
1086+
private function getLocaleCurrency()
1087+
{
1088+
if ($this->localeCurrency === null) {
1089+
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
1090+
}
1091+
return $this->localeCurrency;
1092+
}
1093+
10821094
/**
10831095
* Format price according to the locale of the currency
10841096
*
@@ -1092,7 +1104,7 @@ protected function formatPrice($value)
10921104
}
10931105

10941106
$store = $this->storeManager->getStore();
1095-
$currency = $this->localeCurrency->getCurrency($store->getBaseCurrencyCode());
1107+
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
10961108
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
10971109

10981110
return $value;

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/Eav.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ class Eav extends AbstractModifier
165165
/**
166166
* @var CurrencyInterface
167167
*/
168-
protected $localeCurrency;
168+
private $localeCurrency;
169169

170170
/**
171171
* @param LocatorInterface $locator
@@ -185,7 +185,6 @@ class Eav extends AbstractModifier
185185
* @param ArrayManager $arrayManager
186186
* @param ScopeOverriddenValue $scopeOverriddenValue
187187
* @param DataPersistorInterface $dataPersistor
188-
* @param CurrencyInterface $localeCurrency
189188
* @param array $attributesToDisable
190189
* @param array $attributesToEliminate
191190
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
@@ -208,7 +207,6 @@ public function __construct(
208207
ArrayManager $arrayManager,
209208
ScopeOverriddenValue $scopeOverriddenValue,
210209
DataPersistorInterface $dataPersistor,
211-
CurrencyInterface $localeCurrency,
212210
$attributesToDisable = [],
213211
$attributesToEliminate = []
214212
) {
@@ -229,7 +227,6 @@ public function __construct(
229227
$this->arrayManager = $arrayManager;
230228
$this->scopeOverriddenValue = $scopeOverriddenValue;
231229
$this->dataPersistor = $dataPersistor;
232-
$this->localeCurrency = $localeCurrency;
233230
$this->attributesToDisable = $attributesToDisable;
234231
$this->attributesToEliminate = $attributesToEliminate;
235232
}
@@ -877,6 +874,21 @@ private function calculateGroupCode(AttributeGroupInterface $group)
877874
return $attributeGroupCode;
878875
}
879876

877+
/**
878+
* The getter function to get the locale currency for real application code
879+
*
880+
* @return \Magento\Framework\Locale\CurrencyInterface
881+
*
882+
* @deprecated
883+
*/
884+
private function getLocaleCurrency()
885+
{
886+
if ($this->localeCurrency === null) {
887+
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
888+
}
889+
return $this->localeCurrency;
890+
}
891+
880892
/**
881893
* Format price according to the locale of the currency
882894
*
@@ -890,7 +902,7 @@ protected function formatPrice($value)
890902
}
891903

892904
$store = $this->storeManager->getStore();
893-
$currency = $this->localeCurrency->getCurrency($store->getBaseCurrencyCode());
905+
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
894906
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
895907

896908
return $value;

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/General.php

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,23 @@ class General extends AbstractModifier
3030
/**
3131
* @var StoreManagerInterface
3232
*/
33-
protected $storeManager;
33+
private $storeManager;
3434

3535
/**
3636
* @var CurrencyInterface
3737
*/
38-
protected $localeCurrency;
38+
private $localeCurrency;
3939

4040
/**
4141
* @param LocatorInterface $locator
4242
* @param ArrayManager $arrayManager
43-
* @param StoreManagerInterface $storeManager
44-
* @param CurrencyInterface $localeCurrency
4543
*/
4644
public function __construct(
4745
LocatorInterface $locator,
48-
ArrayManager $arrayManager,
49-
StoreManagerInterface $storeManager,
50-
CurrencyInterface $localeCurrency
46+
ArrayManager $arrayManager
5147
) {
5248
$this->locator = $locator;
5349
$this->arrayManager = $arrayManager;
54-
$this->storeManager = $storeManager;
55-
$this->localeCurrency = $localeCurrency;
5650
}
5751

5852
/**
@@ -369,6 +363,38 @@ protected function customizeNameListeners(array $meta)
369363
);
370364
}
371365

366+
/**
367+
* The getter function to get the locale currency for real application code
368+
*
369+
* @return \Magento\Framework\Locale\CurrencyInterface
370+
*
371+
* @deprecated
372+
*/
373+
private function getLocaleCurrency()
374+
{
375+
if ($this->localeCurrency === null) {
376+
$this->localeCurrency = \Magento\Framework\App\ObjectManager::getInstance()->get(CurrencyInterface::class);
377+
}
378+
return $this->localeCurrency;
379+
}
380+
381+
/**
382+
* The getter function to get the store manager for real application code
383+
*
384+
* @return \Magento\Store\Model\StoreManagerInterface
385+
*
386+
* @deprecated
387+
*/
388+
private function getStoreManager()
389+
{
390+
if ($this->storeManager === null) {
391+
$this->storeManager =
392+
\Magento\Framework\App\ObjectManager::getInstance()->get(StoreManagerInterface::class);
393+
}
394+
return $this->storeManager;
395+
}
396+
397+
372398
/**
373399
* Format price according to the locale of the currency
374400
*
@@ -381,8 +407,8 @@ protected function formatPrice($value)
381407
return null;
382408
}
383409

384-
$store = $this->storeManager->getStore();
385-
$currency = $this->localeCurrency->getCurrency($store->getBaseCurrencyCode());
410+
$store = $this->getStoreManager()->getStore();
411+
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
386412
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL]);
387413

388414
return $value;
@@ -402,8 +428,8 @@ protected function formatNumber($value)
402428

403429
$value = (float)$value;
404430
$precision = strlen(substr(strrchr($value, "."), 1));
405-
$store = $this->storeManager->getStore();
406-
$currency = $this->localeCurrency->getCurrency($store->getBaseCurrencyCode());
431+
$store = $this->getStoreManager()->getStore();
432+
$currency = $this->getLocaleCurrency()->getCurrency($store->getBaseCurrencyCode());
407433
$value = $currency->toCurrency($value, ['display' => \Magento\Framework\Currency::NO_SYMBOL,
408434
'precision' => $precision]);
409435

0 commit comments

Comments
 (0)