Skip to content

Commit 93b73ed

Browse files
committed
39236: Fixed Static Test Failures and added Unit Test case for LocalizedToNormalized
1 parent bafe99a commit 93b73ed

File tree

3 files changed

+104
-8
lines changed

3 files changed

+104
-8
lines changed

app/code/Magento/Checkout/Test/Unit/Model/SidebarTest.php

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,19 +140,25 @@ public function testRemoveQuoteItem()
140140
$this->assertEquals($this->sidebar, $this->sidebar->removeQuoteItem($itemId));
141141
}
142142

143-
public function testUpdateQuoteItem()
143+
/**
144+
* @param string $locale
145+
* @param int|string $itemId
146+
* @param int|string|float $expectedItemQty
147+
* @param int|string|float $itemQty
148+
*
149+
* @dataProvider dataProviderUpdateQuoteItem
150+
*/
151+
public function testUpdateQuoteItem($locale, $itemId, $expectedItemQty ,$itemQty)
144152
{
145-
$itemId = 1;
146-
$itemQty = 2;
147-
148153
$this->resolverMock->expects($this->once())
149154
->method('getLocale')
150-
->willReturn('en');
155+
->willReturn($locale);
151156

152157
$this->cartMock->expects($this->once())
153158
->method('updateItems')
154-
->with([$itemId => ['qty' => $itemQty]])
159+
->with([$itemId => ['qty' => $expectedItemQty]])
155160
->willReturnSelf();
161+
156162
$this->cartMock->expects($this->once())
157163
->method('save')
158164
->willReturnSelf();
@@ -178,4 +184,18 @@ public function testUpdateQuoteItemWithZeroQty()
178184

179185
$this->assertEquals($this->sidebar, $this->sidebar->updateQuoteItem($itemId, $itemQty));
180186
}
187+
188+
/**
189+
* @return array
190+
*/
191+
public static function dataProviderUpdateQuoteItem()
192+
{
193+
return [
194+
//locale, itemId, expectedItemQty, ItemQty
195+
[ 'en_US', 1, 2, 2],
196+
[ 'en_US', 1, 0.5, 0.5],
197+
[ 'en_US', 1,"0.5","0.5"],
198+
[ 'nl_NL', 1,"0.5","0,5"]
199+
];
200+
}
181201
}

lib/internal/Magento/Framework/Filter/LocalizedToNormalized.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,9 @@ public function filter($value)
7070
if (is_numeric($value)) {
7171
$numberParse = new NumberParse(
7272
$this->_options['locale'],
73-
empty($this->_options['decimal_style']) ? NumberFormatter::PATTERN_DECIMAL : $this->_options['decimal_style']
73+
empty($this->_options['decimal_style'])
74+
? NumberFormatter::PATTERN_DECIMAL
75+
: $this->_options['decimal_style']
7476
);
7577
return (string)$numberParse->filter($value);
7678
} elseif ($this->_options['date_format'] === null && strpos($value, ':') !== false) {
@@ -198,7 +200,6 @@ private function parseDate($date)
198200
}
199201
++$cnt;
200202
}
201-
202203
return $result;
203204
}
204205
}
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
/**
3+
* Copyright 2025 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Filter\Test\Unit;
9+
10+
use Magento\Framework\Filter\LocalizedToNormalized;
11+
use PHPUnit\Framework\TestCase;
12+
use NumberFormatter;
13+
14+
class LocalizedToNormalizedTest extends TestCase
15+
{
16+
17+
/**
18+
* @param string $value
19+
* @param array $options
20+
* @param string|array $expectedValues
21+
*
22+
* @dataProvider localizedToNormalizedDataProvider
23+
*/
24+
public function testLocalizedToNormalized($value, $options, $expectedValue)
25+
{
26+
$filter = new LocalizedToNormalized($options);
27+
$this->assertEquals($expectedValue, $filter->filter($value));
28+
}
29+
30+
/**
31+
* @return array
32+
*/
33+
public static function localizedToNormalizedDataProvider()
34+
{
35+
36+
return [
37+
'1' => [
38+
"0.5",
39+
[
40+
'locale' => 'nl',
41+
'date_format' => null,
42+
'precision' => null,
43+
'decimal_style' => NumberFormatter::PATTERN_DECIMAL
44+
],
45+
"0.5"
46+
],
47+
'2' => [
48+
"0.5",
49+
[
50+
'locale' => 'en',
51+
'date_format' => null,
52+
'precision' => null,
53+
'decimal_style' => ' '
54+
],
55+
"0.5"
56+
],
57+
'3' => [
58+
'2014-03-30',
59+
[
60+
'locale' => 'en',
61+
'date_format' => 'Y-M-d',
62+
'precision' => null,
63+
'decimal_style' => ''
64+
],
65+
[
66+
"date_format" => "Y-M-d",
67+
"locale" => "en",
68+
"year" => "2014",
69+
"month" => "03",
70+
"day" => "30",
71+
]
72+
]
73+
];
74+
}
75+
}

0 commit comments

Comments
 (0)