@@ -69,8 +69,13 @@ protected function setUp()
69
69
70
70
$ this ->request = $ this ->getMockBuilder ('\Magento\Framework\Search\RequestInterface ' )
71
71
->disableOriginalConstructor ()
72
- ->setMethods (['getIndex ' , 'getDimensions ' ])
72
+ ->setMethods (['getIndex ' , 'getDimensions ' , ' getQuery ' ])
73
73
->getMockForAbstractClass ();
74
+ $ this ->request ->expects ($ this ->once ())
75
+ ->method ('getQuery ' )
76
+ ->willReturn (
77
+ $ this ->getMockBuilder ('Magento\Framework\Search\Request\QueryInterface ' )->getMockForAbstractClass ()
78
+ );
74
79
75
80
$ this ->config = $ this ->getMockBuilder ('\Magento\Framework\App\Config\ScopeConfigInterface ' )
76
81
->disableOriginalConstructor ()
@@ -157,7 +162,7 @@ public function testBuildWithoutOutOfStock()
157
162
->method ('getDimensions ' )
158
163
->willReturn ($ dimensions );
159
164
160
- $ this ->mockBuild ($ index , $ tableSuffix );
165
+ $ this ->mockBuild ($ index , $ tableSuffix, false );
161
166
162
167
$ this ->config ->expects ($ this ->once ())
163
168
->method ('isSetFlag ' )
@@ -168,11 +173,11 @@ public function testBuildWithoutOutOfStock()
168
173
$ website = $ this ->getMockBuilder ('Magento\Store\Model\Website ' )->disableOriginalConstructor ()->getMock ();
169
174
$ website ->expects ($ this ->once ())->method ('getId ' )->willReturn (1 );
170
175
$ this ->storeManager ->expects ($ this ->once ())->method ('getWebsite ' )->willReturn ($ website );
171
- $ this ->select ->expects ($ this ->at (4 ))
176
+ $ this ->select ->expects ($ this ->at (2 ))
172
177
->method ('where ' )
173
178
->with ('(someName=someValue) ' )
174
179
->willReturnSelf ();
175
- $ this ->select ->expects ($ this ->at (5 ))
180
+ $ this ->select ->expects ($ this ->at (3 ))
176
181
->method ('joinLeft ' )
177
182
->with (
178
183
['stock_index ' => 'cataloginventory_stock_status ' ],
@@ -181,7 +186,7 @@ public function testBuildWithoutOutOfStock()
181
186
[]
182
187
)
183
188
->willReturnSelf ();
184
- $ this ->select ->expects ($ this ->at (6 ))
189
+ $ this ->select ->expects ($ this ->at (4 ))
185
190
->method ('where ' )
186
191
->with ('stock_index.stock_status = ? ' , 1 )
187
192
->will ($ this ->returnSelf ());
@@ -190,7 +195,7 @@ public function testBuildWithoutOutOfStock()
190
195
$ this ->assertSame ($ this ->select , $ result );
191
196
}
192
197
193
- protected function mockBuild ($ index , $ tableSuffix )
198
+ protected function mockBuild ($ index , $ tableSuffix, $ hasFilters = false )
194
199
{
195
200
$ this ->request ->expects ($ this ->atLeastOnce ())
196
201
->method ('getIndex ' )
@@ -220,7 +225,7 @@ function ($index, $dimensions) {
220
225
)
221
226
);
222
227
223
- $ this ->select ->expects ($ this ->once ( ))
228
+ $ this ->select ->expects ($ this ->at ( 0 ))
224
229
->method ('from ' )
225
230
->with (
226
231
['search_index ' => $ index . '_ ' . $ tableSuffix ],
@@ -229,30 +234,31 @@ function ($index, $dimensions) {
229
234
->will ($ this ->returnSelf ());
230
235
231
236
$ this ->select ->expects ($ this ->at (1 ))
232
- ->method ('joinLeft ' )
233
- ->with (
234
- ['category_index ' => 'catalog_category_product_index ' ],
235
- 'search_index.entity_id = category_index.product_id ' ,
236
- []
237
- )
238
- ->will ($ this ->returnSelf ());
239
-
240
- $ this ->select ->expects ($ this ->at (2 ))
241
237
->method ('joinLeft ' )
242
238
->with (
243
239
['cea ' => 'catalog_eav_attribute ' ],
244
240
'search_index.attribute_id = cea.attribute_id ' ,
245
241
[]
246
242
)
247
243
->will ($ this ->returnSelf ());
248
- $ this ->select ->expects ($ this ->at (3 ))
249
- ->method ('joinLeft ' )
250
- ->with (
251
- ['cpie ' => $ this ->resource ->getTableName ('catalog_product_index_eav ' )],
252
- 'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id ' ,
253
- []
254
- )
255
- ->willReturnSelf ();
244
+ if ($ hasFilters ) {
245
+ $ this ->select ->expects ($ this ->at (2 ))
246
+ ->method ('joinLeft ' )
247
+ ->with (
248
+ ['category_index ' => 'catalog_category_product_index ' ],
249
+ 'search_index.entity_id = category_index.product_id ' ,
250
+ []
251
+ )
252
+ ->will ($ this ->returnSelf ());
253
+ $ this ->select ->expects ($ this ->at (3 ))
254
+ ->method ('joinLeft ' )
255
+ ->with (
256
+ ['cpie ' => $ this ->resource ->getTableName ('catalog_product_index_eav ' )],
257
+ 'search_index.entity_id = cpie.entity_id AND search_index.attribute_id = cpie.attribute_id ' ,
258
+ []
259
+ )
260
+ ->willReturnSelf ();
261
+ }
256
262
}
257
263
258
264
/**
0 commit comments