summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-10-09 09:52:12 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-10-09 09:52:12 +0200
commit13b13aeda19310e97d8e8a91d4adb6ad358a93c8 (patch)
treec7105ea5e5aca461b6db26aa7b9814b281bfed95
parentb32fc30d68e18994d2b17bbb30eac0b33ec6af3c (diff)
more code coverage
-rw-r--r--fetcher/fetcher.php2
-rw-r--r--tests/unit/db/ItemTest.php29
-rw-r--r--tests/unit/fetcher/FetcherTest.php24
-rw-r--r--tests/unit/service/ItemServiceTest.php30
-rw-r--r--tests/unit/utility/ConfigTest.php12
5 files changed, 80 insertions, 17 deletions
diff --git a/fetcher/fetcher.php b/fetcher/fetcher.php
index 5d4a0214f..fbdaaa6b8 100644
--- a/fetcher/fetcher.php
+++ b/fetcher/fetcher.php
@@ -47,7 +47,7 @@ class Fetcher {
}
}
- return [null, []];
+ return [null, []];
}
diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php
index 70d4e34e7..6c1a16c20 100644
--- a/tests/unit/db/ItemTest.php
+++ b/tests/unit/db/ItemTest.php
@@ -163,7 +163,7 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
}
- public function testFromImport() {
+ private function createImportItem($isRead) {
$item = new Item();
$item->setGuid('guid');
$item->setUrl('https://google');
@@ -173,9 +173,21 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
$item->setBody('body');
$item->setEnclosureMime('audio/ogg');
$item->setEnclosureLink('enclink');
- $item->setUnread();
$item->setStarred();
+ if ($isRead) {
+ $item->setUnread();
+ } else {
+ $item->setRead();
+ }
+
+ return $item;
+ }
+
+
+ public function testFromImport() {
+ $item = $this->createImportItem(false);
+
$import = [
'guid' => $item->getGuid(),
'url' => $item->getUrl(),
@@ -194,18 +206,9 @@ class ItemTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals($item, $compareWith);
}
+
public function testFromImportRead() {
- $item = new Item();
- $item->setGuid('guid');
- $item->setUrl('https://google');
- $item->setTitle('title');
- $item->setAuthor('author');
- $item->setPubDate(123);
- $item->setBody('body');
- $item->setEnclosureMime('audio/ogg');
- $item->setEnclosureLink('enclink');
- $item->setRead();
- $item->setStarred();
+ $item = $this->createImportItem(true);
$import = [
'guid' => $item->getGuid(),
diff --git a/tests/unit/fetcher/FetcherTest.php b/tests/unit/fetcher/FetcherTest.php
index 261c53108..7421bc9e5 100644
--- a/tests/unit/fetcher/FetcherTest.php
+++ b/tests/unit/fetcher/FetcherTest.php
@@ -50,6 +50,30 @@ class FetcherTest extends \PHPUnit_Framework_TestCase {
}
+ public function testNoFetchers(){
+ $url = 'hi';
+ $mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockFetcher->expects($this->once())
+ ->method('canHandle')
+ ->with($this->equalTo($url))
+ ->will($this->returnValue(false));
+ $mockFetcher2 = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mockFetcher2->expects($this->once())
+ ->method('canHandle')
+ ->with($this->equalTo($url))
+ ->will($this->returnValue(false));
+
+ $this->fetcher->registerFetcher($mockFetcher);
+ $this->fetcher->registerFetcher($mockFetcher2);
+
+ $result = $this->fetcher->fetch($url);
+ $this->assertEquals([null, []], $result);
+ }
+
public function testMultipleFetchers(){
$url = 'hi';
$mockFetcher = $this->getMockBuilder('\OCA\News\Fetcher\IFeedFetcher')
diff --git a/tests/unit/service/ItemServiceTest.php b/tests/unit/service/ItemServiceTest.php
index d5947b406..2f5f31cba 100644
--- a/tests/unit/service/ItemServiceTest.php
+++ b/tests/unit/service/ItemServiceTest.php
@@ -243,7 +243,7 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
$this->assertTrue($item->isUnstarred());
}
- public function testRead(){
+ public function testUnread(){
$itemId = 3;
$item = new Item();
$item->setStatus(128);
@@ -271,6 +271,34 @@ class ItemServiceTest extends \PHPUnit_Framework_TestCase {
}
+ public function testRead(){
+ $itemId = 3;
+ $item = new Item();
+ $item->setStatus(128);
+ $item->setId($itemId);
+ $item->setUnread();
+
+ $expectedItem = new Item();
+ $expectedItem->setStatus(128);
+ $expectedItem->setRead();
+ $expectedItem->setId($itemId);
+ $expectedItem->setLastModified($this->time);
+
+ $this->mapper->expects($this->once())
+ ->method('find')
+ ->with($this->equalTo($itemId), $this->equalTo($this->user))
+ ->will($this->returnValue($item));
+
+ $this->mapper->expects($this->once())
+ ->method('update')
+ ->with($this->equalTo($expectedItem));
+
+ $this->itemService->read($itemId, true, $this->user);
+
+ $this->assertTrue($item->isRead());
+ }
+
+
public function testStarDoesNotExist(){
$this->setExpectedException('\OCA\News\Service\ServiceNotFoundException');
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index 613944eb2..a8f7be1be 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -184,13 +184,21 @@ class ConfigTest extends \PHPUnit_Framework_TestCase {
}
- public function testMinimumAutoPurgeInterval() {
- $this->config->setAutoPurgeMinimumInterval(30);
+ public function testNoLowMinimumAutoPurgeInterval() {
+ $this->config->setAutoPurgeMinimumInterval(59);
$interval = $this->config->getAutoPurgeMinimumInterval();
$this->assertSame(60, $interval);
}
+
+ public function testMinimumAutoPurgeInterval() {
+ $this->config->setAutoPurgeMinimumInterval(61);
+ $interval = $this->config->getAutoPurgeMinimumInterval();
+
+ $this->assertSame(61, $interval);
+ }
+
public function testCacheDuration() {
$this->config->setSimplePieCacheDuration(21);
$duration = $this->config->getSimplePieCacheDuration();