@@ -102,10 +102,7 @@ protected function setUp(): void
102102 ->onlyMethods (['getState ' , 'getProductCollection ' ])
103103 ->getMock ();
104104
105- $ this ->state = $ this ->getMockBuilder (State::class)
106- ->disableOriginalConstructor ()
107- ->onlyMethods (['addFilter ' ])
108- ->getMock ();
105+ $ this ->state = new State ();
109106 $ this ->layer ->expects ($ this ->any ())
110107 ->method ('getState ' )
111108 ->willReturn ($ this ->state );
@@ -129,15 +126,24 @@ protected function setUp(): void
129126 ->onlyMethods (['create ' ])
130127 ->getMock ();
131128
132- $ filterItem = $ this ->getMockBuilder (Item::class)
133- ->disableOriginalConstructor ()
134- ->addMethods (['setFilter ' , 'setLabel ' , 'setValue ' , 'setCount ' ])
135- ->getMock ();
136- $ filterItem ->expects ($ this ->any ())
137- ->method ($ this ->anything ())->willReturnSelf ();
138129 $ this ->filterItemFactory ->expects ($ this ->any ())
139130 ->method ('create ' )
140- ->willReturn ($ filterItem );
131+ ->willReturnCallback (
132+ function (array $ data ) {
133+ return new Item (
134+ $ this ->createMock (\Magento \Framework \UrlInterface::class),
135+ $ this ->createMock (\Magento \Theme \Block \Html \Pager::class),
136+ $ data
137+ );
138+ }
139+ );
140+ $ priceFormatter = $ this ->createMock (\Magento \Framework \Pricing \PriceCurrencyInterface::class);
141+ $ priceFormatter ->method ('format ' )
142+ ->willReturnCallback (
143+ function ($ number ) {
144+ return sprintf ('$%01.2f ' , $ number );
145+ }
146+ );
141147
142148 $ escaper = $ this ->getMockBuilder (Escaper::class)
143149 ->disableOriginalConstructor ()
@@ -160,7 +166,8 @@ protected function setUp(): void
160166 'layer ' => $ this ->layer ,
161167 'itemDataBuilder ' => $ this ->itemDataBuilder ,
162168 'filterItemFactory ' => $ this ->filterItemFactory ,
163- 'escaper ' => $ escaper
169+ 'escaper ' => $ escaper ,
170+ 'priceCurrency ' => $ priceFormatter ,
164171 ]
165172 );
166173 }
@@ -181,7 +188,13 @@ public function testApplyWithEmptyRequest(?int $requestValue, $idValue): void
181188
182189 $ this ->request
183190 ->method ('getParam ' )
184- ->with ($ requestField );
191+ ->with ($ requestField )
192+ ->willReturnMap (
193+ [
194+ [$ requestField , $ requestValue ],
195+ [$ idField , $ idValue ],
196+ ]
197+ );
185198
186199 $ result = $ this ->target ->apply ($ this ->request );
187200 $ this ->assertSame ($ this ->target , $ result );
@@ -209,34 +222,60 @@ public function applyWithEmptyRequestDataProvider(): array
209222 }
210223
211224 /**
212- * @return void
213- */
214- public function testApply (): void
225+ * @dataProvider applyDataProvider
226+ */
227+ public function testApply (string $ filter , array $ expected ): void
215228 {
216- $ priceId = '15-50 ' ;
217- $ requestVar = 'test_request_var ' ;
218-
219- $ this ->target ->setRequestVar ($ requestVar );
229+ $ requestVar = 'price ' ;
220230 $ this ->request ->expects ($ this ->exactly (1 ))
221231 ->method ('getParam ' )
222- ->willReturnCallback (
223- function ($ field ) use ($ requestVar , $ priceId ) {
224- $ this ->assertContains ($ field , [$ requestVar , 'id ' ]);
225- return $ priceId ;
226- }
227- );
232+ ->with ($ requestVar )
233+ ->willReturn ($ filter );
228234
229235 $ this ->fulltextCollection ->expects ($ this ->once ())
230236 ->method ('addFieldToFilter ' )
231237 ->with ('price ' )->willReturnSelf ();
232238
233239 $ this ->target ->setCurrencyRate (1 );
234240 $ this ->target ->apply ($ this ->request );
241+ $ actual = [];
242+ foreach ($ this ->state ->getFilters () as $ item ) {
243+ $ actual [] = ['label ' => $ item ->getLabel (), 'value ' => $ item ->getValue (), 'count ' => $ item ->getCount ()];
244+ }
245+
246+ $ this ->assertEquals ($ expected , $ actual );
235247 }
236248
237249 /**
238- * @return void
239- */
250+ * @return array
251+ */
252+ public function applyDataProvider (): array
253+ {
254+ return [
255+ [
256+ '10-50 ' ,
257+ [
258+ ['label ' => '$10.00 - $49.99 ' , 'value ' => ['10 ' , '50 ' ], 'count ' => '0 ' ],
259+ ]
260+ ],
261+ [
262+ '-50 ' ,
263+ [
264+ ['label ' => '$0.00 - $49.99 ' , 'value ' => ['' , '50 ' ], 'count ' => '0 ' ],
265+ ]
266+ ],
267+ [
268+ '10- ' ,
269+ [
270+ ['label ' => '$10.00 and above ' , 'value ' => ['10 ' , '' ], 'count ' => '0 ' ],
271+ ]
272+ ]
273+ ];
274+ }
275+
276+ /**
277+ * @return void
278+ */
240279 public function testGetItems (): void
241280 {
242281 $ this ->target ->setAttributeModel ($ this ->attribute );
0 commit comments