<?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 OC\DB\QueryBuilder\Parameter;
use OC\DB\ResultAdapter;
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 ItemMapperTest 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);
}
/**
* @covers \OCA\News\Db\ItemMapperV2::__construct
*/
public function testSetUpSuccess(): void
{
$this->assertEquals('news_items', $this->class->getTableName());
}
/**
* @covers \OCA\News\Db\ItemMapperV2::findAllFromUser
*/
public function testFindAllFromUser()
{
$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->once())
->method('innerJoin')
->with('items', 'news_feeds', 'feeds', 'items.feed_id = feeds.id')
->will($this->returnSelf());
$this->builder->expects($this->once())
->method('where')
->with('feeds.user_id = :user_id')
->will($this->returnSelf());
$this->builder->expects($this->once())
->method('andWhere')
->with('feeds.deleted_at = 0')
->will($this->returnSelf());
$this->builder->expects($this->exactly(1))
->method('setParameter')
->withConsecutive(['user_id', 'jack'])
->will($this->returnSelf());
$this->builder->expects($this->once())
->method('execute')
->will($this->returnValue($this->cursor));
$this->cursor->expects($this->exactly(3))
->method('fetch')
->willReturnOnConsecutiveCalls(
['id' => 4],
['id' => 5],
null
);
$result =<