<?php
/**
* ownCloud - 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 Alessandro Cosentino 2012
* @copyright Bernhard Posselt 2012, 2014
*/
namespace OCA\News\Service;
use OCP\AppFramework\Db\DoesNotExistException;
use OCA\News\Db\Feed;
use OCA\News\Db\Item;
use OCA\News\Fetcher\Fetcher;
use OCA\News\Fetcher\FetcherException;
class FeedServiceTest extends \PHPUnit_Framework_TestCase {
private $feedMapper;
private $feedService;
private $user;
private $response;
private $fetcher;
private $itemMapper;
private $threshold;
private $time;
private $importParser;
private $autoPurgeMinimumInterval;
private $purifier;
private $l10n;
private $logger;
private $loggerParams;
protected function setUp(){
$this->logger = $this->getMockBuilder(
'\OCP\ILogger')
->disableOriginalConstructor()
->getMock();
$this->loggerParams = ['hi'];
$this->time = 222;
$this->autoPurgeMinimumInterval = 10;
$timeFactory = $this->getMockBuilder('\OCA\News\Utility\Time')
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
->method('getTime')
->will($this->returnValue($this->time));
$this->l10n = $this->getMockBuilder('\OCP\IL10N')
->disableOriginalConstructor()
->getMock();
$this->feedMapper = $this
->getMockBuilder('\OCA\News\Db\FeedMapper')
->disableOriginalConstructor()
->getMock();
$this->fetcher = $this
->getMockBuilder('\OCA\News\Fetcher\Fetcher')
->disableOriginalConstructor()
->getMock();
$this->itemMapper = $this
->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
->getMock();
$this->purifier = $this
->getMockBuilder('\HTMLPurifier')
->disableOriginalConstructor()
->getMock();
$config = $this->getMockBuilder(
'\OCA\News\Config\Config')
->disableOriginalConstructor()
->getMock();
$config->expects($this->any())
->method('getAutoPurgeMinimumInterval')
->will($this->returnValue($this->autoPurgeMinimumInterval));
$this->feedService = new FeedService($this->feedMapper,
$this->fetcher, $this->itemMapper, $this->logger, $this->l10n,
$timeFactory, $config, $this->purifier, $this->loggerParams);
$this->user = 'jack';
}
public function testFindAll(){
$this->feedMapper->expects($this->once())
->method('findAllFromUser')
->with($this->equalTo($this->user))
->will($this->returnValue($this->response));
$result = $this->feedService->findAll($this->user);
$this->assertEquals($this->response, $result);
}
public function testCreateDoesNotFindFeed(){
$ex = new FetcherException('hi');
$url = 'test'