summaryrefslogtreecommitdiffstats
path: root/tests/Unit/Db/FolderMapperTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Unit/Db/FolderMapperTest.php')
-rw-r--r--tests/Unit/Db/FolderMapperTest.php160
1 files changed, 139 insertions, 21 deletions
diff --git a/tests/Unit/Db/FolderMapperTest.php b/tests/Unit/Db/FolderMapperTest.php
index 026c16bc6..ad44d618f 100644
--- a/tests/Unit/Db/FolderMapperTest.php
+++ b/tests/Unit/Db/FolderMapperTest.php
@@ -13,11 +13,14 @@
namespace OCA\News\Tests\Unit\Db;
+use OC\DB\QueryBuilder\Parameter;
+use OC\DB\ResultAdapter;
use OCA\News\Db\Folder;
use OCA\News\Db\FolderMapperV2;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
+use OCP\DB\QueryBuilder\IQueryBuilder;
class FolderMapperTest extends MapperTestUtility
{
@@ -285,39 +288,96 @@ class FolderMapperTest extends MapperTestUtility
*/
public function testRead()
{
- $this->db->expects($this->once())
+ $selectbuilder = $this->getMockBuilder(IQueryBuilder::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->db->expects($this->exactly(2))
->method('getQueryBuilder')
- ->willReturn($this->builder);
+ ->willReturnOnConsecutiveCalls($selectbuilder, $this->builder);
- $this->builder->expects($this->once())
- ->method('update')
+ $selectbuilder->expects($this->once())
+ ->method('select')
+ ->with('items.id')
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->once())
+ ->method('from')
->with('news_items', 'items')
->will($this->returnSelf());
- $this->builder->expects($this->once())
+ $selectbuilder->expects($this->once())
->method('innerJoin')
->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id')
->will($this->returnSelf());
+ $selectbuilder->expects($this->exactly(2))
+ ->method('andWhere')
+ ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId'])
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->exactly(2))
+ ->method('setParameter')
+ ->withConsecutive(['userId', 'admin'], ['folderId', 1])
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->exactly(1))
+ ->method('getSQL')
+ ->will($this->returnValue('SQL QUERY'));
+
+ $selectbuilder->expects($this->exactly(1))
+ ->method('getParameters')
+ ->will($this->returnValue([]));
+
+ $result = $this->getMockBuilder(ResultAdapter::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $result->expects($this->once())
+ ->method('fetchAll')
+ ->willReturn([['id' => 1], ['id' => 2]]);
+
+ $this->db->expects($this->exactly(1))
+ ->method('executeQuery')
+ ->with('SQL QUERY')
+ ->willReturn($result);
+
+ $this->builder->expects($this->once())
+ ->method('createParameter')
+ ->will($this->returnArgument(0));
+
+ $this->builder->expects($this->once())
+ ->method('update')
+ ->with('news_items')
+ ->will($this->returnSelf());
+
$this->builder->expects($this->once())
- ->method('setValue')
- ->with('unread', 0)
+ ->method('set')
+ ->with('unread', 'unread')
->will($this->returnSelf());
$this->builder->expects($this->exactly(2))
->method('andWhere')
- ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId'])
+ ->withConsecutive(['id IN (:idList)'], ['unread != :unread'])
->will($this->returnSelf());
$this->builder->expects($this->exactly(2))
->method('setParameter')
- ->withConsecutive(['userId', 'admin'], ['folderId', 1])
+ ->withConsecutive(['unread', false], ['idList', [1, 2]])
->will($this->returnSelf());
$this->builder->expects($this->exactly(1))
->method('getSQL')
->will($this->returnValue('QUERY'));
+ $this->builder->expects($this->exactly(1))
+ ->method('getParameters')
+ ->will($this->returnValue([]));
+
+ $this->builder->expects($this->exactly(1))
+ ->method('getParameterTypes')
+ ->will($this->returnValue([]));
+
$this->db->expects($this->exactly(1))
->method('executeUpdate')
->with('QUERY');
@@ -330,43 +390,101 @@ class FolderMapperTest extends MapperTestUtility
*/
public function testReadWithMaxId()
{
- $this->db->expects($this->once())
+
+ $selectbuilder = $this->getMockBuilder(IQueryBuilder::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->db->expects($this->exactly(2))
->method('getQueryBuilder')
- ->willReturn($this->builder);
+ ->willReturnOnConsecutiveCalls($selectbuilder, $this->builder);
- $this->builder->expects($this->once())
- ->method('update')
+ $selectbuilder->expects($this->once())
+ ->method('select')
+ ->with('items.id')
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->once())
+ ->method('from')
->with('news_items', 'items')
->will($this->returnSelf());
- $this->builder->expects($this->once())
+ $selectbuilder->expects($this->once())
->method('innerJoin')
->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id')
->will($this->returnSelf());
+ $selectbuilder->expects($this->exactly(3))
+ ->method('andWhere')
+ ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId'], ['items.id <= :maxItemId'])
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->exactly(3))
+ ->method('setParameter')
+ ->withConsecutive(['userId', 'admin'], ['folderId', 1], ['maxItemId', 4])
+ ->will($this->returnSelf());
+
+ $selectbuilder->expects($this->exactly(1))
+ ->method('getSQL')
+ ->will($this->returnValue('SQL QUERY'));
+
+ $selectbuilder->expects($this->exactly(1))
+ ->method('getParameters')
+ ->will($this->returnValue([]));
+
+ $result = $this->getMockBuilder(ResultAdapter::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $result->expects($this->once())
+ ->method('fetchAll')
+ ->willReturn([['id' => 1], ['id' => 2]]);
+
+ $this->db->expects($this->exactly(1))
+ ->method('executeQuery')
+ ->with('SQL QUERY')
+ ->willReturn($result);
+
+ $this->builder->expects($this->once())
+ ->method('createParameter')
+ ->will($this->returnArgument(0));
+
+ $this->builder->expects($this->once())
+ ->method('update')
+ ->with('news_items')
+ ->will($this->returnSelf());
+
$this->builder->expects($this->once())
- ->method('setValue')
- ->with('unread', 0)
+ ->method('set')
+ ->with('unread', 'unread')
->will($this->returnSelf());
- $this->builder->expects($this->exactly(3))
+ $this->builder->expects($this->exactly(2))
->method('andWhere')
- ->withConsecutive(['feeds.user_id = :userId'], ['feeds.folder_id = :folderId'], ['items.id =< :maxItemId'])
+ ->withConsecutive(['id IN (:idList)'], ['unread != :unread'])
->will($this->returnSelf());
- $this->builder->expects($this->exactly(3))
+ $this->builder->expects($this->exactly(2))
->method('setParameter')
- ->withConsecutive(['userId', 'admin'], ['folderId', 1], ['maxItemId', 4])
+ ->withConsecutive(['unread', false], ['idList', [1, 2]])
->will($this->returnSelf());
$this->builder->expects($this->exactly(1))
->method('getSQL')
->will($this->returnValue('QUERY'));
+ $this->builder->expects($this->exactly(1))
+ ->method('getParameters')
+ ->will($this->returnValue([]));
+
+ $this->builder->expects($this->exactly(1))
+ ->method('getParameterTypes')
+ ->will($this->returnValue([]));
+
$this->db->expects($this->exactly(1))
->method('executeUpdate')
->with('QUERY');
$this->class->read('admin', 1, 4);
}
-} \ No newline at end of file
+}