1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Locale\Test\Unit;
class FormatTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\Locale\Format
*/
protected $formatModel;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Locale\ResolverInterface
*/
protected $localeResolver;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ScopeInterface
*/
protected $scope;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\ScopeResolverInterface
*/
protected $scopeResolver;
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Directory\Model\Currency
*/
protected $currency;
/**
* {@inheritDoc}
*/
protected function setUp()
{
$this->currency = $this->getMockBuilder(\Magento\Directory\Model\Currency::class)
->disableOriginalConstructor()
->getMock();
$this->scope = $this->getMockBuilder(\Magento\Framework\App\ScopeInterface::class)
->setMethods(['getCurrentCurrency'])
->getMockForAbstractClass();
$this->scopeResolver = $this->getMockBuilder(\Magento\Framework\App\ScopeResolverInterface::class)
->setMethods(['getScope'])
->getMockForAbstractClass();
$this->scopeResolver->expects($this->any())
->method('getScope')
->willReturn($this->scope);
$this->localeResolver = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class)
->getMock();
/** @var \Magento\Directory\Model\CurrencyFactory|\PHPUnit_Framework_MockObject_MockObject $currencyFactory */
$currencyFactory = $this->getMockBuilder(\Magento\Directory\Model\CurrencyFactory::class)
->disableOriginalConstructor()
->getMock();
$this->formatModel = new \Magento\Framework\Locale\Format(
$this->scopeResolver,
$this->localeResolver,
$currencyFactory
);
}
/**
* @param string $localeCode
* @param array $expectedResult
* @dataProvider getPriceFormatDataProvider
*/
public function testGetPriceFormat($localeCode, array $expectedResult): void
{
$this->scope->expects($this->once())
->method('getCurrentCurrency')
->willReturn($this->currency);
$result = $this->formatModel->getPriceFormat($localeCode);
$intersection = array_intersect_assoc($result, $expectedResult);
$this->assertCount(count($expectedResult), $intersection);
}
/**
*
* @return array
*/
public function getPriceFormatDataProvider(): array
{
return [
['en_US', ['decimalSymbol' => '.', 'groupSymbol' => ',']],
['de_DE', ['decimalSymbol' => ',', 'groupSymbol' => '.']],
['de_CH', ['decimalSymbol' => '.', 'groupSymbol' => '\'']],
['uk_UA', ['decimalSymbol' => ',', 'groupSymbol' => ' ']]
];
}
/**
*
* @param mixed $value
* @param float $expected
* @dataProvider provideNumbers
*/
public function testGetNumber($value, $expected): void
{
$this->assertEquals($expected, $this->formatModel->getNumber($value));
}
/**
*
* @return array
*/
public function provideNumbers(): array
{
return [
[' 2345.4356,1234', 23454356.1234],
['+23,3452.123', 233452.123],
['12343', 12343],
['-9456km', -9456],
['0', 0],
['2 054,10', 2054.1],
['2046,45', 2046.45],
['2 054.52', 2054.52],
['2,46 GB', 2.46],
['2,054.00', 2054],
];
}
}