<?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\Item;
use OCA\News\Db\ItemMapperV2;
use OCA\News\Service\Exceptions\ServiceValidationException;
use OCA\News\Utility\Time;
use OCP\DB\QueryBuilder\IExpressionBuilder;
/**
* Class ItemMapperTest
*
* @package OCA\News\Tests\Unit\Db
*/
class ItemMapperPaginatedTest extends MapperTestUtility
{
/** @var ItemMapperV2 */
private $class;
/**
* @covers \OCA\News\Db\ItemMapperV2::__construct
*/
protected function setUp(): void
{
parent::setUp();
$time = $this->getMockBuilder(Time::class)
->getMock();
$this->class = new ItemMapperV2($this->db, $time);
}
public function testFindAllItemsInvalid()
{
$this->expectException(ServiceValidationException::class);
$this->expectExceptionMessage('Unexpected Feed type in call');
$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(3))
->method('andWhere')
->withConsecutive(
['feeds.user_id = :userId'],
['feeds.deleted_at = 0']
)
->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')
->with(10)
->will($this->returnSelf());
$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->never())
->method('execute')
->will($this->returnValue($this->cursor));
$this->cursor->expects($this->never())
->method('fetch')
->willReturnOnConsecutiveCalls(
['id' => 4],
false
);
$this->class->findAllItems('jack', 232, 10, 10, false, []);
}
public function testFindAllItemsFullInverted()
{
$this->db->expects($this->once())
->method('getQueryBuilder')