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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Framework\Pricing\Test\Unit\Helper;
use Magento\Framework\Pricing\Helper\Data;
use Magento\Framework\Pricing\PriceCurrencyInterface;
class DataTest extends \PHPUnit\Framework\TestCase
{
/**
* @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
*/
protected $objectManager;
/**
* @var \Magento\Framework\Pricing\PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $priceCurrencyMock;
protected function setUp()
{
$this->priceCurrencyMock = $this->createMock(\Magento\Framework\Pricing\PriceCurrencyInterface::class);
$this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
}
/**
* @param string $amount
* @param bool $format
* @param bool $includeContainer
* @param string $result
* @dataProvider currencyDataProvider
*/
public function testCurrency($amount, $format, $includeContainer, $result)
{
if ($format) {
$this->priceCurrencyMock->expects($this->once())
->method('convertAndFormat')
->with($amount, $includeContainer)
->will($this->returnValue($result));
} else {
$this->priceCurrencyMock->expects($this->once())
->method('convert')
->with($amount)
->will($this->returnValue($result));
}
$helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
$this->assertEquals($result, $helper->currency($amount, $format, $includeContainer));
}
/**
* @return array
*/
public function currencyDataProvider()
{
return [
['amount' => '100', 'format' => true, 'includeContainer' => true, 'result' => '100grn.'],
['amount' => '115', 'format' => true, 'includeContainer' => false, 'result' => '1150'],
['amount' => '120', 'format' => false, 'includeContainer' => null, 'result' => '1200'],
];
}
/**
* @param string $amount
* @param string $store
* @param bool $format
* @param bool $includeContainer
* @param string $result
* @dataProvider currencyByStoreDataProvider
*/
public function testCurrencyByStore($amount, $store, $format, $includeContainer, $result)
{
if ($format) {
$this->priceCurrencyMock->expects($this->once())
->method('convertAndFormat')
->with($amount, $includeContainer, PriceCurrencyInterface::DEFAULT_PRECISION, $store)
->will($this->returnValue($result));
} else {
$this->priceCurrencyMock->expects($this->once())
->method('convert')
->with($amount, $store)
->will($this->returnValue($result));
}
$helper = $this->getHelper(['priceCurrency' => $this->priceCurrencyMock]);
$this->assertEquals($result, $helper->currencyByStore($amount, $store, $format, $includeContainer));
}
/**
* @return array
*/
public function currencyByStoreDataProvider()
{
return [
['amount' => '10', 'store' => 1, 'format' => true, 'includeContainer' => true, 'result' => '10grn.'],
['amount' => '115', 'store' => 4, 'format' => true, 'includeContainer' => false, 'result' => '1150'],
['amount' => '120', 'store' => 5, 'format' => false, 'includeContainer' => null, 'result' => '1200'],
];
}
/**
* Get helper instance
*
* @param array $arguments
* @return Data
*/
private function getHelper($arguments)
{
return $this->objectManager->getObject(\Magento\Framework\Pricing\Helper\Data::class, $arguments);
}
}