From 0368e1e3ce51647869a00cd08871a7baf29de19f Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sun, 15 Feb 2015 17:01:00 +0100 Subject: When passing a negative batchSizes to the item API, all items will be returned --- tests/unit/db/ItemMapperTest.php | 57 +++++++++++++++++++++++++++++++------ tests/unit/db/mappertestutility.php | 10 +++++-- 2 files changed, 55 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php index 26c9074dd..adb1dfe7a 100644 --- a/tests/unit/db/ItemMapperTest.php +++ b/tests/unit/db/ItemMapperTest.php @@ -236,7 +236,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFeed($this->id, $this->limit, $this->offset, $this->status, false, $this->user); @@ -244,12 +244,25 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { } + public function testFindAllFeedNegativeLimit(){ + $sql = 'AND `items`.`feed_id` = ? ' . + 'AND `items`.`id` < ? '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = [$this->user, $this->id, $this->offset]; + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAllFeed($this->id, -1, + $this->offset, $this->status, false, $this->user); + + $this->assertEquals($this->items, $result); + } + + public function testFindAllFeedOldestFirst(){ $sql = 'AND `items`.`feed_id` = ? ' . 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFeed($this->id, $this->limit, $this->offset, $this->status, true, $this->user); @@ -261,7 +274,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { $sql = 'AND `items`.`feed_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); $params = [$this->user, $this->id]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFeed($this->id, $this->limit, 0, $this->status, false, $this->user); @@ -274,7 +287,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFolder($this->id, $this->limit, $this->offset, $this->status, false, $this->user); @@ -282,12 +295,26 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { } + public function testFindAllFolderNegativeLimit(){ + $sql = 'AND `feeds`.`folder_id` = ? ' . + 'AND `items`.`id` < ? '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = [$this->user, $this->id, $this->offset]; + $this->setMapperResult($sql, $params, $this->rows); + $result = $this->mapper->findAllFolder($this->id, -1, + $this->offset, $this->status, false, $this->user); + + $this->assertEquals($this->items, $result); + } + + + public function testFindAllFolderOldestFirst(){ $sql = 'AND `feeds`.`folder_id` = ? ' . 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->id, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFolder($this->id, $this->limit, $this->offset, $this->status, true, $this->user); @@ -299,7 +326,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { $sql = 'AND `feeds`.`folder_id` = ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); $params = [$this->user, $this->id]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAllFolder($this->id, $this->limit, 0, $this->status, false, $this->user); @@ -311,7 +338,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { $sql = 'AND `items`.`id` < ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status); $params = [$this->user, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAll($this->limit, $this->offset, $this->status, false, $this->user); @@ -319,11 +346,23 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { } + public function testFindAllNegativeLimit(){ + $sql = 'AND `items`.`id` < ? '; + $sql = $this->makeSelectQueryStatus($sql, $this->status); + $params = [$this->user, $this->offset]; + $this->setMapperResult($sql, $params, $this->rows, null); + $result = $this->mapper->findAll(-1, + $this->offset, $this->status, false, $this->user); + + $this->assertEquals($this->items, $result); + } + + public function testFindAllOldestFirst(){ $sql = 'AND `items`.`id` > ? '; $sql = $this->makeSelectQueryStatus($sql, $this->status, true); $params = [$this->user, $this->offset]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAll($this->limit, $this->offset, $this->status, true, $this->user); @@ -334,7 +373,7 @@ class ItemMapperTest extends \OCA\News\Tests\Unit\Db\MapperTestUtility { public function testFindAllOffsetZero(){ $sql = $this->makeSelectQueryStatus('', $this->status); $params = [$this->user]; - $this->setMapperResult($sql, $params, $this->rows); + $this->setMapperResult($sql, $params, $this->rows, $this->limit); $result = $this->mapper->findAll($this->limit, 0, $this->status, false, $this->user); diff --git a/tests/unit/db/mappertestutility.php b/tests/unit/db/mappertestutility.php index 49e985f3b..278cbc475 100644 --- a/tests/unit/db/mappertestutility.php +++ b/tests/unit/db/mappertestutility.php @@ -68,7 +68,7 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { * of the database query. If not provided, it wont be assumed that fetch * will be called on the result */ - protected function setMapperResult($sql, $arguments=array(), $returnRows=array(), + protected function setMapperResult($sql, $arguments=[], $returnRows=[], $limit=null, $offset=null, $expectClose=false){ $this->iterators[] = new ArgumentIterator($returnRows); @@ -135,12 +135,16 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { if($limit === null && $offset === null) { $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') - ->with($this->equalTo($sql)) + ->with($this->equalTo($sql), + $this->equalTo(null), + $this->equalTo(null)) ->will(($this->returnValue($this->query))); } elseif($limit !== null && $offset === null) { $this->db->expects($this->at($this->prepareAt)) ->method('prepareQuery') - ->with($this->equalTo($sql), $this->equalTo($limit)) + ->with($this->equalTo($sql), + $this->equalTo($limit), + $this->equalTo(null)) ->will(($this->returnValue($this->query))); } elseif($limit === null && $offset !== null) { $this->db->expects($this->at($this->prepareAt)) -- cgit v1.2.3