Пример #1
0
 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->request = $this->getMockBuilder('\\Magento\\Framework\\App\\RequestInterface')->disableOriginalConstructor()->setMethods(['getParam'])->getMockForAbstractClass();
     $dataProviderFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\PriceFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->dataProvider = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\DataProvider\\Price')->disableOriginalConstructor()->setMethods(['setPriceId', 'getPrice', 'getResource'])->getMock();
     $this->resource = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Resource\\Layer\\Filter\\Price')->disableOriginalConstructor()->setMethods(['applyPriceRange'])->getMock();
     $this->dataProvider->expects($this->any())->method('getResource')->will($this->returnValue($this->resource));
     $dataProviderFactory->expects($this->once())->method('create')->will($this->returnValue($this->dataProvider));
     $this->layer = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer')->disableOriginalConstructor()->setMethods(['getState'])->getMock();
     $this->state = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\State')->disableOriginalConstructor()->setMethods(['addFilter'])->getMock();
     $this->layer->expects($this->any())->method('getState')->will($this->returnValue($this->state));
     $this->itemDataBuilder = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item\\DataBuilder')->disableOriginalConstructor()->setMethods(['addItemData', 'build'])->getMock();
     $this->filterItemFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\ItemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $filterItem = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Item')->disableOriginalConstructor()->setMethods(['setFilter', 'setLabel', 'setValue', 'setCount'])->getMock();
     $filterItem->expects($this->any())->method($this->anything())->will($this->returnSelf());
     $this->filterItemFactory->expects($this->any())->method('create')->will($this->returnValue($filterItem));
     $escaper = $this->getMockBuilder('\\Magento\\Framework\\Escaper')->disableOriginalConstructor()->setMethods(['escapeHtml'])->getMock();
     $escaper->expects($this->any())->method('escapeHtml')->will($this->returnArgument(0));
     $this->attribute = $this->getMockBuilder('\\Magento\\Eav\\Model\\Entity\\Attribute')->disableOriginalConstructor()->setMethods(['getAttributeCode', 'getFrontend', 'getIsFilterable'])->getMock();
     $algorithmFactory = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\AlgorithmFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->algorithm = $this->getMockBuilder('\\Magento\\Catalog\\Model\\Layer\\Filter\\Dynamic\\Auto')->disableOriginalConstructor()->setMethods(['getItemsData'])->getMock();
     $algorithmFactory->expects($this->any())->method('create')->will($this->returnValue($this->algorithm));
     $objectManagerHelper = new ObjectManagerHelper($this);
     $this->target = $objectManagerHelper->getObject('Magento\\Catalog\\Model\\Layer\\Filter\\Price', ['dataProviderFactory' => $dataProviderFactory, 'layer' => $this->layer, 'itemDataBuilder' => $this->itemDataBuilder, 'filterItemFactory' => $this->filterItemFactory, 'escaper' => $escaper, 'algorithmFactory' => $algorithmFactory]);
 }
Пример #2
0
 public function testGetRangeItemCounts()
 {
     $range = 10;
     $count = [50, 20, 20];
     $this->resource->expects($this->once())->method('getCount')->with($range)->will($this->returnValue($count));
     $this->assertSame($count, $this->target->getRangeItemCounts($range));
 }
Пример #3
0
 /**
  * @SuppressWarnings(PHPMD.CamelCaseMethodName)
  *
  * {@inheritDoc}
  */
 protected function _renderRangeLabel($fromPrice, $toPrice)
 {
     $formattedPrice = $this->priceCurrency->format($fromPrice);
     if ($toPrice === '') {
         $formattedPrice = __('%1 and above', $formattedPrice);
     } elseif ($fromPrice != $toPrice || !$this->dataProvider->getOnePriceIntervalValue()) {
         $formattedPrice = __('%1 - %2', $formattedPrice, $this->priceCurrency->format($toPrice));
     }
     return $formattedPrice;
 }
Пример #4
0
 /**
  * @param string $key
  * @param int $count
  * @return array
  */
 private function prepareData($key, $count)
 {
     list($from, $to) = explode('_', $key);
     if ($from == '*') {
         $from = $this->getFrom($to);
     }
     if ($to == '*') {
         $to = $this->getTo($to);
     }
     $label = $this->_renderRangeLabel(empty($from) ? 0 : $from * $this->getCurrencyRate(), empty($to) ? $to : $to * $this->getCurrencyRate());
     $value = $from . '-' . $to . $this->dataProvider->getAdditionalRequestData();
     $data = ['label' => $label, 'value' => $value, 'count' => $count, 'from' => $from, 'to' => $to];
     return $data;
 }
Пример #5
0
 /**
  * @dataProvider getRangeItemCountsDataProvider
  */
 public function testGetRangeItemCounts($inputRange, $expectedItemCounts)
 {
     $actualItemCounts = $this->_model->getRangeItemCounts($inputRange);
     $this->assertEquals($expectedItemCounts, $actualItemCounts);
 }