From 7faa40dc59738fc4b5bb9dd2121e433e2301c36b Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Tue, 13 May 2014 23:13:52 +0200 Subject: fix some tests --- tests/unit/businesslayer/BusinessLayerTest.php | 5 ++- tests/unit/businesslayer/FeedBusinessLayerTest.php | 16 ++++--- .../unit/businesslayer/FolderBusinessLayerTest.php | 7 +-- tests/unit/businesslayer/ItemBusinessLayerTest.php | 3 +- tests/unit/controller/EntityApiSerializerTest.php | 50 ++++++++++++++++++++++ tests/unit/controller/JSONHttpErrorTest.php | 31 ++++++++++++++ tests/unit/http/TextDownloadResponseTest.php | 3 +- tests/unit/utility/ConfigTest.php | 16 ++++--- 8 files changed, 110 insertions(+), 21 deletions(-) create mode 100644 tests/unit/controller/EntityApiSerializerTest.php create mode 100644 tests/unit/controller/JSONHttpErrorTest.php (limited to 'tests/unit') 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 @@ + + * @author Bernhard Posselt + * @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 @@ + + * @author Bernhard Posselt + * @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); } -- cgit v1.2.3