Fix #1205 Fix calculation of current page

This commit is contained in:
Nicolas Le Goff
2013-06-17 19:07:56 +02:00
parent 4e3496447a
commit 005b3c3231
2 changed files with 30 additions and 2 deletions

View File

@@ -94,7 +94,7 @@ class SearchEngineResult
*/
public function getCurrentPage($amountPerPage)
{
return ceil($this->offsetStart / $amountPerPage);
return max(1, ceil(($this->offsetStart + 1) / $amountPerPage));
}
/**

View File

@@ -19,7 +19,7 @@ class SearchEngineResultTest extends \PhraseanetPHPUnitAbstract
$query = 'Gotainer';
$duration = 1 / 3;
$offsetStart = 24;
$offsetStart = 23;
$available = 25;
$total = 10000;
$error = 'this is an error message';
@@ -49,4 +49,32 @@ class SearchEngineResultTest extends \PhraseanetPHPUnitAbstract
$this->assertEquals($available, $result->getAvailable());
}
public function testWithOffsetStartAtZero()
{
$results = new ArrayCollection(array(
self::$DI['record_24']
));
$query = 'Gotainer';
$duration = 1 / 3;
$offsetStart = 0;
$available = 25;
$total = 10000;
$error = 'this is an error message';
$warning = 'this is a warning message';
$suggestions = new ArrayCollection(array(
new SearchEngineSuggestion($query, 'Richard', 22)
));
$propositions = new ArrayCollection();
$indexes = 'new-index';
$result = new SearchEngineResult($results, $query, $duration,
$offsetStart, $available, $total, $error, $warning,
$suggestions, $propositions, $indexes);
$this->assertEquals(1, $result->getCurrentPage(10));
$this->assertEquals(1, $result->getCurrentPage(25));
$this->assertEquals(1, $result->getCurrentPage(40));
}
}