summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--controller/entityapiserializer.php8
-rw-r--r--controller/jsonhttperror.php2
-rw-r--r--tests/unit/businesslayer/BusinessLayerTest.php5
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php16
-rw-r--r--tests/unit/businesslayer/FolderBusinessLayerTest.php7
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php3
-rw-r--r--tests/unit/controller/EntityApiSerializerTest.php50
-rw-r--r--tests/unit/controller/JSONHttpErrorTest.php31
-rw-r--r--tests/unit/http/TextDownloadResponseTest.php3
-rw-r--r--tests/unit/utility/ConfigTest.php16
-rw-r--r--warn12
11 files changed, 116 insertions, 37 deletions
diff --git a/controller/entityapiserializer.php b/controller/entityapiserializer.php
index 6548fe6fd..8bd17ba29 100644
--- a/controller/entityapiserializer.php
+++ b/controller/entityapiserializer.php
@@ -14,7 +14,7 @@ namespace OCA\News\Controller;
use \OCP\AppFramework\Http\IResponseSerializer;
-class EntityApiSeralizer implements IResponseSerializer {
+class EntityApiSerializer implements IResponseSerializer {
public function __construct($level) {
@@ -32,12 +32,14 @@ class EntityApiSeralizer implements IResponseSerializer {
}
$response = array(
- $this->level => array();
+ $this->level => array()
);
foreach($data as $entity) {
- $response[$this->level][] = $entity->toAPI()
+ $response[$this->level][] = $entity->toAPI();
}
+
+ return $response;
}
diff --git a/controller/jsonhttperror.php b/controller/jsonhttperror.php
index dca0cb2f3..b841ba5b5 100644
--- a/controller/jsonhttperror.php
+++ b/controller/jsonhttperror.php
@@ -23,7 +23,7 @@ trait JSONHttpError {
* @param int the http error code
* @return \OCP\AppFramework\Http\JSONResponse
*/
- protected function error($exception, $code) {
+ public function error($exception, $code) {
return new JSONResponse(
array('message' => $exception->getMessage()),
$code
diff --git a/tests/unit/businesslayer/BusinessLayerTest.php b/tests/unit/businesslayer/BusinessLayerTest.php
index 8b9df37c0..898458adb 100644
--- a/tests/unit/businesslayer/BusinessLayerTest.php
+++ b/tests/unit/businesslayer/BusinessLayerTest.php
@@ -16,8 +16,9 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\News\Db\DoesNotExistException;
-use \OCA\News\Db\MultipleObjectsReturnedException;
+use \OCP\AppFramework\Db\DoesNotExistException;
+use \OCP\AppFramework\Db\MultipleObjectsReturnedException;
+
use \OCA\News\Db\Folder;
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 2c6aa9ac9..65cd3e3db 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -16,7 +16,8 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\News\Db\DoesNotExistException;
+use \OCP\AppFramework\Db\DoesNotExistException;
+
use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
use \OCA\News\Fetcher\Fetcher;
@@ -38,19 +39,23 @@ class FeedBusinessLayerTest extends \PHPUnit_Framework_TestCase {
private $purifier;
private $l10n;
private $logger;
+ private $loggerParams;
protected function setUp(){
$this->logger = $this->getMockBuilder(
- '\OCA\News\Core\Logger')
+ '\OCP\ILogger')
->disableOriginalConstructor()
->getMock();
- $this->l10n = $this->getMock('L10N', array('t'));
+ $this->loggerParams = array('hi');
$this->time = 222;
$this->autoPurgeMinimumInterval = 10;
$timeFactory = $this->getMock('TimeFactory', array('getTime'));
$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();
@@ -74,8 +79,7 @@ class FeedBusinessLayerTest extends \PHPUnit_Framework_TestCase {
$this->feedBusinessLayer = new FeedBusinessLayer($this->feedMapper,
$this->fetcher, $this->itemMapper, $this->logger, $this->l10n,
- $timeFactory, $config,
- $this->enhancer, $this->purifier);
+ $timeFactory, $config, $this->enhancer, $this->purifier, $this->loggerParams);
$this->user = 'jack';
}
@@ -344,7 +348,7 @@ class FeedBusinessLayerTest extends \PHPUnit_Framework_TestCase {
->method('fetch')
->will($this->throwException($ex));
$this->logger->expects($this->any())
- ->method('log');
+ ->method('debug');
$this->feedMapper->expects($this->at(1))
->method('find')
diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php
index e94a71ffa..62f53100c 100644
--- a/tests/unit/businesslayer/FolderBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php
@@ -29,7 +29,9 @@ class FolderBusinessLayerTest extends \PHPUnit_Framework_TestCase {
private $l10n;
protected function setUp(){
- $this->l10n = $this->getMock('L10N', array('t'));
+ $this->l10n = $this->getMockBuilder('\OCP\IL10N')
+ ->disableOriginalConstructor()
+ ->getMock();
$this->time = 222;
$timeFactory = $this->getMock('TimeFactory', array('getTime'));
$timeFactory->expects($this->any())
@@ -48,8 +50,7 @@ class FolderBusinessLayerTest extends \PHPUnit_Framework_TestCase {
->method('getAutoPurgeMinimumInterval')
->will($this->returnValue($this->autoPurgeMinimumInterval));
$this->folderBusinessLayer = new FolderBusinessLayer(
- $this->folderMapper, $this->l10n, $timeFactory,
- $config);
+ $this->folderMapper, $this->l10n, $timeFactory, $config);
$this->user = 'hi';
}
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index 930990350..770791ce6 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -15,7 +15,8 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\News\Db\DoesNotExistException;
+use \OCP\AppFramework\Db\DoesNotExistException;
+
use \OCA\News\Db\Item;
use \OCA\News\Db\StatusFlag;
use \OCA\News\Db\FeedType;
diff --git a/tests/unit/controller/EntityApiSerializerTest.php b/tests/unit/controller/EntityApiSerializerTest.php
new file mode 100644
index 000000000..8153f40d6
--- /dev/null
+++ b/tests/unit/controller/EntityApiSerializerTest.php
@@ -0,0 +1,50 @@
+<?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\Controller;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+use \OCA\News\Db\Item;
+
+
+class EntityApiSerializerTest extends \PHPUnit_Framework_TestCase {
+
+
+ public function testSerializeSingle() {
+ $item = new Item();
+ $item->setUnread();
+
+ $serializer = new EntityApiSerializer('items');
+ $result = $serializer->serialize($item);
+
+ $this->assertTrue($result['items'][0]['unread']);
+ }
+
+
+ public function testSerializeMultiple() {
+ $item = new Item();
+ $item->setUnread();
+
+ $item2 = new Item();
+ $item2->setRead();
+
+ $serializer = new EntityApiSerializer('items');
+ $result = $serializer->serialize(array($item, $item2));
+
+ $this->assertTrue($result['items'][0]['unread']);
+ $this->assertFalse($result['items'][1]['unread']);
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/unit/controller/JSONHttpErrorTest.php b/tests/unit/controller/JSONHttpErrorTest.php
new file mode 100644
index 000000000..135095e1f
--- /dev/null
+++ b/tests/unit/controller/JSONHttpErrorTest.php
@@ -0,0 +1,31 @@
+<?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\Controller;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class JSONHttpErrorTest extends \PHPUnit_Framework_TestCase {
+
+
+ public function testError() {
+ $ex = new \Exception('hi');
+ $result = JSONHttpError::error($ex, 3);
+
+ $this->assertEquals(array('message' => 'hi'), $result->getData());
+ $this->assertEquals(3, $result->getStatus());
+ }
+
+
+} \ No newline at end of file
diff --git a/tests/unit/http/TextDownloadResponseTest.php b/tests/unit/http/TextDownloadResponseTest.php
index c7f2e211f..f3dd08181 100644
--- a/tests/unit/http/TextDownloadResponseTest.php
+++ b/tests/unit/http/TextDownloadResponseTest.php
@@ -16,10 +16,9 @@ namespace OCA\News\Http;
require_once(__DIR__ . "/../../classloader.php");
-require_once(__DIR__ . "/DownloadResponseTest.php");
-class TextDownloadResponseTest extends DownloadResponseTest {
+class TextDownloadResponseTest extends \PHPUnit_Framework_TestCase {
protected function setUp() {
diff --git a/tests/unit/utility/ConfigTest.php b/tests/unit/utility/ConfigTest.php
index 186177489..8c1bee0f0 100644
--- a/tests/unit/utility/ConfigTest.php
+++ b/tests/unit/utility/ConfigTest.php
@@ -16,15 +16,16 @@ namespace OCA\News\Utility;
require_once(__DIR__ . "/../../classloader.php");
-class ConfigFetcherTest extends \PHPUnit_Framework_TestCase {
+class ConfigTest extends \PHPUnit_Framework_TestCase {
private $fileSystem;
private $config;
private $configPath;
+ private $loggerParams;
public function setUp() {
$this->logger = $this->getMockBuilder(
- '\OCA\News\Core\Logger')
+ '\OCP\ILogger')
->disableOriginalConstructor()
->getMock();
$this->fileSystem = $this->getMock('FileSystem', array(
@@ -32,7 +33,8 @@ class ConfigFetcherTest extends \PHPUnit_Framework_TestCase {
'file_put_contents',
'file_exists'
));
- $this->config = new Config($this->fileSystem, $this->logger);
+ $this->loggerParams = array('hi');
+ $this->config = new Config($this->fileSystem, $this->logger, $this->loggerParams);
$this->configPath = 'config.json';
}
@@ -83,10 +85,10 @@ class ConfigFetcherTest extends \PHPUnit_Framework_TestCase {
->with($this->equalTo($this->configPath))
->will($this->returnValue('autoPurgeCounts = 3'));
$this->logger->expects($this->once())
- ->method('log')
+ ->method('warning')
->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
'does not exist. Ignored value.'),
- $this->equalTo('warn'));
+ $this->equalTo($this->loggerParams));
$this->config->read($this->configPath);
}
@@ -98,9 +100,9 @@ class ConfigFetcherTest extends \PHPUnit_Framework_TestCase {
->with($this->equalTo($this->configPath))
->will($this->returnValue(''));
$this->logger->expects($this->once())
- ->method('log')
+ ->method('warning')
->with($this->equalTo('Configuration invalid. Ignoring values.'),
- $this->equalTo('warn'));
+ $this->equalTo($this->loggerParams));
$this->config->read($this->configPath);
}
diff --git a/warn b/warn
deleted file mode 100644
index a082caf81..000000000
--- a/warn
+++ /dev/null
@@ -1,12 +0,0 @@
-./businesslayer/feedbusinesslayer.php: $this->logger->debug($ex->getMessage(), $this->loggerParams);
-./businesslayer/feedbusinesslayer.php: $this->logger->debug('Could not update feed ' . $ex->getMessage(),
-./businesslayer/feedbusinesslayer.php: $this->logger->debug('Can not update feed with url ' . $existingFeed->getUrl() .
-./businesslayer/feedbusinesslayer.php: $this->logger->debug($ex->getMessage(), $this->loggerParams);
-./controller/feedapicontroller.php: $this->logger->debug('Could not update feed ' . $ex->getMessage(),
-./appinfo/app.php: $logger->warning($e->getMessage(), $params);
-./tests/unit/businesslayer/FeedBusinessLayerTest.php: $this->logger->expects($this->any())
-./tests/unit/controller/FeedApiControllerTest.php: $this->logger->expects($this->once())
-./tests/unit/utility/ConfigTest.php: $this->logger->expects($this->once())
-./tests/unit/utility/ConfigTest.php: $this->logger->expects($this->once())
-./utility/config.php: $this->logger->warn('Configuration invalid. Ignoring values.',
-./utility/config.php: $this->logger->warn('Configuration value "' . $key .