public function testWithLimits() { $this->markTestIncomplete('Bug MAGE-6561'); $request = new Mage_Test_Controller_Request_Http(); $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()); }
/** * @dataProvider pricesSegmentationDataProvider */ public function testPricesSegmentation($prices, $intervalsNumber, $intervalItems) { $this->_model->setPrices($prices); 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']); } }
/** * @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); }
/** * Load all product prices to algorithm model * * @param Mage_Catalog_Model_Layer_Filter_Price_Algorithm $algorithm * @param Mage_Catalog_Model_Layer_Filter_Price $filter * @return array */ public function loadAllPrices($algorithm, $filter) { $select = $this->_getSelect($filter); $connection = $this->_getReadAdapter(); $response = $this->_dispatchPreparePriceEvent($filter, $select); $table = $this->_getIndexTableAlias(); $additional = join('', $response->getAdditionalCalculations()); $maxPriceExpr = new Zend_Db_Expr("({$table}.min_price {$additional}) * " . $connection->quote($filter->getCurrencyRate())); $select->columns(array($maxPriceExpr)); $prices = $connection->fetchCol($select); $algorithm->setPrices($prices); return $prices; }