Пример #1
0
 protected function setUp()
 {
     /** @var $attribute \Magento\Catalog\Model\Entity\Attribute */
     $attribute = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Entity\\Attribute');
     $attribute->loadByCode('catalog_product', 'attribute_with_option');
     foreach ($attribute->getSource()->getAllOptions() as $optionInfo) {
         if ($optionInfo['label'] == 'Option Label') {
             $this->_attributeOptionId = $optionInfo['value'];
             break;
         }
     }
     $this->_layer = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Layer\\Category');
     $this->_model = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create('Magento\\CatalogSearch\\Model\\Layer\\Filter\\Attribute', ['layer' => $this->_layer]);
     $this->_model->setAttributeModel($attribute);
     $this->_model->setRequestVar('attribute');
 }
Пример #2
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsIfFacetedDataIsEmpty()
 {
     $attributeCode = 'attributeCode';
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->atLeastOnce())->method('getIsFilterable')->willReturn(0);
     $this->target->setAttributeModel($this->attribute);
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->willReturn([]);
     $this->itemDataBuilder->expects($this->once())->method('build')->willReturn([]);
     $this->assertEquals([], $this->target->getItems());
 }
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItemsWithoutApply()
 {
     $attributeCode = 'attributeCode';
     $selectedOptions = [['label' => 'selectedOptionLabel1', 'value' => 'selectedOptionValue1', 'count' => 25], ['label' => 'selectedOptionLabel2', 'value' => 'selectedOptionValue2', 'count' => 13], ['label' => 'selectedOptionLabel3', 'value' => 'selectedOptionValue3', 'count' => 10]];
     $facetedData = ['selectedOptionValue1' => ['count' => 10], 'selectedOptionValue2' => ['count' => 45], 'selectedOptionValue3' => ['count' => 50]];
     $builtData = [['label' => $selectedOptions[0]['label'], 'value' => $selectedOptions[0]['value'], 'count' => $facetedData[$selectedOptions[0]['value']]['count']], ['label' => $selectedOptions[1]['label'], 'value' => $selectedOptions[1]['value'], 'count' => $facetedData[$selectedOptions[1]['value']]['count']], ['label' => $selectedOptions[2]['label'], 'value' => $selectedOptions[2]['value'], 'count' => $facetedData[$selectedOptions[2]['value']]['count']]];
     $this->attribute->expects($this->exactly(2))->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->target->setAttributeModel($this->attribute);
     $this->frontend->expects($this->once())->method('getSelectOptions')->will($this->returnValue($selectedOptions));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->will($this->returnValue($facetedData));
     $this->itemDataBuilder->expects($this->at(0))->method('addItemData')->with($selectedOptions[0]['label'], $selectedOptions[0]['value'], $facetedData[$selectedOptions[0]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->at(1))->method('addItemData')->with($selectedOptions[1]['label'], $selectedOptions[1]['value'], $facetedData[$selectedOptions[1]['value']]['count'])->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->once())->method('build')->will($this->returnValue($builtData));
     $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50));
     $expectedFilterItems = [$this->createFilterItem(0, $builtData[0]['label'], $builtData[0]['value'], $builtData[0]['count']), $this->createFilterItem(1, $builtData[1]['label'], $builtData[1]['value'], $builtData[1]['count']), $this->createFilterItem(2, $builtData[2]['label'], $builtData[2]['value'], $builtData[2]['count'])];
     $result = $this->target->getItems();
     $this->assertEquals($expectedFilterItems, $result);
 }