summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-09-11 16:42:03 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2013-09-12 01:00:32 +0200
commit09f60e75c90e5734a3b11a0cca944bd42bc41665 (patch)
tree8ecdc41cd6bb7c2b338e8e82b2b1e090b4d82ce4 /tests
parent24cab805e7484a5d206974d05f8de38641435f8c (diff)
#342 implement export
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php12
-rw-r--r--tests/unit/controller/ExportControllerTest.php62
-rw-r--r--tests/unit/db/ItemMapperTest.php12
-rw-r--r--tests/unit/db/ItemTest.php40
-rw-r--r--tests/unit/utility/ConfigTest.php4
5 files changed, 127 insertions, 3 deletions
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 21a776c05..5dc6c9895 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -348,6 +348,18 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
}
+ public function testGetUnreadOrStarred(){
+ $star = 18;
+
+ $this->mapper->expects($this->once())
+ ->method('findAllUnreadOrStarred')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($star));
+
+ $result = $this->itemBusinessLayer->getUnreadOrStarred($this->user);
+
+ $this->assertEquals($star, $result);
+ }
}
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php
index 29e0b6f71..2b9d41dde 100644
--- a/tests/unit/controller/ExportControllerTest.php
+++ b/tests/unit/controller/ExportControllerTest.php
@@ -27,11 +27,14 @@ namespace OCA\News\Controller;
use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Http\TextDownloadResponse;
+use \OCA\AppFramework\Http\JSONResponse;
use \OCA\AppFramework\Utility\ControllerTestUtility;
use \OCA\AppFramework\Db\DoesNotExistException;
use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Utility\OPMLExporter;
+use \OCA\News\Db\Item;
+use \OCA\News\Db\Feed;
require_once(__DIR__ . "/../../classloader.php");
@@ -44,6 +47,7 @@ class ExportControllerTest extends ControllerTestUtility {
private $user;
private $feedBusinessLayer;
private $folderBusinessLayer;
+ private $itemBusinessLayer;
private $opmlExporter;
/**
@@ -51,6 +55,9 @@ class ExportControllerTest extends ControllerTestUtility {
*/
public function setUp(){
$this->api = $this->getAPIMock();
+ $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer')
->disableOriginalConstructor()
->getMock();
@@ -60,7 +67,8 @@ class ExportControllerTest extends ControllerTestUtility {
$this->request = new Request();
$this->opmlExporter = new OPMLExporter();
$this->controller = new ExportController($this->api, $this->request,
- $this->feedBusinessLayer, $this->folderBusinessLayer, $this->opmlExporter);
+ $this->feedBusinessLayer, $this->folderBusinessLayer,
+ $this->itemBusinessLayer, $this->opmlExporter);
$this->user = 'john';
}
@@ -72,6 +80,13 @@ class ExportControllerTest extends ControllerTestUtility {
}
+ public function testArticlesAnnotations(){
+ $annotations = array('IsAdminExemption', 'IsSubAdminExemption',
+ 'CSRFExemption');
+ $this->assertAnnotations($this->controller, 'articles', $annotations);
+ }
+
+
public function testOpmlExportNoFeeds(){
$opml =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
@@ -100,4 +115,49 @@ class ExportControllerTest extends ControllerTestUtility {
}
+ public function testGetAllArticles(){
+ $item1 = new Item();
+ $item1->setFeedId(3);
+ $item2 = new Item();
+ $item2->setFeedId(5);
+
+ $feed1 = new Feed();
+ $feed1->setId(3);
+ $feed1->setLink('http://goo');
+ $feed2 = new Feed();
+ $feed2->setId(5);
+ $feed2->setLink('http://gee');
+ $feeds = array($feed1, $feed2);
+
+ $articles = array(
+ $item1, $item2
+ );
+
+ $this->api->expects($this->once())
+ ->method('getUserId')
+ ->will($this->returnValue($this->user));
+ $this->feedBusinessLayer->expects($this->once())
+ ->method('findAll')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($feeds));
+ $this->itemBusinessLayer->expects($this->once())
+ ->method('getUnreadOrStarred')
+ ->with($this->equalTo($this->user))
+ ->will($this->returnValue($articles));
+
+
+ $return = $this->controller->articles();
+ $headers = $return->getHeaders();
+ $this->assertTrue($return instanceof JSONResponse);
+ $this->assertEquals('attachment; filename="articles.json"', $headers ['Content-Disposition']);
+
+ $this->assertEquals('[{"guid":null,"url":null,"title":null,' .
+ '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' .
+ '"enclosureLink":null,"unread":false,"starred":false,' .
+ '"feedLink":"http:\/\/goo"},{"guid":null,"url":null,"title":null,' .
+ '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' .
+ '"enclosureLink":null,"unread":false,"starred":false,' .
+ '"feedLink":"http:\/\/gee"}]', $return->render());
+ }
+
} \ No newline at end of file
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index eb04b1514..ae045ce31 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -221,6 +221,18 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
}
+ public function testFindAllUnreadOrStarred(){
+ $status = StatusFlag::UNREAD | StatusFlag::STARRED;
+ $sql = 'AND ((`items`.`status` & ' . $status . ') > 0) ';
+ $sql = $this->makeSelectQuery($sql);
+ $params = array($this->user);
+ $this->setMapperResult($sql, $params, $this->rows);
+ $result = $this->mapper->findAllUnreadOrStarred($this->user);
+
+ $this->assertEquals($this->items, $result);
+ }
+
+
public function testFindAllFeed(){
$sql = 'AND `items`.`feed_id` = ? ' .
'AND `items`.`id` < ? ';
diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php
index daaf64a65..511badeeb 100644
--- a/tests/unit/db/ItemTest.php
+++ b/tests/unit/db/ItemTest.php
@@ -103,6 +103,46 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
}
+ public function testToExport() {
+ $item = new Item();
+ $item->setId(3);
+ $item->setGuid('guid');
+ $item->setGuidHash('hash');
+ $item->setUrl('https://google');
+ $item->setTitle('title');
+ $item->setAuthor('author');
+ $item->setPubDate(123);
+ $item->setBody('body');
+ $item->setEnclosureMime('audio/ogg');
+ $item->setEnclosureLink('enclink');
+ $item->setFeedId(1);
+ $item->setStatus(0);
+ $item->setUnread();
+ $item->setStarred();
+ $item->setLastModified(321);
+
+ $feed = new Feed();
+ $feed->setLink('http://test');
+ $feeds = array(
+ "feed1" => $feed
+ );
+
+ $this->assertEquals(array(
+ 'guid' => 'guid',
+ 'url' => 'https://google',
+ 'title' => 'title',
+ 'author' => 'author',
+ 'pubDate' => 123,
+ 'body' => 'body',
+ 'enclosureMime' => 'audio/ogg',
+ 'enclosureLink' => 'enclink',
+ 'unread' => true,
+ 'starred' => true,
+ 'feedLink' => 'http://test'
+ ), $item->toExport($feeds));
+ }
+
+
public function testSetAuthor(){
$item = new Item();
$item->setAuthor('<a>my link</li>');
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index 479acabb5..0e2d6ab4e 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -51,7 +51,7 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
public function testDefaults() {
$this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval());
- $this->assertEquals(200, $this->config->getAutoPurgeCount());
+ $this->assertEquals(5000, $this->config->getAutoPurgeCount());
$this->assertEquals(30*60, $this->config->getSimplePieCacheDuration());
$this->assertEquals(60, $this->config->getFeedFetcherTimeout());
$this->assertEquals(true, $this->config->getUseCronUpdates());
@@ -139,7 +139,7 @@ class ConfigFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
$this->config->setUseCronUpdates(false);
$json = "autoPurgeMinimumInterval = 60\n" .
- "autoPurgeCount = 200\n" .
+ "autoPurgeCount = 5000\n" .
"simplePieCacheDuration = 1800\n" .
"feedFetcherTimeout = 60\n" .
"useCronUpdates = false";