Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
CurrencyTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class CurrencyTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $currency;
17 
18  protected $currencyCode = 'USD';
19 
24 
25  protected function setUp()
26  {
27  $this->localeCurrencyMock = $this->createMock(\Magento\Framework\Locale\CurrencyInterface::class);
28 
29  $objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
30  $this->currency = $objectManager->getObject(
31  \Magento\Directory\Model\Currency::class,
32  [
33  'localeCurrency' => $this->localeCurrencyMock,
34  'data' => [
35  'currency_code' => $this->currencyCode,
36  ]
37  ]
38  );
39  }
40 
41  public function testGetCurrencySymbol()
42  {
43  $currencySymbol = '$';
44 
45  $currencyMock = $this->getMockBuilder(\Magento\Framework\Currency::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48  $currencyMock->expects($this->once())
49  ->method('getSymbol')
50  ->willReturn($currencySymbol);
51 
52  $this->localeCurrencyMock->expects($this->once())
53  ->method('getCurrency')
54  ->with($this->currencyCode)
55  ->willReturn($currencyMock);
56  $this->assertEquals($currencySymbol, $this->currency->getCurrencySymbol());
57  }
58 
65  public function testGetOutputFormat($withCurrency, $noCurrency, $expected)
66  {
67  $currencyMock = $this->getMockBuilder(\Magento\Framework\Currency::class)
68  ->disableOriginalConstructor()
69  ->getMock();
70  $currencyMock->expects($this->at(0))
71  ->method('toCurrency')
72  ->willReturn($withCurrency);
73  $currencyMock->expects($this->at(1))
74  ->method('toCurrency')
75  ->willReturn($noCurrency);
76  $this->localeCurrencyMock->expects($this->atLeastOnce())
77  ->method('getCurrency')
78  ->with($this->currencyCode)
79  ->willReturn($currencyMock);
80  $this->assertEquals($expected, $this->currency->getOutputFormat());
81  }
82 
88  public function getOutputFormatDataProvider()
89  {
90  return [
91  'no_unicode' => [
92  'withCurrency' => '$0.00',
93  'noCurrency' => '0.00',
94  'expected' => '$%s',
95  ],
96  'arabic_unicode' => [
97  'withCurrency' => json_decode('"\u200E"') . '$0.00',
98  'noCurrency' => json_decode('"\u200E"') . '0.00',
99  'expected' => json_decode('"\u200E"') . '$%s',
100  ]
101  ];
102  }
103 }
testGetOutputFormat($withCurrency, $noCurrency, $expected)
$objectManager
Definition: bootstrap.php:17
$currencySymbol
Definition: matrix.phtml:14