summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller/feedcontroller.php30
-rw-r--r--js/Gruntfile.js5
-rw-r--r--service/feedservice.php18
-rw-r--r--tests/unit/controller/FeedControllerTest.php14
-rw-r--r--tests/unit/service/FeedServiceTest.php5
5 files changed, 41 insertions, 31 deletions
diff --git a/controller/feedcontroller.php b/controller/feedcontroller.php
index c31d4d1d6..3b9ab5cf9 100644
--- a/controller/feedcontroller.php
+++ b/controller/feedcontroller.php
@@ -36,8 +36,8 @@ class FeedController extends Controller {
private $userId;
private $settings;
- public function __construct($appName,
- IRequest $request,
+ public function __construct($appName,
+ IRequest $request,
FolderService $folderService,
FeedService $feedService,
ItemService $itemService,
@@ -66,9 +66,9 @@ class FeedController extends Controller {
];
try {
- $params['newestItemId'] =
+ $params['newestItemId'] =
$this->itemService->getNewestItemId($this->userId);
-
+
// An exception occurs if there is a newest item. If there is none,
// simply ignore it and do not add the newestItemId
} catch (ServiceNotFoundException $ex) {}
@@ -81,11 +81,11 @@ class FeedController extends Controller {
* @NoAdminRequired
*/
public function active(){
- $feedId = (int) $this->settings->getUserValue($this->userId,
+ $feedId = (int) $this->settings->getUserValue($this->userId,
$this->appName,'lastViewedFeedId');
$feedType = $this->settings->getUserValue($this->userId, $this->appName,
'lastViewedFeedType');
-
+
// cast from null to int is 0
if($feedType !== null){
$feedType = (int) $feedType;
@@ -95,15 +95,15 @@ class FeedController extends Controller {
try {
if($feedType === FeedType::FOLDER){
$this->folderService->find($feedId, $this->userId);
-
+
} elseif ($feedType === FeedType::FEED){
$this->feedService->find($feedId, $this->userId);
-
+
// if its the first launch, those values will be null
} elseif($feedType === null){
throw new ServiceNotFoundException('');
}
-
+
} catch (ServiceNotFoundException $ex){
$feedId = 0;
$feedType = FeedType::SUBSCRIPTIONS;
@@ -123,18 +123,20 @@ class FeedController extends Controller {
*
* @param string $url
* @param int $parentFolderId
+ * @param string $title
*/
- public function create($url, $parentFolderId){
+ public function create($url, $parentFolderId, $title){
try {
- // we need to purge deleted feeds if a feed is created to
+ // we need to purge deleted feeds if a feed is created to
// prevent already exists exceptions
$this->feedService->purgeDeleted($this->userId, false);
- $feed = $this->feedService->create($url, $parentFolderId, $this->userId);
+ $feed = $this->feedService->create($url, $parentFolderId,
+ $this->userId, $title);
$params = ['feeds' => [$feed]];
try {
- $params['newestItemId'] =
+ $params['newestItemId'] =
$this->itemService->getNewestItemId($this->userId);
// An exception occurs if there is a newest item. If there is none,
@@ -153,7 +155,7 @@ class FeedController extends Controller {
/**
* @NoAdminRequired
- *
+ *
* @param int $feedId
*/
public function delete($feedId){
diff --git a/js/Gruntfile.js b/js/Gruntfile.js
index 518627c9c..58764d823 100644
--- a/js/Gruntfile.js
+++ b/js/Gruntfile.js
@@ -120,8 +120,7 @@ module.exports = function (grunt) {
},
phpunit: {
files: [
- '../*/**.php',
- '!../3rdparty'
+ '../**/*.php'
],
tasks: ['phpunit']
}
@@ -139,7 +138,7 @@ module.exports = function (grunt) {
},
phpunit: {
classes: {
- dir: '../tests/unit'
+ dir: '../tests'
},
options: {
colors: true
diff --git a/service/feedservice.php b/service/feedservice.php
index 68555cf1b..08b2d1d2f 100644
--- a/service/feedservice.php
+++ b/service/feedservice.php
@@ -40,9 +40,9 @@ class FeedService extends Service {
private $purifier;
private $loggerParams;
- public function __construct(FeedMapper $feedMapper,
+ public function __construct(FeedMapper $feedMapper,
Fetcher $feedFetcher,
- ItemMapper $itemMapper,
+ ItemMapper $itemMapper,
ILogger $logger,
IL10N $l10n,
$timeFactory,
@@ -87,11 +87,12 @@ class FeedService extends Service {
* @param string $feedUrl the url to the feed
* @param int $folderId the folder where it should be put into, 0 for root folder
* @param string $userId for which user the feed should be created
+ * @param string $title if given, this is used for the opml feed title
* @throws ServiceConflictException if the feed exists already
* @throws ServiceNotFoundException if the url points to an invalid feed
* @return Feed the newly created feed
*/
- public function create($feedUrl, $folderId, $userId){
+ public function create($feedUrl, $folderId, $userId, $title=null){
// first try if the feed exists already
try {
list($feed, $items) = $this->feedFetcher->fetch($feedUrl);
@@ -109,6 +110,11 @@ class FeedService extends Service {
$feed->setFolderId($folderId);
$feed->setUserId($userId);
$feed->setArticlesPerUpdate(count($items));
+
+ if ($title) {
+ $feed->setTitle($title);
+ }
+
$feed = $this->feedMapper->insert($feed);
// insert items in reverse order because the first one is usually the
@@ -197,7 +203,7 @@ class FeedService extends Service {
try {
$this->itemMapper->findByGuidHash($item->getGuidHash(), $feedId, $userId);
} catch(DoesNotExistException $ex){
- $item = $this->enhancer->enhance($item,
+ $item = $this->enhancer->enhance($item,
$existingFeed->getLink());
$item->setBody($this->purifier->purify($item->getBody()));
$this->itemMapper->insert($item);
@@ -279,7 +285,7 @@ class FeedService extends Service {
$item->setFeedId($feed->getId());
} elseif(array_key_exists($url, $feedsDict)) {
$feed = $feedsDict[$url];
- $item->setFeedId($feed->getId());
+ $item->setFeedId($feed->getId());
} else {
$createdFeed = true;
$feed = new Feed();
@@ -289,7 +295,7 @@ class FeedService extends Service {
$feed->setTitle($this->l10n->t('Articles without feed'));
$feed->setAdded($this->timeFactory->getTime());
$feed->setFolderId(0);
- $feed->setPreventUpdate(true);
+ $feed->setPreventUpdate(true);
$feed = $this->feedMapper->insert($feed);
$item->setFeedId($feed->getId());
diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php
index c756875d2..fc46594a8 100644
--- a/tests/unit/controller/FeedControllerTest.php
+++ b/tests/unit/controller/FeedControllerTest.php
@@ -229,10 +229,11 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase {
->method('create')
->with($this->equalTo('hi'),
$this->equalTo(4),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo('yo'))
->will($this->returnValue($result['feeds'][0]));
- $response = $this->controller->create('hi', 4);
+ $response = $this->controller->create('hi', 4, 'yo');
$this->assertEquals($result, $response);
}
@@ -253,10 +254,11 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase {
->method('create')
->with($this->equalTo('hi'),
$this->equalTo(4),
- $this->equalTo($this->user))
+ $this->equalTo($this->user),
+ $this->equalTo('yo'))
->will($this->returnValue($result['feeds'][0]));
- $response = $this->controller->create('hi', 4);
+ $response = $this->controller->create('hi', 4, 'yo');
$this->assertEquals($result, $response);
}
@@ -272,7 +274,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase {
->method('create')
->will($this->throwException($ex));
- $response = $this->controller->create('hi', 4);
+ $response = $this->controller->create('hi', 4, 'test');
$params = json_decode($response->render(), true);
$this->assertEquals($msg, $params['message']);
@@ -290,7 +292,7 @@ class FeedControllerTest extends \PHPUnit_Framework_TestCase {
->method('create')
->will($this->throwException($ex));
- $response = $this->controller->create('hi', 4);
+ $response = $this->controller->create('hi', 4, 'test');
$params = json_decode($response->render(), true);
$this->assertEquals($msg, $params['message']);
diff --git a/tests/unit/service/FeedServiceTest.php b/tests/unit/service/FeedServiceTest.php
index d4174b245..2ec1d7a9b 100644
--- a/tests/unit/service/FeedServiceTest.php
+++ b/tests/unit/service/FeedServiceTest.php
@@ -116,6 +116,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$createdFeed->setUrl($url);
$createdFeed->setUrlHash('hsssi');
$createdFeed->setLink($url);
+ $createdFeed->setTitle('hehoy');
$item1 = new Item();
$item1->setGuidHash('hi');
$item2 = new Item();
@@ -203,7 +204,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$this->feedMapper->expects($this->once())
->method('findByUrlHash')
- ->with($this->equalTo($createdFeed->getUrlHash()),
+ ->with($this->equalTo($createdFeed->getUrlHash()),
$this->equalTo($this->user))
->will($this->throwException($ex));
$this->fetcher->expects($this->once())
@@ -601,7 +602,7 @@ class FeedServiceTest extends \PHPUnit_Framework_TestCase {
$this->itemMapper->expects($this->at(1))
->method('insert')
->with($this->equalTo($item));
-
+
$this->itemMapper->expects($this->at(2))
->method('findByGuidHash')
->will($this->returnValue($item));