<?php
/**
* Nextcloud - News
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Alessandro Cosentino <cosenal@gmail.com>
* @author Bernhard Posselt <dev@bernhard-posselt.com>
* @copyright 2012 Alessandro Cosentino
* @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Tests\Unit\Db;
use OC\DB\QueryBuilder\Literal;
use OCA\News\Db\Feed;
use OCA\News\Db\FeedMapperV2;
use OCA\News\Db\Folder;
use OCA\News\Db\Item;
use OCA\News\Db\ItemMapperV2;
use OCA\News\Db\NewsMapperV2;
use OCA\News\Service\Exceptions\ServiceValidationException;
use OCA\News\Utility\Time;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\MultipleObjectsReturnedException;
use OCP\DB\IResult;
use OCP\DB\QueryBuilder\IExpressionBuilder;
use OCP\DB\QueryBuilder\IFunctionBuilder;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\QueryBuilder\IQueryFunction;
use OCP\IDBConnection;
use Test\TestCase;
/**
* Class ItemMapperTest
*
* @package OCA\News\Tests\Unit\Db
*/
class ItemMapperPaginatedTest extends MapperTestUtility
{
/** @var Time */
private $time;
/** @var ItemMapperV2 */
private $class;
/**
* @covers \OCA\News\Db\ItemMapperV2::__construct
*/
protected function setUp(): void
{
parent::setUp();
$this->time = $this->getMockBuilder(Time::class)
->getMock();
$this->class = new ItemMapperV2($this->db, $this->time);
}
public function testFindAllItemsInvalid()
{
$this->expectException(ServiceValidationException::class);
$this->expectExceptionMessage('Unexpected Feed type in call');
$expr = $this->getMockBuilder(IExpressionBuilder::class)
->getMock();
$this->builder->expects($this->exactly(1))
->method('expr')
->will($this->returnValue($expr));
$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(2))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId']
)
->will($this->returnSelf());
$this->builder->expects($this->exactly(2))
->method('setParameter')
->withConsecutive(['userId', 'jack'], ['offset', 10])
->will($this->returnSelf());
$this->builder->expects($this->exactly(1))
->method('setMaxResults'