diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2021-04-05 15:13:30 +0200 |
---|---|---|
committer | Sean Molenaar <SMillerDev@users.noreply.github.com> | 2021-04-05 19:18:19 +0200 |
commit | 951f3eb7eefae9b7236517a2eca8fcbfe77567b2 (patch) | |
tree | fafe57eb7d65515e0d3478bb3066c14524b58feb /tests/Unit/Db | |
parent | 5264713b50be83d022b15cd0431134972af25c36 (diff) |
DB: Allow negative limits
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Db')
-rw-r--r-- | tests/Unit/Db/ItemMapperPaginatedTest.php | 223 |
1 files changed, 223 insertions, 0 deletions
diff --git a/tests/Unit/Db/ItemMapperPaginatedTest.php b/tests/Unit/Db/ItemMapperPaginatedTest.php index 6bd6906d3..93521f541 100644 --- a/tests/Unit/Db/ItemMapperPaginatedTest.php +++ b/tests/Unit/Db/ItemMapperPaginatedTest.php @@ -259,6 +259,75 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->assertEquals([Item::fromRow(['id' => 4])], $result); } + public function testFindAllItemsUnreadNoLimit() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['feeds.deleted_at = 0'], + ['items.id < :offset'], + ['items.unread = 1'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['offset', 10]) + ->will($this->returnSelf()); + + $this->builder->expects($this->never()) + ->method('setMaxResults'); + + $this->builder->expects($this->exactly(0)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.last_modified', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllItems('jack', 6, -1, 10, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + public function testFindAllItemsStarred() { $this->db->expects($this->once()) @@ -482,6 +551,77 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->assertEquals([Item::fromRow(['id' => 4])], $result); } + public function testFindAllFeedNoLimit() + { + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.deleted_at = 0'], + ['feeds.user_id = :userId'], + ['items.feed_id = :feedId'], + ['items.id < :offset'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(3)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['feedId', 2], ['offset', 10]) + ->will($this->returnSelf()); + + + $this->builder->expects($this->never()) + ->method('setMaxResults'); + + + $this->builder->expects($this->exactly(0)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.last_modified', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFeed('jack', 2, -1, 10, false, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + public function testFindAllFeedInverted() { $this->db->expects($this->once()) @@ -796,6 +936,89 @@ class ItemMapperPaginatedTest extends MapperTestUtility $this->assertEquals([Item::fromRow(['id' => 4])], $result); } + public function testFindAllFolderIdNullNoLimit() + { + $expr = $this->getMockBuilder(IExpressionBuilder::class) + ->getMock(); + + $expr->expects($this->once()) + ->method('isNull') + ->with('feeds.folder_id') + ->will($this->returnValue('x IS NULL')); + + $this->db->expects($this->once()) + ->method('getQueryBuilder') + ->willReturn($this->builder); + + $this->builder->expects($this->exactly(1)) + ->method('expr') + ->will($this->returnValue($expr)); + + $this->builder->expects($this->once()) + ->method('select') + ->with('items.*') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('from') + ->with('news_items', 'items') + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(1)) + ->method('innerJoin') + ->withConsecutive(['items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id']) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(4)) + ->method('andWhere') + ->withConsecutive( + ['feeds.user_id = :userId'], + ['feeds.deleted_at = 0'], + ['x IS NULL'], + ['items.id < :offset'] + ) + ->will($this->returnSelf()); + + $this->builder->expects($this->exactly(2)) + ->method('setParameter') + ->withConsecutive(['userId', 'jack'], ['offset', 10]) + ->will($this->returnSelf()); + + + $this->builder->expects($this->never(1)) + ->method('setMaxResults'); + + + $this->builder->expects($this->exactly(0)) + ->method('setFirstResult') + ->with(10) + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('orderBy') + ->with('items.last_modified', 'DESC') + ->will($this->returnSelf()); + + $this->builder->expects($this->once()) + ->method('addOrderBy') + ->with('items.id', 'DESC') + ->willReturnSelf(); + + $this->builder->expects($this->exactly(1)) + ->method('execute') + ->will($this->returnValue($this->cursor)); + + $this->cursor->expects($this->exactly(2)) + ->method('fetch') + ->willReturnOnConsecutiveCalls( + ['id' => 4], + false + ); + + $result = $this->class->findAllFolder('jack', null, -1, 10, false, false, []); + $this->assertEquals([Item::fromRow(['id' => 4])], $result); + } + public function testFindAllFolderHideRead() { $expr = $this->getMockBuilder(IExpressionBuilder::class) |