summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Db/ItemMapperPaginatedTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Db/ItemMapperPaginatedTest.php')
-rw-r--r--tests/Unit/Db/ItemMapperPaginatedTest.php223
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)