55 */
66namespace Magento \ConfigurableProduct \Test \Unit \Block \Product \View \Type ;
77
8+ use Magento \Customer \Model \Session ;
9+ use Magento \Framework \App \State ;
10+
811/**
912 * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1013 */
@@ -65,6 +68,11 @@ class ConfigurableTest extends \PHPUnit\Framework\TestCase
6568 */
6669 private $ storeManager ;
6770
71+ /**
72+ * @var \PHPUnit_Framework_MockObject_MockObject
73+ */
74+ private $ customerSession ;
75+
6876 protected function setUp ()
6977 {
7078 $ this ->mockContextObject ();
@@ -92,6 +100,28 @@ protected function setUp()
92100 ->disableOriginalConstructor ()
93101 ->getMock ();
94102
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 );
95125 $ this ->configurableAttributeData = $ this ->getMockBuilder (
96126 \Magento \ConfigurableProduct \Model \ConfigurableAttributeData::class
97127 )
@@ -102,6 +132,10 @@ protected function setUp()
102132 ->disableOriginalConstructor ()
103133 ->getMock ();
104134
135+ $ this ->customerSession = $ this ->getMockBuilder (Session::class)
136+ ->disableOriginalConstructor ()
137+ ->getMock ();
138+
105139 $ this ->block = new \Magento \ConfigurableProduct \Block \Product \View \Type \Configurable (
106140 $ this ->context ,
107141 $ this ->arrayUtils ,
@@ -112,10 +146,92 @@ protected function setUp()
112146 $ this ->priceCurrency ,
113147 $ this ->configurableAttributeData ,
114148 [],
115- $ this ->localeFormat
149+ $ this ->localeFormat ,
150+ $ this ->customerSession
116151 );
117152 }
118153
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+
119235 /**
120236 * Check that getJsonConfig() method returns expected value
121237 */
0 commit comments