summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:24:31 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-04-22 18:24:31 +0200
commitdf18314b32b05f10720936831ed43573e1792ae6 (patch)
treea2b8e28e165727e7a88d7ac3529f64d5f6b938e2 /tests
parent366c1b15545b4da69bc8e236ba4350c28ad24e77 (diff)
added import from google reader, fix #80
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php102
-rw-r--r--tests/unit/utility/ImportParserTest.php114
2 files changed, 215 insertions, 1 deletions
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index cd044161f..0f8f61e4f 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -34,6 +34,7 @@ use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
use \OCA\News\Utility\Fetcher;
use \OCA\News\Utility\FetcherException;
+use \OCA\News\Utility\ImportParser;
class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
@@ -45,6 +46,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
private $itemMapper;
private $threshold;
private $time;
+ private $importParser;
protected function setUp(){
$this->api = $this->getAPIMock();
@@ -65,9 +67,12 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->itemMapper = $this->getMockBuilder('\OCA\News\Db\ItemMapper')
->disableOriginalConstructor()
->getMock();
+ $this->importParser = $this->getMockBuilder('\OCA\News\Utility\ImportParser')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->businessLayer = new FeedBusinessLayer($this->mapper,
$this->fetcher, $this->itemMapper, $this->api,
- $timeFactory);
+ $timeFactory, $this->importParser);
$this->user = 'jack';
$response = 'hi';
}
@@ -576,5 +581,100 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testImportGoogleReaderJSON(){
+ $url = 'http://owncloud/googlereader';
+ $urlHash = md5($url);
+
+ $feed = new Feed();
+ $feed->setId(3);
+ $feed->setUserId($this->user);
+ $feed->setUrlHash($urlHash);
+ $feed->setUrl($url);
+ $feed->setTitle('Google Reader');
+ $feed->setAdded($this->time);
+ $feed->setFolderId(0);
+ $feed->setPreventUpdate(true);
+
+ $items = array(new Item());
+
+ $this->mapper->expects($this->at(0))
+ ->method('findByUrlHash')
+ ->with($this->equalTo($urlHash),
+ $this->equalTo($this->user))
+ ->will($this->throwException(new DoesNotExistException('hi')));
+ $this->mapper->expects($this->at(1))
+ ->method('insert')
+ ->will($this->returnValue($feed));
+ $this->mapper->expects($this->at(2))
+ ->method('findByUrlHash')
+ ->with($this->equalTo($urlHash),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->importParser->expects($this->once())
+ ->method('parse')
+ ->will($this->returnValue($items));
+ $this->itemMapper->expects($this->once())
+ ->method('findByGuidHash');
+ $this->itemMapper->expects($this->never())
+ ->method('insert');
+
+
+ $result = $this->businessLayer->importGoogleReaderJSON(array(), $this->user);
+
+ $this->assertEquals($feed, $result);
+ }
+
+
+ public function testImportGoogleReaderJSONFeedExists(){
+ $url = 'http://owncloud/googlereader';
+ $urlHash = md5($url);
+
+ $feed = new Feed();
+ $feed->setUserId($this->user);
+ $feed->setUrlHash($urlHash);
+ $feed->setUrl($url);
+ $feed->setTitle('Google Reader');
+ $feed->setAdded($this->time);
+ $feed->setFolderId(0);
+ $feed->setPreventUpdate(true);
+ $feed->setId(3);
+
+ $item = new Item();
+ $item->setGuidHash('hi');
+ $items = array($item);
+ $savedItem = new Item();
+ $savedItem->setFeedId($feed->getId());
+ $savedItem->setGuidHash('hi');
+
+ $in = array();
+
+ $this->mapper->expects($this->at(0))
+ ->method('findByUrlHash')
+ ->with($this->equalTo($urlHash),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->mapper->expects($this->at(1))
+ ->method('findByUrlHash')
+ ->with($this->equalTo($urlHash),
+ $this->equalTo($this->user))
+ ->will($this->returnValue($feed));
+ $this->importParser->expects($this->once())
+ ->method('parse')
+ ->with($this->equalTo($in))
+ ->will($this->returnValue($items));
+ $this->itemMapper->expects($this->once())
+ ->method('findByGuidHash')
+ ->with($this->equalTo($savedItem->getGuidHash()),
+ $this->equalTo($savedItem->getFeedId()),
+ $this->equalTo($this->user))
+ ->will($this->throwException(new DoesNotExistException('ho')));
+ $this->itemMapper->expects($this->once())
+ ->method('insert')
+ ->with($this->equalTo($savedItem));
+
+ $result = $this->businessLayer->importGoogleReaderJSON($in, $this->user);
+
+ $this->assertEquals($feed, $result);
+ }
}
diff --git a/tests/unit/utility/ImportParserTest.php b/tests/unit/utility/ImportParserTest.php
new file mode 100644
index 000000000..5c4a6292c
--- /dev/null
+++ b/tests/unit/utility/ImportParserTest.php
@@ -0,0 +1,114 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Cosentino
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Utility;
+
+use \OCA\News\Db\Item;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class ImportParserTest extends \OCA\AppFramework\Utility\TestUtility {
+
+ private $parser;
+ private $time;
+ private $in;
+
+ protected function setUp(){
+ $this->time = 222;
+ $timeFactory = $this->getMockBuilder(
+ '\OCA\AppFramework\Utility\TimeFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $timeFactory->expects($this->any())
+ ->method('getTime')
+ ->will($this->returnValue($this->time));
+
+ $this->parser = new ImportParser($timeFactory);
+ $this->in = array(
+ 'items' => array(
+ array(
+ 'id' => "tag:google.com,2005:reader/item/f9fd1dd3c19262e1",
+ 'title' => "[HorribleSubs] Mushibugyo - 01 [720p].mkv",
+ "published" => 1365415485,
+
+ "alternate" => array( array(
+ "href" => "http://www.nyaa.eu/?page=view&tid=421561",
+ "type" => "text/html"
+ )),
+ "summary" => array(
+ "content" => "1596 seeder(s), 775 leecher(s), 8005 download(s) - 316.7 MiB - Trusted"
+ )
+ )
+ )
+ );
+ }
+
+
+ public function testImportParserReturnsEmptyArrayIfNoInput(){
+ $result = $this->parser->parse(array());
+
+ $this->assertEquals($result, array());
+ }
+
+
+ public function testParsesItems() {
+ $result = $this->parser->parse($this->in);
+
+ $out = new Item();
+ $out->setTitle($this->in['items'][0]['title']);
+ $out->setPubDate($this->in['items'][0]['published']);
+ $out->setBody($this->in['items'][0]['summary']['content']);
+ $out->setUrl($this->in['items'][0]['alternate'][0]['href']);
+ $out->setGuid($this->in['items'][0]['id']);
+ $out->setGuidHash(md5($this->in['items'][0]['id']));
+ $out->setStatus(0);
+ $out->setUnread();
+ $out->setStarred();
+
+ $this->assertEquals(array($out), $result);
+ }
+
+
+ public function testParsesItemsNoSummary() {
+ $this->in['items'][0]['content']['content'] = 'hi';
+ unset($this->in['items'][0]['summary']);
+ $result = $this->parser->parse($this->in);
+
+ $out = new Item();
+ $out->setTitle($this->in['items'][0]['title']);
+ $out->setPubDate($this->in['items'][0]['published']);
+ $out->setBody($this->in['items'][0]['content']['content']);
+ $out->setUrl($this->in['items'][0]['alternate'][0]['href']);
+ $out->setGuid($this->in['items'][0]['id']);
+ $out->setGuidHash(md5($this->in['items'][0]['id']));
+ $out->setStatus(0);
+ $out->setUnread();
+ $out->setStarred();
+
+ $this->assertEquals(array($out), $result);
+ }
+
+}