summaryrefslogtreecommitdiffstats
path: root/tests/unit
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2016-07-23 21:24:54 +0200
commit004fcbbcc7609ca83807f2e38967ef54f469bf72 (patch)
tree49eb99b4ea92b2045793fc567f719b31ec7f9042 /tests/unit
parent60abc0ed4438c9b6fda245b0dc33cb483bc2aeaf (diff)
Move to new directory structure
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/config/ConfigTest.php230
-rw-r--r--tests/unit/controller/AdminControllerTest.php161
-rw-r--r--tests/unit/controller/EntityApiSerializerTest.php116
-rw-r--r--tests/unit/controller/ExportControllerTest.php131
-rw-r--r--tests/unit/controller/FeedApiControllerTest.php353
-rw-r--r--tests/unit/controller/FeedControllerTest.php484
-rw-r--r--tests/unit/controller/FolderApiControllerTest.php255
-rw-r--r--tests/unit/controller/FolderControllerTest.php306
-rw-r--r--tests/unit/controller/ItemApiControllerTest.php372
-rw-r--r--tests/unit/controller/ItemControllerTest.php384
-rw-r--r--tests/unit/controller/JSONHttpErrorTest.php34
-rw-r--r--tests/unit/controller/PageControllerTest.php322
-rw-r--r--tests/unit/controller/UserApiControllerTest.php141
-rw-r--r--tests/unit/controller/UtilityApiControllerTest.php90
-rw-r--r--tests/unit/db/FeedMapperTest.php306
-rw-r--r--tests/unit/db/FeedTest.php116
-rw-r--r--tests/unit/db/FolderMapperTest.php196
-rw-r--r--tests/unit/db/FolderTest.php50
-rw-r--r--tests/unit/db/ItemMapperTest.php550
-rw-r--r--tests/unit/db/ItemTest.php316
-rw-r--r--tests/unit/db/MapperFactoryTest.php50
-rw-r--r--tests/unit/db/mappertestutility.php208
-rw-r--r--tests/unit/db/mysql/ItemMapperTest.php119
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php386
-rw-r--r--tests/unit/fetcher/FetcherTest.php137
-rw-r--r--tests/unit/fetcher/YoutubeFetcherTest.php68
-rw-r--r--tests/unit/http/TextDownloadResponseTest.php32
-rw-r--r--tests/unit/http/TextResponseTest.php44
-rw-r--r--tests/unit/service/FeedServiceTest.php1060
-rw-r--r--tests/unit/service/FolderServiceTest.php282
-rw-r--r--tests/unit/service/ItemServiceTest.php443
-rw-r--r--tests/unit/service/ServiceTest.php98
-rw-r--r--tests/unit/service/StatusFlagTest.php57
-rw-r--r--tests/unit/service/StatusServiceTest.php89
-rw-r--r--tests/unit/upgrade/UpgradeTest.php72
-rw-r--r--tests/unit/utility/OPMLExporterTest.php123
-rw-r--r--tests/unit/utility/ProxyConfigParserTest.php93
-rw-r--r--tests/unit/utility/UpdaterTest.php62
38 files changed, 0 insertions, 8336 deletions
diff --git a/tests/unit/config/ConfigTest.php b/tests/unit/config/ConfigTest.php
deleted file mode 100644
index a30601403..000000000
--- a/tests/unit/config/ConfigTest.php
+++ /dev/null
@@ -1,230 +0,0 @@
-<?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\Config;
-
-use PHPUnit_Framework_TestCase;
-
-
-class ConfigTest extends PHPUnit_Framework_TestCase {
-
- private $fileSystem;
- private $config;
- private $configPath;
- private $loggerParams;
-
- public function setUp() {
- $this->logger = $this->getMockBuilder(
- 'OCP\ILogger')
- ->disableOriginalConstructor()
- ->getMock();
- $this->fileSystem = $this->getMockBuilder('OCP\Files\Folder')->getMock();
- $this->loggerParams = ['hi'];
- $this->config = new Config(
- $this->fileSystem, $this->logger, $this->loggerParams
- );
- $this->configPath = 'config.json';
- }
-
-
- public function testDefaults() {
- $this->assertEquals(60, $this->config->getAutoPurgeMinimumInterval());
- $this->assertEquals(200, $this->config->getAutoPurgeCount());
- $this->assertEquals(10, $this->config->getMaxRedirects());
- $this->assertEquals(60, $this->config->getFeedFetcherTimeout());
- $this->assertEquals(true, $this->config->getUseCronUpdates());
- $this->assertEquals('', $this->config->getExploreUrl());
- $this->assertEquals(1024*1024*100, $this->config->getMaxSize());
- }
-
-
- public function testRead () {
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('getContent')
- ->will($this->returnValue(
- 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = true'
- ));
-
-
- $this->config->read($this->configPath);
-
- $this->assertSame(3, $this->config->getAutoPurgeCount());
- $this->assertSame(true, $this->config->getUseCronUpdates());
- }
-
-
- public function testReadIgnoresVeryLowPurgeInterval () {
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('getContent')
- ->will($this->returnValue('autoPurgeMinimumInterval = 59'));
-
- $this->config->read($this->configPath);
-
- $this->assertSame(60, $this->config->getAutoPurgeMinimumInterval());
- }
-
-
-
- public function testReadBool () {
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('getContent')
- ->will($this->returnValue(
- 'autoPurgeCount = 3' . "\n" . 'useCronUpdates = false')
- );
-
- $this->config->read($this->configPath);
-
- $this->assertSame(3, $this->config->getAutoPurgeCount());
- $this->assertSame(false, $this->config->getUseCronUpdates());
- }
-
-
- public function testReadLogsInvalidValue() {
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('getContent')
- ->will($this->returnValue('autoPurgeCounts = 3'));
- $this->logger->expects($this->once())
- ->method('warning')
- ->with($this->equalTo('Configuration value "autoPurgeCounts" ' .
- 'does not exist. Ignored value.'),
- $this->equalTo($this->loggerParams));
-
- $this->config->read($this->configPath);
- }
-
-
- public function testReadLogsInvalidINI() {
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('getContent')
- ->will($this->returnValue(''));
- $this->logger->expects($this->once())
- ->method('warning')
- ->with($this->equalTo('Configuration invalid. Ignoring values.'),
- $this->equalTo($this->loggerParams));
-
- $this->config->read($this->configPath);
- }
-
-
- public function testWrite () {
- $json = 'autoPurgeMinimumInterval = 60' . "\n" .
- 'autoPurgeCount = 3' . "\n" .
- 'maxRedirects = 10' . "\n" .
- 'maxSize = 399' . "\n" .
- 'exploreUrl = http://google.de' . "\n" .
- 'feedFetcherTimeout = 60' . "\n" .
- 'useCronUpdates = true';
- $this->config->setAutoPurgeCount(3);
- $this->config->setMaxSize(399);
- $this->config->setExploreUrl('http://google.de');
-
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('putContent')
- ->with($this->equalTo($json));
-
- $this->config->write($this->configPath);
- }
-
-
-
- public function testReadingNonExistentConfigWillWriteDefaults() {
- $this->fileSystem->expects($this->once())
- ->method('nodeExists')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue(false));
-
- $this->config->setUseCronUpdates(false);
-
- $json = 'autoPurgeMinimumInterval = 60' . "\n" .
- 'autoPurgeCount = 200' . "\n" .
- 'maxRedirects = 10' . "\n" .
- 'maxSize = 104857600' . "\n" .
- 'exploreUrl = ' . "\n" .
- 'feedFetcherTimeout = 60' . "\n" .
- 'useCronUpdates = false';
-
- $this->fileSystem->expects($this->once())
- ->method('newFile')
- ->with($this->equalTo($this->configPath));
- $file = $this->getMockBuilder('OCP\Files\File')->getMock();
- $this->fileSystem->expects($this->once())
- ->method('get')
- ->with($this->equalTo($this->configPath))
- ->will($this->returnValue($file));
- $file->expects($this->once())
- ->method('putContent')
- ->with($this->equalTo($json));
-
- $this->config->read($this->configPath, true);
- }
-
-
- 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 testMaxRedirects() {
- $this->config->setMaxRedirects(21);
- $redirects = $this->config->getMaxRedirects();
-
- $this->assertSame(21, $redirects);
- }
-
- public function testFeedFetcherTimeout() {
- $this->config->setFeedFetcherTimeout(2);
- $timout = $this->config->getFeedFetcherTimeout();
-
- $this->assertSame(2, $timout);
- }
-}
diff --git a/tests/unit/controller/AdminControllerTest.php b/tests/unit/controller/AdminControllerTest.php
deleted file mode 100644
index 9d5014636..000000000
--- a/tests/unit/controller/AdminControllerTest.php
+++ /dev/null
@@ -1,161 +0,0 @@
-<?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;
-
-
-class AdminControllerTest extends \PHPUnit_Framework_TestCase {
-
- private $appName;
- private $request;
- private $controller;
- private $config;
- private $configPath;
- private $itemService;
-
- /**
- * Gets run before each test
- */
- public function setUp(){
- $this->appName = 'news';
- $this->request = $this->getMockBuilder(
- '\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->config = $this->getMockBuilder(
- '\OCA\News\Config\Config')
- ->disableOriginalConstructor()
- ->getMock();
- $this->itemService = $this->getMockBuilder(
- '\OCA\News\Service\ItemService')
- ->disableOriginalConstructor()
- ->getMock();
-
- $this->configPath = 'my.ini';
- $this->controller = new AdminController($this->appName, $this->request,
- $this->config, $this->itemService, $this->configPath);
- }
-
-
- public function testIndex() {
- $expected = [
- 'autoPurgeMinimumInterval' => 1,
- 'autoPurgeCount' => 2,
- 'maxRedirects' => 3,
- 'feedFetcherTimeout' => 4,
- 'useCronUpdates' => 5,
- 'maxSize' => 7,
- 'exploreUrl' => 'test'
- ];
- $this->config->expects($this->once())
- ->method('getAutoPurgeMinimumInterval')
- ->will($this->returnValue($expected['autoPurgeMinimumInterval']));
- $this->config->expects($this->once())
- ->method('getAutoPurgeCount')
- ->will($this->returnValue($expected['autoPurgeCount']));
- $this->config->expects($this->once())
- ->method('getMaxRedirects')
- ->will($this->returnValue($expected['maxRedirects']));
- $this->config->expects($this->once())
- ->method('getFeedFetcherTimeout')
- ->will($this->returnValue($expected['feedFetcherTimeout']));
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue($expected['useCronUpdates']));
- $this->config->expects($this->once())
- ->method('getMaxSize')
- ->will($this->returnValue($expected['maxSize']));
- $this->config->expects($this->once())
- ->method('getExploreUrl')
- ->will($this->returnValue($expected['exploreUrl']));
-
- $response = $this->controller->index();
- $data = $response->getParams();
- $name = $response->getTemplateName();
- $type = $response->getRenderAs();
-
- $this->assertEquals($type, 'blank');
- $this->assertEquals($name, 'admin');
- $this->assertEquals($expected, $data);
- }
-
-
- public function testUpdate() {
- $expected = [
- 'autoPurgeMinimumInterval' => 1,
- 'autoPurgeCount' => 2,
- 'maxRedirects' => 3,
- 'feedFetcherTimeout' => 4,
- 'useCronUpdates' => 5,
- 'maxSize' => 7,
- 'exploreUrl' => 'test'
- ];
-
- $this->config->expects($this->once())
- ->method('setAutoPurgeMinimumInterval')
- ->with($this->equalTo($expected['autoPurgeMinimumInterval']));
- $this->config->expects($this->once())
- ->method('setAutoPurgeCount')
- ->with($this->equalTo($expected['autoPurgeCount']));
- $this->config->expects($this->once())
- ->method('setMaxRedirects')
- ->with($this->equalTo($expected['maxRedirects']));
- $this->config->expects($this->once())
- ->method('setFeedFetcherTimeout')
- ->with($this->equalTo($expected['feedFetcherTimeout']));
- $this->config->expects($this->once())
- ->method('setUseCronUpdates')
- ->with($this->equalTo($expected['useCronUpdates']));
- $this->config->expects($this->once())
- ->method('setExploreUrl')
- ->with($this->equalTo($expected['exploreUrl']));
- $this->config->expects($this->once())
- ->method('write')
- ->with($this->equalTo($this->configPath));
-
- $this->config->expects($this->once())
- ->method('getAutoPurgeMinimumInterval')
- ->will($this->returnValue($expected['autoPurgeMinimumInterval']));
- $this->config->expects($this->once())
- ->method('getAutoPurgeCount')
- ->will($this->returnValue($expected['autoPurgeCount']));
- $this->config->expects($this->once())
- ->method('getMaxRedirects')
- ->will($this->returnValue($expected['maxRedirects']));
- $this->config->expects($this->once())
- ->method('getFeedFetcherTimeout')
- ->will($this->returnValue($expected['feedFetcherTimeout']));
- $this->config->expects($this->once())
- ->method('getUseCronUpdates')
- ->will($this->returnValue($expected['useCronUpdates']));
- $this->config->expects($this->once())
- ->method('getMaxSize')
- ->will($this->returnValue($expected['maxSize']));
- $this->config->expects($this->once())
- ->method('getExploreUrl')
- ->will($this->returnValue($expected['exploreUrl']));
-
- $response = $this->controller->update(
- $expected['autoPurgeMinimumInterval'],
- $expected['autoPurgeCount'],
- $expected['maxRedirects'],
- $expected['feedFetcherTimeout'],
- $expected['maxSize'],
- $expected['useCronUpdates'],
- $expected['exploreUrl']
- );
-
- $this->assertEquals($expected, $response);
- }
-
-}
diff --git a/tests/unit/controller/EntityApiSerializerTest.php b/tests/unit/controller/EntityApiSerializerTest.php
deleted file mode 100644
index 80752889d..000000000
--- a/tests/unit/controller/EntityApiSerializerTest.php
+++ /dev/null
@@ -1,116 +0,0 @@
-<?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;
-
-
-use \OCP\AppFramework\Http\Response;
-use \OCP\AppFramework\Db\Entity;
-
-use \OCA\News\Db\Item;
-
-class TestEntity extends Entity {
-
-}
-
-
-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([$item, $item2]);
-
- $this->assertTrue($result['items'][0]['unread']);
- $this->assertFalse($result['items'][1]['unread']);
- }
-
-
- public function testResponseNoChange() {
- $response = new Response();
- $serializer = new EntityApiSerializer('items');
-
- $result = $serializer->serialize($response);
-
- $this->assertEquals($response, $result);
- }
-
-
- public function testCompleteArraysTransformed() {
- $item = new Item();
- $item->setUnread();
-
- $item2 = new Item();
- $item2->setRead();
-
- $serializer = new EntityApiSerializer('items');
-
- $in = [
- 'items' => [$item, $item2],
- 'test' => 1
- ];
-
- $result = $serializer->serialize($in);
-
- $this->assertTrue($result['items'][0]['unread']);
- $this->assertFalse($result['items'][1]['unread']);
- $this->assertEquals(1, $result['test']);
- }
-
-
- public function testNoEntityNoChange() {
- $serializer = new EntityApiSerializer('items');
-
- $in = [
- 'items' => ['hi', '2'],
- 'test' => 1
- ];
-
- $result = $serializer->serialize($in);
-
- $this->assertEquals('hi', $result['items'][0]);
- $this->assertEquals('2', $result['items'][1]);
- $this->assertEquals(1, $result['test']);
- }
-
-
- public function testEntitiesNoChange() {
- $serializer = new EntityApiSerializer('items');
-
- $in = [
- 'items' => [new TestEntity()]
- ];
-
- $result = $serializer->serialize($in);
-
- $this->assertEquals($in, $result);
- }
-} \ No newline at end of file
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php
deleted file mode 100644
index 6e7df683e..000000000
--- a/tests/unit/controller/ExportControllerTest.php
+++ /dev/null
@@ -1,131 +0,0 @@
-<?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;
-
-use \OCP\AppFramework\Http;
-
-use \OCA\News\Http\TextDownloadResponse;
-use \OCA\News\Utility\OPMLExporter;
-use \OCA\News\Db\Item;
-use \OCA\News\Db\Feed;
-
-
-class ExportControllerTest extends \PHPUnit_Framework_TestCase {
-
- private $appName;
- private $request;
- private $controller;
- private $user;
- private $feedService;
- private $folderService;
- private $itemService;
- private $opmlExporter;
-
- /**
- * Gets run before each test
- */
- public function setUp(){
- $this->appName = 'news';
- $this->user = 'john';
- $this->itemService = $this->getMockBuilder(
- '\OCA\News\Service\ItemService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->feedService = $this->getMockBuilder(
- '\OCA\News\Service\FeedService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->folderService = $this->getMockBuilder(
- '\OCA\News\Service\FolderService')
- ->disableOriginalConstructor()
- ->getMock();
- $this->request = $this->getMockBuilder('\OCP\IRequest')
- ->disableOriginalConstructor()
- ->getMock();
- $this->opmlExporter = new OPMLExporter();
- $this->controller = new ExportController($this->appName, $this->request,
- $this->folderService, $this->feedService,
- $this->itemService, $this->opmlExporter, $this->user);
- }
-
-
- public function testOpmlExportNoFeeds(){
- $opml =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" .
- "<opml version=\"2.0\">\n" .
- " <head>\n" .
- " <title>Subscriptions</title>\n" .
- " </head>\n" .
- " <body/>\n" .
- "</opml>\n";
-
- $this->feedService->expects($this->once())
- ->method('findAll')
- ->with($this->equalTo($this->user))
- ->will($this->returnValue([]));
- $this->folderService->expects($this->once())
- ->method('findAll')
- ->with($this->equalTo($this->user))
- ->will($this->returnValue([]));
-
- $return = $this->controller->opml();
- $this->assertTrue($return instanceof TextDownloadResponse);
- $this->assertEquals($opml, $return->render());
- }
-
-
- public function testGetAllArticles(){
- $item1 = new Item();