Ejemplo n.º 1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testGetItems()
 {
     $this->category->expects($this->any())->method('getIsActive')->will($this->returnValue(true));
     $category1 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock();
     $category1->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(120));
     $category1->expects($this->once())->method('getName')->will($this->returnValue('Category 1'));
     $category1->expects($this->once())->method('getIsActive')->will($this->returnValue(true));
     $category2 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock();
     $category2->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(5641));
     $category2->expects($this->once())->method('getName')->will($this->returnValue('Category 2'));
     $category2->expects($this->once())->method('getIsActive')->will($this->returnValue(true));
     $category3 = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Category')->disableOriginalConstructor()->setMethods(['getId', 'getName', 'getIsActive'])->getMock();
     $category3->expects($this->atLeastOnce())->method('getId')->will($this->returnValue(777));
     $category3->expects($this->never())->method('getName');
     $category3->expects($this->once())->method('getIsActive')->will($this->returnValue(true));
     $categories = [$category1, $category2, $category3];
     $this->category->expects($this->once())->method('getChildrenCategories')->will($this->returnValue($categories));
     $facetedData = [120 => ['count' => 10], 5641 => ['count' => 45], 777 => ['count' => 80]];
     $this->fulltextCollection->expects($this->once())->method('getSize')->will($this->returnValue(50));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->with('category')->will($this->returnValue($facetedData));
     $builtData = [['label' => 'Category 1', 'value' => 120, 'count' => 10], ['label' => 'Category 2', 'value' => 5641, 'count' => 45]];
     $this->itemDataBuilder->expects($this->at(0))->method('addItemData')->with('Category 1', 120, 10)->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->at(1))->method('addItemData')->with('Category 2', 5641, 45)->will($this->returnSelf());
     $this->itemDataBuilder->expects($this->once())->method('build')->will($this->returnValue($builtData));
     $this->target->getItems();
 }
Ejemplo n.º 2
0
 public function testGetItems()
 {
     $this->target->setAttributeModel($this->attribute);
     $attributeCode = 'attributeCode';
     $this->attribute->expects($this->any())->method('getAttributeCode')->will($this->returnValue($attributeCode));
     $this->fulltextCollection->expects($this->once())->method('getFacetedData')->with($attributeCode)->will($this->returnValue([]));
     $this->target->getItems();
 }
Ejemplo n.º 3
0
 public function testApply()
 {
     $categoryId = 123;
     $requestVar = 'test_request_var';
     $this->target->setRequestVar($requestVar);
     $this->request->expects($this->any())->method('getParam')->will($this->returnCallback(function ($field) use($requestVar, $categoryId) {
         $this->assertTrue(in_array($field, [$requestVar, 'id']));
         return $categoryId;
     }));
     $this->dataProvider->expects($this->once())->method('setCategoryId')->with($categoryId)->will($this->returnSelf());
     $this->category->expects($this->once())->method('getId')->will($this->returnValue($categoryId));
     $this->collection->expects($this->once())->method('addCategoryFilter')->with($this->category)->will($this->returnSelf());
     $this->target->apply($this->request);
 }
Ejemplo n.º 4
0
 /**
  * @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->attribute->expects($this->at(3))->method('getIsFilterable')->will($this->returnValue(1));
     $this->attribute->expects($this->at(4))->method('getIsFilterable')->will($this->returnValue(2));
     $this->attribute->expects($this->at(5))->method('getIsFilterable')->will($this->returnValue(1));
     $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);
 }
Ejemplo n.º 5
0
 /**
  * @expectedException \Exception
  * @expectedExceptionCode 333
  * @expectedExceptionMessage setRequestName
  */
 public function testGetFacetedData()
 {
     $this->model->getFacetedData('field');
 }
Ejemplo n.º 6
0
 public function testItemData()
 {
     $this->fulltextCollection->expects($this->any())->method('getSize')->willReturn(5);
     $this->fulltextCollection->expects($this->any())->method('getFacetedData')->willReturn(['2_10' => ['count' => 5], '*_*' => ['count' => 2]]);
     $this->assertEquals([$this->filterItem], $this->target->getItems());
 }