|
6 | 6 |
|
7 | 7 | namespace Magento\CatalogSearch\Test\Unit\Model\Layer\Filter;
|
8 | 8 |
|
| 9 | +use Magento\Catalog\Model\Layer\Filter\AbstractFilter; |
9 | 10 | use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
|
10 | 11 | use PHPUnit_Framework_MockObject_MockObject as MockObject;
|
11 | 12 |
|
@@ -104,9 +105,6 @@ protected function setUp()
|
104 | 105 | ->disableOriginalConstructor()
|
105 | 106 | ->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])
|
106 | 107 | ->getMock();
|
107 |
| - $this->attribute->expects($this->atLeastOnce()) |
108 |
| - ->method('getFrontend') |
109 |
| - ->will($this->returnValue($this->frontend)); |
110 | 108 |
|
111 | 109 | $this->request = $this->getMockBuilder('\Magento\Framework\App\RequestInterface')
|
112 | 110 | ->setMethods(['getParam'])
|
@@ -143,6 +141,9 @@ public function testApplyFilter()
|
143 | 141 | $this->attribute->expects($this->exactly(2))
|
144 | 142 | ->method('getAttributeCode')
|
145 | 143 | ->will($this->returnValue($attributeCode));
|
| 144 | + $this->attribute->expects($this->atLeastOnce()) |
| 145 | + ->method('getFrontend') |
| 146 | + ->will($this->returnValue($this->frontend)); |
146 | 147 |
|
147 | 148 | $this->target->setAttributeModel($this->attribute);
|
148 | 149 |
|
@@ -202,6 +203,9 @@ public function testGetItemsWithApply()
|
202 | 203 | $this->attribute->expects($this->exactly(2))
|
203 | 204 | ->method('getAttributeCode')
|
204 | 205 | ->will($this->returnValue($attributeCode));
|
| 206 | + $this->attribute->expects($this->atLeastOnce()) |
| 207 | + ->method('getFrontend') |
| 208 | + ->will($this->returnValue($this->frontend)); |
205 | 209 |
|
206 | 210 | $this->target->setAttributeModel($this->attribute);
|
207 | 211 |
|
@@ -283,6 +287,9 @@ public function testGetItemsWithoutApply()
|
283 | 287 | $this->attribute->expects($this->exactly(2))
|
284 | 288 | ->method('getAttributeCode')
|
285 | 289 | ->will($this->returnValue($attributeCode));
|
| 290 | + $this->attribute->expects($this->atLeastOnce()) |
| 291 | + ->method('getFrontend') |
| 292 | + ->will($this->returnValue($this->frontend)); |
286 | 293 |
|
287 | 294 | $this->target->setAttributeModel($this->attribute);
|
288 | 295 |
|
@@ -329,6 +336,105 @@ public function testGetItemsWithoutApply()
|
329 | 336 | $this->assertEquals($expectedFilterItems, $result);
|
330 | 337 | }
|
331 | 338 |
|
| 339 | + /** |
| 340 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 341 | + */ |
| 342 | + public function testGetItemsOnlyWithResults() |
| 343 | + { |
| 344 | + $attributeCode = 'attributeCode'; |
| 345 | + $selectedOptions = [ |
| 346 | + [ |
| 347 | + 'label' => 'selectedOptionLabel1', |
| 348 | + 'value' => 'selectedOptionValue1', |
| 349 | + ], |
| 350 | + [ |
| 351 | + 'label' => 'selectedOptionLabel2', |
| 352 | + 'value' => 'selectedOptionValue2', |
| 353 | + ], |
| 354 | + ]; |
| 355 | + $facetedData = [ |
| 356 | + 'selectedOptionValue1' => ['count' => 10], |
| 357 | + 'selectedOptionValue2' => ['count' => 0], |
| 358 | + ]; |
| 359 | + $builtData = [ |
| 360 | + [ |
| 361 | + 'label' => $selectedOptions[0]['label'], |
| 362 | + 'value' => $selectedOptions[0]['value'], |
| 363 | + 'count' => $facetedData[$selectedOptions[0]['value']]['count'], |
| 364 | + ], |
| 365 | + ]; |
| 366 | + |
| 367 | + $this->attribute->expects($this->atLeastOnce()) |
| 368 | + ->method('getAttributeCode') |
| 369 | + ->willReturn($attributeCode); |
| 370 | + $this->attribute->expects($this->atLeastOnce()) |
| 371 | + ->method('getIsFilterable') |
| 372 | + ->willReturn(AbstractFilter::ATTRIBUTE_OPTIONS_ONLY_WITH_RESULTS); |
| 373 | + $this->attribute->expects($this->atLeastOnce()) |
| 374 | + ->method('getFrontend') |
| 375 | + ->will($this->returnValue($this->frontend)); |
| 376 | + |
| 377 | + $this->target->setAttributeModel($this->attribute); |
| 378 | + |
| 379 | + $this->frontend->expects($this->once()) |
| 380 | + ->method('getSelectOptions') |
| 381 | + ->willReturn($selectedOptions); |
| 382 | + |
| 383 | + $this->fulltextCollection->expects($this->once()) |
| 384 | + ->method('getFacetedData') |
| 385 | + ->willReturn($facetedData); |
| 386 | + $this->fulltextCollection->expects($this->once()) |
| 387 | + ->method('getSize') |
| 388 | + ->will($this->returnValue(50)); |
| 389 | + |
| 390 | + $this->itemDataBuilder->expects($this->once()) |
| 391 | + ->method('addItemData') |
| 392 | + ->with( |
| 393 | + $selectedOptions[0]['label'], |
| 394 | + $selectedOptions[0]['value'], |
| 395 | + $facetedData[$selectedOptions[0]['value']]['count'] |
| 396 | + ) |
| 397 | + ->will($this->returnSelf()); |
| 398 | + |
| 399 | + $this->itemDataBuilder->expects($this->once()) |
| 400 | + ->method('build') |
| 401 | + ->willReturn($builtData); |
| 402 | + |
| 403 | + $expectedFilterItems = [ |
| 404 | + $this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']), |
| 405 | + ]; |
| 406 | + $result = $this->target->getItems(); |
| 407 | + |
| 408 | + $this->assertEquals($expectedFilterItems, $result); |
| 409 | + } |
| 410 | + |
| 411 | + /** |
| 412 | + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) |
| 413 | + */ |
| 414 | + public function testGetItemsIfFacetedDataIsEmpty() |
| 415 | + { |
| 416 | + $attributeCode = 'attributeCode'; |
| 417 | + |
| 418 | + $this->attribute->expects($this->atLeastOnce()) |
| 419 | + ->method('getAttributeCode') |
| 420 | + ->willReturn($attributeCode); |
| 421 | + $this->attribute->expects($this->atLeastOnce()) |
| 422 | + ->method('getIsFilterable') |
| 423 | + ->willReturn(0); |
| 424 | + |
| 425 | + $this->target->setAttributeModel($this->attribute); |
| 426 | + |
| 427 | + $this->fulltextCollection->expects($this->once()) |
| 428 | + ->method('getFacetedData') |
| 429 | + ->willReturn([]); |
| 430 | + |
| 431 | + $this->itemDataBuilder->expects($this->once()) |
| 432 | + ->method('build') |
| 433 | + ->willReturn([]); |
| 434 | + |
| 435 | + $this->assertEquals([], $this->target->getItems()); |
| 436 | + } |
| 437 | + |
332 | 438 | /**
|
333 | 439 | * @param int $index
|
334 | 440 | * @param string $label
|
|
0 commit comments