summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSean Molenaar <sean@seanmolenaar.eu>2020-09-29 13:54:17 +0200
committerBenjamin Brahmer <info@b-brahmer.de>2020-09-29 14:56:07 +0200
commit35b53ecd404a74edea3c6866e451c4819bdc9ea8 (patch)
treedac46834d8fa7ec0122243f94604c3d2215b4d22 /tests
parentd6d169be15913404f99b86c39a03bc71942c9f77 (diff)
OPML export command and fixes
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests')
-rw-r--r--tests/Unit/Controller/ExportControllerTest.php71
-rw-r--r--tests/Unit/Controller/FolderApiControllerTest.php2
-rw-r--r--tests/Unit/Controller/FolderControllerTest.php4
-rw-r--r--tests/Unit/Controller/ItemApiControllerTest.php4
-rw-r--r--tests/Unit/Controller/ItemControllerTest.php16
-rw-r--r--tests/Unit/Controller/JSONHttpErrorTest.php14
-rw-r--r--tests/Unit/Controller/PageControllerTest.php2
-rw-r--r--tests/Unit/Http/TextDownloadResponseTest.php38
-rw-r--r--tests/Unit/Http/TextResponseTest.php51
-rw-r--r--tests/Unit/Service/ServiceTest.php2
10 files changed, 64 insertions, 140 deletions
diff --git a/tests/Unit/Controller/ExportControllerTest.php b/tests/Unit/Controller/ExportControllerTest.php
index 94ffa1ed1..563bd987c 100644
--- a/tests/Unit/Controller/ExportControllerTest.php
+++ b/tests/Unit/Controller/ExportControllerTest.php
@@ -14,14 +14,15 @@
namespace OCA\News\Tests\Unit\Controller;
use OCA\News\Controller\ExportController;
-use OCA\News\Service\FeedService;
-use OCA\News\Service\FolderService;
-use OCA\News\Service\ItemService;
+use OCA\News\Service\FeedServiceV2;
+use OCA\News\Service\FolderServiceV2;
-use \OCA\News\Http\TextDownloadResponse;
+use OCA\News\Service\ItemServiceV2;
+use OCA\News\Service\OpmlService;
use \OCA\News\Utility\OPMLExporter;
use \OCA\News\Db\Item;
use \OCA\News\Db\Feed;
+use OCP\AppFramework\Http\DataDownloadResponse;
use OCP\IRequest;
use PHPUnit\Framework\TestCase;
@@ -29,39 +30,55 @@ use PHPUnit\Framework\TestCase;
class ExportControllerTest extends TestCase
{
- private $appName;
- private $request;
private $controller;
private $user;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|FeedServiceV2
+ */
private $feedService;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|FolderServiceV2
+ */
private $folderService;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|ItemServiceV2
+ */
private $itemService;
- private $opmlExporter;
+ /**
+ * @var \PHPUnit\Framework\MockObject\MockObject|OpmlService
+ */
+ private $opmlService;
/**
* Gets run before each test
*/
public function setUp(): void
{
- $this->appName = 'news';
+ $appName = 'news';
$this->user = 'john';
- $this->itemService = $this->getMockBuilder(ItemService::class)
+ $this->itemService = $this->getMockBuilder(ItemServiceV2::class)
->disableOriginalConstructor()
->getMock();
- $this->feedService = $this->getMockBuilder(FeedService::class)
+ $this->feedService = $this->getMockBuilder(FeedServiceV2::class)
->disableOriginalConstructor()
->getMock();
- $this->folderService = $this->getMockBuilder(FolderService::class)
+ $this->folderService = $this->getMockBuilder(FolderServiceV2::class)
->disableOriginalConstructor()
->getMock();
- $this->request = $this->getMockBuilder(IRequest::class)
+ $this->opmlService = $this->getMockBuilder(OpmlService::class)
+ ->disableOriginalConstructor()
+ ->getMock();
+ $request = $this->getMockBuilder(IRequest::class)
->disableOriginalConstructor()
->getMock();
- $this->opmlExporter = new OPMLExporter();
$this->controller = new ExportController(
- $this->appName, $this->request,
- $this->folderService, $this->feedService,
- $this->itemService, $this->opmlExporter, $this->user
+ $appName,
+ $request,
+ $this->folderService,
+ $this->feedService,
+ $this->itemService,
+ $this->opmlService,
+ $this->user
);
}
@@ -77,17 +94,13 @@ class ExportControllerTest extends TestCase
" <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([]));
+ $this->opmlService->expects($this->once())
+ ->method('export')
+ ->with($this->user)
+ ->will($this->returnValue($opml));
$return = $this->controller->opml();
- $this->assertTrue($return instanceof TextDownloadResponse);
+ $this->assertTrue($return instanceof DataDownloadResponse);
$this->assertEquals($opml, $return->render());
}
@@ -112,12 +125,12 @@ class ExportControllerTest extends TestCase
$articles = [$item1, $item2];
$this->feedService->expects($this->once())
- ->method('findAll')
- ->with($this->equalTo($this->user))
+ ->method('findAllForUser')
+ ->with($this->user)
->will($this->returnValue($feeds));
$this->itemService->expects($this->once())
- ->method('getUnreadOrStarred')
- ->with($this->equalTo($this->user))
+ ->method('findAllForUser')
+ ->with($this->user, ['unread' => true, 'starred' => true])
->will($this->returnValue($articles));
diff --git a/tests/Unit/Controller/FolderApiControllerTest.php b/tests/Unit/Controller/FolderApiControllerTest.php
index de62b887a..3c5650e5c 100644
--- a/tests/Unit/Controller/FolderApiControllerTest.php
+++ b/tests/Unit/Controller/FolderApiControllerTest.php
@@ -81,7 +81,7 @@ class FolderApiControllerTest extends TestCase
$folders = [new Folder()];
$this->folderService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user->getUID()))
->will($this->returnValue($folders));
diff --git a/tests/Unit/Controller/FolderControllerTest.php b/tests/Unit/Controller/FolderControllerTest.php
index ea3454656..94c7b1c53 100644
--- a/tests/Unit/Controller/FolderControllerTest.php
+++ b/tests/Unit/Controller/FolderControllerTest.php
@@ -72,7 +72,7 @@ class FolderControllerTest extends TestCase
{
$return = [new Folder(), new Folder()];
$this->folderService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->will($this->returnValue($return));
$response = $this->controller->index();
@@ -303,7 +303,7 @@ class FolderControllerTest extends TestCase
$this->equalTo($this->user)
);
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue([$feed]));
diff --git a/tests/Unit/Controller/ItemApiControllerTest.php b/tests/Unit/Controller/ItemApiControllerTest.php
index 1360ad872..d2653b92a 100644
--- a/tests/Unit/Controller/ItemApiControllerTest.php
+++ b/tests/Unit/Controller/ItemApiControllerTest.php
@@ -80,7 +80,7 @@ class ItemApiControllerTest extends TestCase
$item->setFeedId(123);
$this->itemService->expects($this->once())
- ->method('findAll')
+ ->method('findAllItems')
->with(
$this->equalTo(2),
$this->equalTo(1),
@@ -111,7 +111,7 @@ class ItemApiControllerTest extends TestCase
$item->setFeedId(123);
$this->itemService->expects($this->once())
- ->method('findAll')
+ ->method('findAllItems')
->with(
$this->equalTo(2),
$this->equalTo(1),
diff --git a/tests/Unit/Controller/ItemControllerTest.php b/tests/Unit/Controller/ItemControllerTest.php
index a0780cecb..c69191423 100644
--- a/tests/Unit/Controller/ItemControllerTest.php
+++ b/tests/Unit/Controller/ItemControllerTest.php
@@ -181,7 +181,7 @@ class ItemControllerTest extends TestCase
$this->equalTo($this->user)
);
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue([$feed]));
@@ -240,7 +240,7 @@ class ItemControllerTest extends TestCase
$this->itemsApiExpects(2, FeedType::FEED, '0');
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
@@ -255,7 +255,7 @@ class ItemControllerTest extends TestCase
->will($this->returnValue(3111));
$this->itemService->expects($this->once())
- ->method('findAll')
+ ->method('findAllItems')
->with(
$this->equalTo(2),
$this->equalTo(FeedType::FEED),
@@ -286,7 +286,7 @@ class ItemControllerTest extends TestCase
$this->itemsApiExpects(2, FeedType::FEED, '0');
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
@@ -301,7 +301,7 @@ class ItemControllerTest extends TestCase
->will($this->returnValue(3111));
$this->itemService->expects($this->once())
- ->method('findAll')
+ ->method('findAllItems')
->with(
$this->equalTo(2),
$this->equalTo(FeedType::FEED),
@@ -329,7 +329,7 @@ class ItemControllerTest extends TestCase
$this->itemsApiExpects(2, FeedType::FEED);
$this->itemService->expects($this->once())
- ->method('findAll')
+ ->method('findAllItems')
->with(
$this->equalTo(2),
$this->equalTo(FeedType::FEED),
@@ -342,7 +342,7 @@ class ItemControllerTest extends TestCase
->will($this->returnValue($result['items']));
$this->feedService->expects($this->never())
- ->method('findAll');
+ ->method('findAllForUser');
$response = $this->controller->index(FeedType::FEED, 2, 3, 10);
$this->assertEquals($result, $response);
@@ -383,7 +383,7 @@ class ItemControllerTest extends TestCase
->will($this->returnValue('1'));
$this->feedService->expects($this->once())
- ->method('findAll')
+ ->method('findAllForUser')
->with($this->equalTo($this->user))
->will($this->returnValue($feeds));
diff --git a/tests/Unit/Controller/JSONHttpErrorTest.php b/tests/Unit/Controller/JSONHttpErrorTest.php
index 3b48bc36e..8bfb11f3e 100644
--- a/tests/Unit/Controller/JSONHttpErrorTest.php
+++ b/tests/Unit/Controller/JSONHttpErrorTest.php
@@ -14,14 +14,8 @@
namespace OCA\News\Tests\Unit\Controller;
use OCA\News\Controller\JSONHttpErrorTrait;
-
use PHPUnit\Framework\TestCase;
-class Test
-{
- use JSONHttpErrorTrait;
-}
-
class JSONHttpErrorTest extends TestCase
{
@@ -29,7 +23,7 @@ class JSONHttpErrorTest extends TestCase
public function testError()
{
$ex = new \Exception('hi');
- $test = new Test();
+ $test = new DummyTraitingClass();
$result = $test->error($ex, 3);
$this->assertEquals(['message' => 'hi'], $result->getData());
@@ -37,4 +31,10 @@ class JSONHttpErrorTest extends TestCase
}
+}
+
+
+class DummyTraitingClass
+{
+ use JSONHttpErrorTrait;
} \ No newline at end of file
diff --git a/tests/Unit/Controller/PageControllerTest.php b/tests/Unit/Controller/PageControllerTest.php
index 69fed0d77..fe263f242 100644
--- a/tests/Unit/Controller/PageControllerTest.php
+++ b/tests/Unit/Controller/PageControllerTest.php
@@ -255,7 +255,7 @@ class PageControllerTest extends TestCase
public function testExplore()
{
- $in = 'test';
+ $in = ['test'];
$this->settings->expects($this->at(0))
->method('setUserValue')
->with('becka', 'news', 'lastViewedFeedId', 0);
diff --git a/tests/Unit/Http/TextDownloadResponseTest.php b/tests/Unit/Http/TextDownloadResponseTest.php
deleted file mode 100644
index be5f53ec1..000000000
--- a/tests/Unit/Http/TextDownloadResponseTest.php
+++ /dev/null
@@ -1,38 +0,0 @@
-<?php
-/**
- * Nextcloud - 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 2012 Alessandro Cosentino
- * @copyright 2012-2014 Bernhard Posselt
- */
-
-
-namespace OCA\News\Tests\Unit\Http;
-
-
-use OCA\News\Http\TextDownloadResponse;
-use PHPUnit\Framework\TestCase;
-
-class TextDownloadResponseTest extends TestCase
-{
-
-
- protected function setUp(): void
- {
- $this->response = new TextDownloadResponse(
- 'sometext', 'file', 'content'
- );
- }
-
-
- public function testRender()
- {
- $this->assertEquals('sometext', $this->response->render());
- }
-
-} \ No newline at end of file
diff --git a/tests/Unit/Http/TextResponseTest.php b/tests/Unit/Http/TextResponseTest.php
deleted file mode 100644
index eaad769b5..000000000
--- a/tests/Unit/Http/TextResponseTest.php
+++ /dev/null
@@ -1,51 +0,0 @@
-<?php
-/**
- * Nextcloud - 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 2012 Alessandro Cosentino
- * @copyright 2012-2014 Bernhard Posselt
- */
-
-
-namespace OCA\News\Tests\Unit\Http;
-
-use PHPUnit\Framework\TestCase;
-use OCA\News\Http\TextResponse;
-
-class TextResponseTest extends TestCase
-{
-
-
- protected function setUp(): void
- {
- $this->response = new TextResponse('sometext');
- }
-
-
- public function testRender()
- {
- $this->assertEquals('sometext', $this->response->render());
- }
-
- public function testContentTypeDefaultsToText()
- {
- $headers = $this->response->getHeaders();
-
- $this->assertEquals('text/plain', $headers['Content-type']);
- }
-
-
- public function testContentTypeIsSetableViaConstructor()
- {
- $response = new TextResponse('sometext', 'html');
- $headers = $response->getHeaders();
-
- $this->assertEquals('text/html', $headers['Content-type']);
- }
-
-} \ No newline at end of file
diff --git a/tests/Unit/Service/ServiceTest.php b/tests/Unit/Service/ServiceTest.php
index e243efb3f..4b6c6b03d 100644
--- a/tests/Unit/Service/ServiceTest.php
+++ b/tests/Unit/Service/ServiceTest.php
@@ -32,7 +32,7 @@ class TestLegacyService extends Service
parent::__construct($mapper, $logger);
}
- public function findAllForUser(string $userId): array
+ public function findAllForUser(string $userId, array $params = []): array
{
// TODO: Implement findAllForUser() method.
}