Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultLocatorTest.php
Go to the documentation of this file.
1 <?php
7 
8 class DefaultLocatorTest extends \PHPUnit\Framework\TestCase
9 {
13  protected $_model;
14 
18  protected $_configMock;
19 
23  protected $_storeManagerMock;
24 
28  protected $_requestMock;
29 
30  protected function setUp()
31  {
32  $backendData = $this->createMock(\Magento\Backend\Helper\Data::class);
33  $this->_requestMock = $this->getMockForAbstractClass(
34  \Magento\Framework\App\RequestInterface::class,
35  [$backendData],
36  '',
37  false,
38  false,
39  true,
40  ['getParam']
41  );
42  $this->_configMock = $this->createMock(\Magento\Framework\App\Config\ScopeConfigInterface::class);
43  $this->_storeManagerMock = $this->createMock(\Magento\Store\Model\StoreManager::class);
44  $this->_model = new \Magento\Directory\Model\Currency\DefaultLocator(
45  $this->_configMock,
46  $this->_storeManagerMock
47  );
48  }
49 
51  {
52  $this->_configMock->expects($this->once())->method('getValue')->will($this->returnValue('storeCurrency'));
53  $this->assertEquals('storeCurrency', $this->_model->getDefaultCurrency($this->_requestMock));
54  }
55 
57  {
58  $this->_requestMock->expects(
59  $this->any()
60  )->method(
61  'getParam'
62  )->with(
63  'store'
64  )->will(
65  $this->returnValue('someStore')
66  );
67  $storeMock = $this->createMock(\Magento\Store\Model\Store::class);
68  $storeMock->expects($this->once())->method('getBaseCurrencyCode')->will($this->returnValue('storeCurrency'));
69  $this->_storeManagerMock->expects(
70  $this->once()
71  )->method(
72  'getStore'
73  )->with(
74  'someStore'
75  )->will(
76  $this->returnValue($storeMock)
77  );
78  $this->assertEquals('storeCurrency', $this->_model->getDefaultCurrency($this->_requestMock));
79  }
80 
82  {
83  $this->_requestMock->expects(
84  $this->any()
85  )->method(
86  'getParam'
87  )->will(
88  $this->returnValueMap([['store', null, ''], ['website', null, 'someWebsite']])
89  );
90  $websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
91  $websiteMock->expects(
92  $this->once()
93  )->method(
94  'getBaseCurrencyCode'
95  )->will(
96  $this->returnValue('websiteCurrency')
97  );
98  $this->_storeManagerMock->expects(
99  $this->once()
100  )->method(
101  'getWebsite'
102  )->with(
103  'someWebsite'
104  )->will(
105  $this->returnValue($websiteMock)
106  );
107  $this->assertEquals('websiteCurrency', $this->_model->getDefaultCurrency($this->_requestMock));
108  }
109 
111  {
112  $this->_requestMock->expects(
113  $this->any()
114  )->method(
115  'getParam'
116  )->will(
117  $this->returnValueMap(
118  [['store', null, ''], ['website', null, ''], ['group', null, 'someGroup']]
119  )
120  );
121  $websiteMock = $this->createMock(\Magento\Store\Model\Website::class);
122  $websiteMock->expects(
123  $this->once()
124  )->method(
125  'getBaseCurrencyCode'
126  )->will(
127  $this->returnValue('websiteCurrency')
128  );
129 
130  $groupMock = $this->createMock(\Magento\Store\Model\Group::class);
131  $groupMock->expects($this->once())->method('getWebsite')->will($this->returnValue($websiteMock));
132 
133  $this->_storeManagerMock->expects(
134  $this->once()
135  )->method(
136  'getGroup'
137  )->with(
138  'someGroup'
139  )->will(
140  $this->returnValue($groupMock)
141  );
142  $this->assertEquals('websiteCurrency', $this->_model->getDefaultCurrency($this->_requestMock));
143  }
144 }