/** * @dataProvider pricesSegmentationDataProvider */ public function testPricesSegmentation($categoryId, $intervalsNumber, $intervalItems) { $this->_layer->setCurrentCategory($categoryId); $collection = $this->_layer->getProductCollection(); $memoryUsedBefore = memory_get_usage(); $this->_model->setPricesModel($this->_filter)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getSize()); if (!is_null($intervalsNumber)) { $this->assertEquals($intervalsNumber, $this->_model->getIntervalsNumber()); } $items = $this->_model->calculateSeparators(); $this->assertEquals(array_keys($intervalItems), array_keys($items)); for ($i = 0; $i < count($intervalItems); ++$i) { $this->assertInternalType('array', $items[$i]); $this->assertEquals($intervalItems[$i]['from'], $items[$i]['from']); $this->assertEquals($intervalItems[$i]['to'], $items[$i]['to']); $this->assertEquals($intervalItems[$i]['count'], $items[$i]['count']); } // Algorythm should use less than 10M $this->assertLessThan(10 * 1024 * 1024, memory_get_usage() - $memoryUsedBefore); }
public function testWithLimits() { $this->markTestIncomplete('Bug MAGE-6561'); /** @var $objectManager \Magento\TestFramework\ObjectManager */ $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); /** @var $request \Magento\TestFramework\Request */ $request = $objectManager->get('Magento\\TestFramework\\Request'); $request->setParam('price', '10-100'); $this->_prepareFilter($request); $this->assertEquals(array(0 => array('from' => 10, 'to' => 20, 'count' => 2), 1 => array('from' => 20, 'to' => 100, 'count' => 2)), $this->_model->calculateSeparators()); }
/** * Get data generated by algorithm for build price filter items * * @return array */ protected function _getCalculatedItemsData() { $collection = $this->getLayer()->getProductCollection(); $appliedInterval = $this->getInterval(); if ($appliedInterval && $collection->getPricesCount() <= $this->getIntervalDivisionLimit()) { return array(); } $this->_priceAlgorithm->setPricesModel($this)->setStatistics($collection->getMinPrice(), $collection->getMaxPrice(), $collection->getPriceStandardDeviation(), $collection->getPricesCount()); if ($appliedInterval) { if ($appliedInterval[0] == $appliedInterval[1] || $appliedInterval[1] === '0') { return array(); } $this->_priceAlgorithm->setLimits($appliedInterval[0], $appliedInterval[1]); } $items = array(); foreach ($this->_priceAlgorithm->calculateSeparators() as $separator) { $items[] = array('label' => $this->_renderRangeLabel($separator['from'], $separator['to']), 'value' => ($separator['from'] == 0 ? '' : $separator['from']) . '-' . $separator['to'] . $this->_getAdditionalRequestData(), 'count' => $separator['count']); } return $items; }