5
5
*/
6
6
namespace Magento \ConfigurableProduct \Test \Unit \Block \Product \View \Type ;
7
7
8
+ use Magento \Customer \Model \Session ;
9
+ use Magento \Framework \App \State ;
10
+
8
11
/**
9
12
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
10
13
*/
@@ -65,6 +68,11 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
65
68
*/
66
69
private $ storeManager ;
67
70
71
+ /**
72
+ * @var \PHPUnit_Framework_MockObject_MockObject
73
+ */
74
+ private $ customerSession ;
75
+
68
76
protected function setUp ()
69
77
{
70
78
$ this ->mockContextObject ();
@@ -92,6 +100,28 @@ protected function setUp()
92
100
->disableOriginalConstructor ()
93
101
->getMock ();
94
102
103
+ $ appState = $ this ->getMockBuilder (State::class)
104
+ ->disableOriginalConstructor ()
105
+ ->getMock ();
106
+ $ this ->context ->expects ($ this ->once ())
107
+ ->method ('getAppState ' )
108
+ ->willReturn ($ appState );
109
+ $ appState ->expects ($ this ->any ())
110
+ ->method ('getAreaCode ' )
111
+ ->willReturn ('frontend ' );
112
+ $ urlBuilder = $ this ->getMockBuilder (\Magento \Framework \UrlInterface::class)
113
+ ->disableOriginalConstructor ()
114
+ ->getMock ();
115
+ $ this ->context ->expects ($ this ->once ())
116
+ ->method ('getUrlBuilder ' )
117
+ ->willReturn ($ urlBuilder );
118
+ $ fileResolverMock = $ this
119
+ ->getMockBuilder (\Magento \Framework \View \Element \Template \File \Resolver::class)
120
+ ->disableOriginalConstructor ()
121
+ ->getMock ();
122
+ $ this ->context ->expects ($ this ->once ())
123
+ ->method ('getResolver ' )
124
+ ->willReturn ($ fileResolverMock );
95
125
$ this ->configurableAttributeData = $ this ->getMockBuilder (
96
126
\Magento \ConfigurableProduct \Model \ConfigurableAttributeData::class
97
127
)
@@ -102,6 +132,10 @@ protected function setUp()
102
132
->disableOriginalConstructor ()
103
133
->getMock ();
104
134
135
+ $ this ->customerSession = $ this ->getMockBuilder (Session::class)
136
+ ->disableOriginalConstructor ()
137
+ ->getMock ();
138
+
105
139
$ this ->block = new \Magento \ConfigurableProduct \Block \Product \View \Type \Configurable (
106
140
$ this ->context ,
107
141
$ this ->arrayUtils ,
@@ -112,10 +146,92 @@ protected function setUp()
112
146
$ this ->priceCurrency ,
113
147
$ this ->configurableAttributeData ,
114
148
[],
115
- $ this ->localeFormat
149
+ $ this ->localeFormat ,
150
+ $ this ->customerSession
116
151
);
117
152
}
118
153
154
+ /**
155
+ * Provide cache key info
156
+ *
157
+ * @return array
158
+ */
159
+ public function cacheKeyProvider () : array
160
+ {
161
+ return [
162
+ 'without_currency_and_customer_group ' => [
163
+ [
164
+ 0 => 'BLOCK_TPL ' ,
165
+ 1 => 'default ' ,
166
+ 2 => null ,
167
+ 'base_url ' => null ,
168
+ 'template ' => null ,
169
+ 3 => null ,
170
+ 4 => null ,
171
+ ],
172
+ null ,
173
+ null ,
174
+ ],
175
+ 'with_customer_group ' => [
176
+ [
177
+ 0 => 'BLOCK_TPL ' ,
178
+ 1 => 'default ' ,
179
+ 2 => null ,
180
+ 'base_url ' => null ,
181
+ 'template ' => null ,
182
+ 3 => null ,
183
+ 4 => 1 ,
184
+ ],
185
+ null ,
186
+ 1 ,
187
+ ],
188
+ 'with_price_currency ' => [
189
+ [
190
+ 0 => 'BLOCK_TPL ' ,
191
+ 1 => 'default ' ,
192
+ 2 => null ,
193
+ 'base_url ' => null ,
194
+ 'template ' => null ,
195
+ 3 => '$ ' ,
196
+ 4 => null ,
197
+ ],
198
+ '$ ' ,
199
+ null ,
200
+ ]
201
+ ];
202
+ }
203
+
204
+ /**
205
+ * Test cache Tags
206
+ * @dataProvider cacheKeyProvider
207
+ * @param array $expected
208
+ * @param string|null $priceCurrency
209
+ * @param string|null $customerGroupId
210
+ */
211
+ public function testGetCacheKeyInfo (array $ expected , string $ priceCurrency = null , string $ customerGroupId = null )
212
+ {
213
+ $ storeMock = $ this ->getMockBuilder (\Magento \Store \Api \Data \StoreInterface::class)
214
+ ->setMethods ([
215
+ 'getCurrentCurrency ' ,
216
+ ])
217
+ ->getMockForAbstractClass ();
218
+ $ storeMock ->expects ($ this ->any ())
219
+ ->method ('getCode ' )
220
+ ->willReturn ('default ' );
221
+
222
+ $ this ->storeManager ->expects ($ this ->any ())
223
+ ->method ('getStore ' )
224
+ ->willReturn ($ storeMock );
225
+ $ this ->priceCurrency ->expects ($ this ->once ())
226
+ ->method ('getCurrencySymbol ' )
227
+ ->willReturn ($ priceCurrency );
228
+ $ this ->customerSession ->expects ($ this ->once ())
229
+ ->method ('getCustomerGroupId ' )
230
+ ->willReturn ($ customerGroupId );
231
+ $ actual = $ this ->block ->getCacheKeyInfo ();
232
+ $ this ->assertEquals ($ expected , $ actual );
233
+ }
234
+
119
235
/**
120
236
* Check that getJsonConfig() method returns expected value
121
237
*/
0 commit comments