33 * Copyright © Magento, Inc. All rights reserved.
44 * See COPYING.txt for license details.
55 */
6-
76namespace Magento \Store \Test \Unit \Model ;
87
98use Magento \Framework \App \Config \ReinitableConfigInterface ;
109use Magento \Framework \App \Config \ScopeConfigInterface ;
10+ use Magento \Framework \Session \SessionManagerInterface ;
1111use Magento \Store \Model \ScopeInterface ;
1212use Magento \Store \Model \Store ;
1313
@@ -38,6 +38,16 @@ class StoreTest extends \PHPUnit\Framework\TestCase
3838 */
3939 protected $ filesystemMock ;
4040
41+ /**
42+ * @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject
43+ */
44+ private $ configMock ;
45+
46+ /**
47+ * @var SessionManagerInterface|\PHPUnit_Framework_MockObject_MockObject
48+ */
49+ private $ sessionMock ;
50+
4151 /**
4252 * @var \Magento\Framework\Url\ModifierInterface|\PHPUnit_Framework_MockObject_MockObject
4353 */
@@ -61,12 +71,22 @@ protected function setUp()
6171 'isSecure ' ,
6272 'getServer ' ,
6373 ]);
74+
6475 $ this ->filesystemMock = $ this ->getMockBuilder (\Magento \Framework \Filesystem::class)
6576 ->disableOriginalConstructor ()
6677 ->getMock ();
78+ $ this ->configMock = $ this ->getMockBuilder (ReinitableConfigInterface::class)
79+ ->getMock ();
80+ $ this ->sessionMock = $ this ->getMockBuilder (SessionManagerInterface::class)
81+ ->setMethods (['getCurrencyCode ' ])
82+ ->getMockForAbstractClass ();
6783 $ this ->store = $ this ->objectManagerHelper ->getObject (
6884 \Magento \Store \Model \Store::class,
69- ['filesystem ' => $ this ->filesystemMock ]
85+ [
86+ 'filesystem ' => $ this ->filesystemMock ,
87+ 'config ' => $ this ->configMock ,
88+ 'session ' => $ this ->sessionMock ,
89+ ]
7090 );
7191
7292 $ this ->urlModifierMock = $ this ->createMock (\Magento \Framework \Url \ModifierInterface::class);
@@ -694,6 +714,80 @@ public function testGetScopeTypeName()
694714 $ this ->assertEquals ('Store View ' , $ this ->store ->getScopeTypeName ());
695715 }
696716
717+ /**
718+ * @param array $availableCodes
719+ * @param string $currencyCode
720+ * @param string $defaultCode
721+ * @param string $expectedCode
722+ * @return void
723+ * @dataProvider currencyCodeDataProvider
724+ */
725+ public function testGetCurrentCurrencyCode (
726+ array $ availableCodes ,
727+ string $ currencyCode ,
728+ string $ defaultCode ,
729+ string $ expectedCode
730+ ): void {
731+ $ this ->store ->setData ('available_currency_codes ' , $ availableCodes );
732+ $ this ->sessionMock ->method ('getCurrencyCode ' )
733+ ->willReturn ($ currencyCode );
734+ $ this ->configMock ->method ('getValue ' )
735+ ->with (\Magento \Directory \Model \Currency::XML_PATH_CURRENCY_DEFAULT )
736+ ->willReturn ($ defaultCode );
737+
738+ $ code = $ this ->store ->getCurrentCurrencyCode ();
739+ $ this ->assertEquals ($ expectedCode , $ code );
740+ }
741+
742+ /**
743+ * @return array
744+ */
745+ public function currencyCodeDataProvider (): array
746+ {
747+ return [
748+ [
749+ [
750+ 'USD ' ,
751+ ],
752+ 'USD ' ,
753+ 'USD ' ,
754+ 'USD ' ,
755+ ],
756+ [
757+ [
758+ 'USD ' ,
759+ 'EUR ' ,
760+ ],
761+ 'EUR ' ,
762+ 'USD ' ,
763+ 'EUR ' ,
764+ ],
765+ [
766+ [
767+ 'EUR ' ,
768+ 'USD ' ,
769+ ],
770+ 'GBP ' ,
771+ 'USD ' ,
772+ 'USD ' ,
773+ ],
774+ [
775+ [
776+ 'USD ' ,
777+ ],
778+ 'GBP ' ,
779+ 'EUR ' ,
780+ 'USD ' ,
781+ ],
782+ [
783+ [],
784+ 'GBP ' ,
785+ 'EUR ' ,
786+ 'EUR ' ,
787+ ],
788+ ];
789+ }
790+
697791 /**
698792 * @param \Magento\Store\Model\Store $model
699793 */
0 commit comments