diff options
author | Sean Molenaar <sean@seanmolenaar.eu> | 2020-09-29 13:54:17 +0200 |
---|---|---|
committer | Benjamin Brahmer <info@b-brahmer.de> | 2020-09-29 14:56:07 +0200 |
commit | 35b53ecd404a74edea3c6866e451c4819bdc9ea8 (patch) | |
tree | dac46834d8fa7ec0122243f94604c3d2215b4d22 /tests/Unit/Controller | |
parent | d6d169be15913404f99b86c39a03bc71942c9f77 (diff) |
OPML export command and fixes
Signed-off-by: Sean Molenaar <sean@seanmolenaar.eu>
Diffstat (limited to 'tests/Unit/Controller')
-rw-r--r-- | tests/Unit/Controller/ExportControllerTest.php | 71 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderApiControllerTest.php | 2 | ||||
-rw-r--r-- | tests/Unit/Controller/FolderControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemApiControllerTest.php | 4 | ||||
-rw-r--r-- | tests/Unit/Controller/ItemControllerTest.php | 16 | ||||
-rw-r--r-- | tests/Unit/Controller/JSONHttpErrorTest.php | 14 | ||||
-rw-r--r-- | tests/Unit/Controller/PageControllerTest.php | 2 |
7 files changed, 63 insertions, 50 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); |