16 private $mockEventManager;
21 private $mockLocaleResolver;
26 private $mockCurrencyFactory;
31 private $testCurrencyObject;
44 $this->mockEventManager = $this
45 ->getMockBuilder(\
Magento\Framework\
Event\Manager::class)
46 ->disableOriginalConstructor()
48 $this->mockLocaleResolver = $this
49 ->getMockBuilder(\
Magento\Framework\Locale\Resolver::class)
50 ->disableOriginalConstructor()
52 $this->mockCurrencyFactory = $this
53 ->getMockBuilder(\
Magento\Framework\CurrencyFactory::class)
54 ->disableOriginalConstructor()
57 $this->testCurrencyObject = (new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this))
59 \
Magento\Framework\Locale\Currency::class,
61 'eventManager' => $this->mockEventManager,
62 'localeResolver' => $this->mockLocaleResolver,
63 'currencyFactory' => $this->mockCurrencyFactory,
71 $retrievedDefaultCurrency = $this->testCurrencyObject->getDefaultCurrency();
72 $this->assertEquals($expectedDefaultCurrency, $retrievedDefaultCurrency);
77 $options = new \Zend_Currency(
null, self::TEST_NONCACHED_CURRENCY_LOCALE);
79 $this->mockCurrencyFactory
80 ->expects($this->once())
82 ->will($this->returnValue(
$options));
84 $this->mockEventManager
85 ->expects($this->once())
88 $retrievedCurrencyObject = $this->testCurrencyObject
89 ->getCurrency(self::TEST_NONCACHED_CURRENCY);
91 $this->assertInstanceOf(
'Zend_Currency', $retrievedCurrencyObject);
92 $this->assertEquals(self::TEST_NONCACHED_CURRENCY_LOCALE, $retrievedCurrencyObject->getLocale());
93 $this->assertEquals(
'US Dollar', $retrievedCurrencyObject->getName());
94 $this->assertEquals([self::TEST_NONCACHED_CURRENCY], $retrievedCurrencyObject->getCurrencyList());
99 $options = new \Zend_Currency(
null, self::TEST_CACHED_CURRENCY_LOCALE);
101 $this->mockCurrencyFactory
102 ->expects($this->once())
104 ->will($this->returnValue(
$options));
106 $this->mockEventManager
107 ->expects($this->once())
108 ->method(
'dispatch');
110 $retrievedCurrencyObject = $this->testCurrencyObject
111 ->getCurrency(self::TEST_CACHED_CURRENCY);
113 $this->assertInstanceOf(
'Zend_Currency', $retrievedCurrencyObject);
114 $this->assertEquals(self::TEST_CACHED_CURRENCY_LOCALE, $retrievedCurrencyObject->getLocale());
115 $this->assertEquals(
'Canadian Dollar', $retrievedCurrencyObject->getName());
116 $this->assertEquals([self::TEST_CACHED_CURRENCY], $retrievedCurrencyObject->getCurrencyList());
124 $this->mockCurrencyFactory
125 ->expects($this->never())
127 ->will($this->returnValue(
$options));
129 $this->mockEventManager
130 ->expects($this->never())
131 ->method(
'dispatch');
133 $retrievedCurrencyObject = $this->testCurrencyObject
134 ->getCurrency(self::TEST_CACHED_CURRENCY);
136 $this->assertInstanceOf(
'Zend_Currency', $retrievedCurrencyObject);
137 $this->assertEquals(self::TEST_CACHED_CURRENCY_LOCALE, $retrievedCurrencyObject->getLocale());
138 $this->assertEquals(
'Canadian Dollar', $retrievedCurrencyObject->getName());
139 $this->assertEquals([self::TEST_CACHED_CURRENCY], $retrievedCurrencyObject->getCurrencyList());
144 $options = new \Zend_Currency(
null, self::TEST_NONEXISTANT_CURRENCY_LOCALE);
146 $this->mockCurrencyFactory
147 ->expects($this->once())
149 ->will($this->returnValue(
$options));
151 $this->mockEventManager
152 ->expects($this->once())
153 ->method(
'dispatch');
155 $this->mockEventManager
156 ->expects($this->once())
157 ->method(
'dispatch');
159 $retrievedCurrencyObject = $this->testCurrencyObject
160 ->getCurrency(self::TEST_NONEXISTANT_CURRENCY);
162 $this->assertInstanceOf(
'Zend_Currency', $retrievedCurrencyObject);
163 $this->assertEquals(self::TEST_NONEXISTANT_CURRENCY_LOCALE, $retrievedCurrencyObject->getLocale());
164 $this->assertEquals(
'euro', $retrievedCurrencyObject->getName());
165 $this->assertEquals([
'EUR'], $retrievedCurrencyObject->getCurrencyList());
170 $options = new \Zend_Currency(
null, self::TEST_EXCEPTION_CURRENCY_LOCALE);
172 $this->mockCurrencyFactory
173 ->expects($this->at(0))
175 ->will($this->throwException(
new \Exception()));
177 $this->mockCurrencyFactory
178 ->expects($this->at(1))
180 ->will($this->returnValue(
$options));
182 $this->mockEventManager
183 ->expects($this->once())
184 ->method(
'dispatch');
186 $this->mockLocaleResolver
187 ->expects($this->exactly(5))
188 ->method(
'getLocale');
190 $retrievedCurrencyObject = $this->testCurrencyObject
191 ->getCurrency(self::TEST_EXCEPTION_CURRENCY);
193 $this->assertInstanceOf(
'Zend_Currency', $retrievedCurrencyObject);
194 $this->assertEquals(self::TEST_EXCEPTION_CURRENCY_LOCALE, $retrievedCurrencyObject->getLocale());
195 $this->assertEquals(self::TEST_EXCEPTION_CURRENCY, $retrievedCurrencyObject->getName());
196 $this->assertEquals([
'EUR'], $retrievedCurrencyObject->getCurrencyList());
testGetNonExistantCurrency()
const TEST_NONCACHED_CURRENCY
const TEST_EXCEPTION_CURRENCY
const TEST_NONCACHED_CURRENCY_LOCALE
const TEST_EXCEPTION_CURRENCY_LOCALE
const TEST_NONEXISTANT_CURRENCY
testGetCurrencyNonCached()
const TEST_CACHED_CURRENCY
const TEST_NONEXISTANT_CURRENCY_LOCALE
const TEST_CACHED_CURRENCY_LOCALE