summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 23:13:52 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 23:13:52 +0200
commit7faa40dc59738fc4b5bb9dd2121e433e2301c36b (patch)
tree2eac772fb6e39eebbf4349760f5757c6b2547ecf /tests
parentf333f6b38f985c40247f7c82dd462f3016611dfe (diff)
fix some tests
Diffstat (limited to 'tests')
-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
8 files changed, 110 insertions, 21 deletions
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);
}