3
3
* Copyright © Magento, Inc. All rights reserved.
4
4
* See COPYING.txt for license details.
5
5
*/
6
-
7
6
namespace Magento \Store \Test \Unit \Model ;
8
7
9
8
use Magento \Framework \App \Config \ReinitableConfigInterface ;
10
9
use Magento \Framework \App \Config \ScopeConfigInterface ;
10
+ use Magento \Framework \Session \SessionManagerInterface ;
11
11
use Magento \Store \Model \ScopeInterface ;
12
12
use Magento \Store \Model \Store ;
13
13
@@ -38,6 +38,16 @@ class StoreTest extends \PHPUnit\Framework\TestCase
38
38
*/
39
39
protected $ filesystemMock ;
40
40
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
+
41
51
/**
42
52
* @var \Magento\Framework\Url\ModifierInterface|\PHPUnit_Framework_MockObject_MockObject
43
53
*/
@@ -61,12 +71,22 @@ protected function setUp()
61
71
'isSecure ' ,
62
72
'getServer ' ,
63
73
]);
74
+
64
75
$ this ->filesystemMock = $ this ->getMockBuilder (\Magento \Framework \Filesystem::class)
65
76
->disableOriginalConstructor ()
66
77
->getMock ();
78
+ $ this ->configMock = $ this ->getMockBuilder (ReinitableConfigInterface::class)
79
+ ->getMock ();
80
+ $ this ->sessionMock = $ this ->getMockBuilder (SessionManagerInterface::class)
81
+ ->setMethods (['getCurrencyCode ' ])
82
+ ->getMockForAbstractClass ();
67
83
$ this ->store = $ this ->objectManagerHelper ->getObject (
68
84
\Magento \Store \Model \Store::class,
69
- ['filesystem ' => $ this ->filesystemMock ]
85
+ [
86
+ 'filesystem ' => $ this ->filesystemMock ,
87
+ 'config ' => $ this ->configMock ,
88
+ 'session ' => $ this ->sessionMock ,
89
+ ]
70
90
);
71
91
72
92
$ this ->urlModifierMock = $ this ->createMock (\Magento \Framework \Url \ModifierInterface::class);
@@ -694,6 +714,80 @@ public function testGetScopeTypeName()
694
714
$ this ->assertEquals ('Store View ' , $ this ->store ->getScopeTypeName ());
695
715
}
696
716
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
+
697
791
/**
698
792
* @param \Magento\Store\Model\Store $model
699
793
*/
0 commit comments