diff options
Diffstat (limited to 'tests/unit/controller')
-rw-r--r-- | tests/unit/controller/ExportControllerTest.php | 200 | ||||
-rw-r--r-- | tests/unit/controller/FeedApiControllerTest.php | 576 | ||||
-rw-r--r-- | tests/unit/controller/FeedControllerTest.php | 778 | ||||
-rw-r--r-- | tests/unit/controller/FolderApiControllerTest.php | 332 | ||||
-rw-r--r-- | tests/unit/controller/FolderControllerTest.php | 422 | ||||
-rw-r--r-- | tests/unit/controller/ItemApiControllerTest.php | 674 | ||||
-rw-r--r-- | tests/unit/controller/ItemControllerTest.php | 620 | ||||
-rw-r--r-- | tests/unit/controller/PageControllerTest.php | 234 | ||||
-rw-r--r-- | tests/unit/controller/UtilityApiControllerTest.php | 84 |
9 files changed, 1960 insertions, 1960 deletions
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 28d69c6f3..29760e6f4 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -23,105 +23,105 @@ 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(); - $item1->setFeedId(3); - $item2 = new Item(); - $item2->setFeedId(5); - - $feed1 = new Feed(); - $feed1->setId(3); - $feed1->setLink('http://goo'); - $feed2 = new Feed(); - $feed2->setId(5); - $feed2->setLink('http://gee'); - $feeds = [$feed1, $feed2]; - - $articles = [$item1, $item2]; - - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($feeds)); - $this->itemService->expects($this->once()) - ->method('getUnreadOrStarred') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($articles)); - - - $return = $this->controller->articles(); - $headers = $return->getHeaders(); - $this->assertEquals('attachment; filename="articles.json"', $headers ['Content-Disposition']); - - $this->assertEquals('[{"guid":null,"url":null,"title":null,' . - '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . - '"enclosureLink":null,"unread":false,"starred":false,' . - '"feedLink":"http:\/\/goo"},{"guid":null,"url":null,"title":null,' . - '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . - '"enclosureLink":null,"unread":false,"starred":false,' . - '"feedLink":"http:\/\/gee"}]', $return->render()); - } + 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(); + $item1->setFeedId(3); + $item2 = new Item(); + $item2->setFeedId(5); + + $feed1 = new Feed(); + $feed1->setId(3); + $feed1->setLink('http://goo'); + $feed2 = new Feed(); + $feed2->setId(5); + $feed2->setLink('http://gee'); + $feeds = [$feed1, $feed2]; + + $articles = [$item1, $item2]; + + $this->feedService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->itemService->expects($this->once()) + ->method('getUnreadOrStarred') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($articles)); + + + $return = $this->controller->articles(); + $headers = $return->getHeaders(); + $this->assertEquals('attachment; filename="articles.json"', $headers ['Content-Disposition']); + + $this->assertEquals('[{"guid":null,"url":null,"title":null,' . + '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . + '"enclosureLink":null,"unread":false,"starred":false,' . + '"feedLink":"http:\/\/goo"},{"guid":null,"url":null,"title":null,' . + '"author":null,"pubDate":null,"body":null,"enclosureMime":null,' . + '"enclosureLink":null,"unread":false,"starred":false,' . + '"feedLink":"http:\/\/gee"}]', $return->render()); + } }
\ No newline at end of file diff --git a/tests/unit/controller/FeedApiControllerTest.php b/tests/unit/controller/FeedApiControllerTest.php index 8dff56f2e..d14782856 100644 --- a/tests/unit/controller/FeedApiControllerTest.php +++ b/tests/unit/controller/FeedApiControllerTest.php @@ -24,322 +24,322 @@ use \OCA\News\Db\Item; class FeedApiControllerTest extends \PHPUnit_Framework_TestCase { - private $feedService; - private $itemService; - private $feedAPI; - private $appName; - private $user; - private $request; - private $msg; - private $logger; - private $loggerParams; - - protected function setUp() { - $this->user = 'tom'; - $this->loggerParams = ['hi']; - $this->logger = $this->getMockBuilder( - '\OCP\ILogger') - ->disableOriginalConstructor() - ->getMock(); - $this->appName = 'news'; - $this->request = $this->getMockBuilder( - '\OCP\IRequest') - ->disableOriginalConstructor() - ->getMock(); - $this->feedService = $this->getMockBuilder( - '\OCA\News\Service\FeedService') - ->disableOriginalConstructor() - ->getMock(); - $this->itemService = $this->getMockBuilder( - '\OCA\News\Service\ItemService') - ->disableOriginalConstructor() - ->getMock(); - $this->feedAPI = new FeedApiController( - $this->appName, - $this->request, - $this->feedService, - $this->itemService, - $this->logger, - $this->user, - $this->loggerParams - ); - $this->msg = 'hohoho'; - } - - - public function testIndex() { - $feeds = [new Feed()]; - $starredCount = 3; - $newestItemId = 2; - - $this->itemService->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($starredCount)); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($newestItemId)); - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($feeds)); - - $response = $this->feedAPI->index(); - - $this->assertEquals([ - 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, - 'newestItemId' => $newestItemId - ], $response); - } - - - public function testIndexNoNewestItemId() { - $feeds = [new Feed()]; - $starredCount = 3; - - $this->itemService->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($starredCount)); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo($this->user)) - ->will($this->throwException(new ServiceNotFoundException(''))); - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($feeds)); - - $response = $this->feedAPI->index(); - - $this->assertEquals([ - 'feeds' => [$feeds[0]->toAPI()], - 'starredCount' => $starredCount, - ], $response); - } - - - public function testDelete() { - $this->feedService->expects($this->once()) - ->method('delete') - ->with( - $this->equalTo(2), - $this->equalTo($this->user)); - - $this->feedAPI->delete(2); - } - - - public function testDeleteDoesNotExist() { - $this->feedService->expects($this->once()) - ->method('delete') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); - - $response = $this->feedAPI->delete(2); - - $data = $response->getData(); - $this->assertEquals($this->msg, $data['message']); - $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); - } - - - public function testCreate() { - $feeds = [new Feed()]; - - $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedService->expects($this->once()) - ->method('create') - ->with( - $this->equalTo('url'), - $this->equalTo(3), - $this->equalTo($this->user)) - ->will($this->returnValue($feeds[0])); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->returnValue(3)); - - $response = $this->feedAPI->create('url', 3); - - $this->assertEquals([ - 'feeds' => [$feeds[0]->toAPI()], - 'newestItemId' => 3 - ], $response); - } - - - public function testCreateNoItems() { - $feeds = [new Feed()]; - - $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedService->expects($this->once()) - ->method('create') - ->with( - $this->equalTo('ho'), - $this->equalTo(3), - $this->equalTo($this->user)) - ->will($this->returnValue($feeds[0])); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->will($this->throwException(new ServiceNotFoundException(''))); - - $response = $this->feedAPI->create('ho', 3); - - $this->assertEquals([ - 'feeds' => [$feeds[0]->toAPI()] - ], $response); - } - - - - public function testCreateExists() { - $this->feedService->expects($this->once()) - ->method('purgeDeleted') - ->with($this->equalTo($this->user), $this->equalTo(false)); - $this->feedService->expects($this->once()) - ->method('create') - ->will($this->throwException(new ServiceConflictException($this->msg))); - - $response = $this->feedAPI->create('ho', 3); - - $data = $response->getData(); - $this->assertEquals($this->msg, $data['message']); - $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus()); - } + private $feedService; + private $itemService; + private $feedAPI; + private $appName; + private $user; + private $request; + private $msg; + private $logger; + private $loggerParams; + + protected function setUp() { + $this->user = 'tom'; + $this->loggerParams = ['hi']; + $this->logger = $this->getMockBuilder( + '\OCP\ILogger') + ->disableOriginalConstructor() + ->getMock(); + $this->appName = 'news'; + $this->request = $this->getMockBuilder( + '\OCP\IRequest') + ->disableOriginalConstructor() + ->getMock(); + $this->feedService = $this->getMockBuilder( + '\OCA\News\Service\FeedService') + ->disableOriginalConstructor() + ->getMock(); + $this->itemService = $this->getMockBuilder( + '\OCA\News\Service\ItemService') + ->disableOriginalConstructor() + ->getMock(); + $this->feedAPI = new FeedApiController( + $this->appName, + $this->request, + $this->feedService, + $this->itemService, + $this->logger, + $this->user, + $this->loggerParams + ); + $this->msg = 'hohoho'; + } + + + public function testIndex() { + $feeds = [new Feed()]; + $starredCount = 3; + $newestItemId = 2; + + $this->itemService->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($starredCount)); + $this->itemService->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($newestItemId)); + $this->feedService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + + $response = $this->feedAPI->index(); + + $this->assertEquals([ + 'feeds' => [$feeds[0]->toAPI()], + 'starredCount' => $starredCount, + 'newestItemId' => $newestItemId + ], $response); + } + + + public function testIndexNoNewestItemId() { + $feeds = [new Feed()]; + $starredCount = 3; + + $this->itemService->expects($this->once()) + ->method('starredCount') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($starredCount)); + $this->itemService->expects($this->once()) + ->method('getNewestItemId') + ->with($this->equalTo($this->user)) + ->will($this->throwException(new ServiceNotFoundException(''))); + $this->feedService->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + + $response = $this->feedAPI->index(); + + $this->assertEquals([ + 'feeds' => [$feeds[0]->toAPI()], + 'starredCount' => $starredCount, + ], $response); + } + + + public function testDelete() { + $this->feedService->expects($this->once()) + ->method('delete') + ->with( + $this->equalTo(2), + $this->equalTo($this->user)); + + $this->feedAPI->delete(2); + } + + + public function testDeleteDoesNotExist() { + $this->feedService->expects($this->once()) + ->method('delete') + ->will($this->throwException(new ServiceNotFoundException($this->msg))); + + $response = $this->feedAPI->delete(2); + + $data = $response->getData(); + $this->assertEquals($this->msg, $data['message']); + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); + } + + + public function testCreate() { + $feeds = [new Feed()]; + + $this->feedService->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user), $this->equalTo(false)); + $this->feedService->expects($this->once()) + ->method('create') + ->with( + $this->equalTo('url'), + $this->equalTo(3), + $this->equalTo($this->user)) + ->will($this->returnValue($feeds[0])); + $this->itemService->expects($this->once()) + ->method('getNewestItemId') + ->will($this->returnValue(3)); + + $response = $this->feedAPI->create('url', 3); + + $this->assertEquals([ + 'feeds' => [$feeds[0]->toAPI()], + 'newestItemId' => 3 + ], $response); + } + + + public function testCreateNoItems() { + $feeds = [new Feed()]; + + $this->feedService->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user), $this->equalTo(false)); + $this->feedService->expects($this->once()) + ->method('create') + ->with( + $this->equalTo('ho'), + $this->equalTo(3), + $this->equalTo($this->user)) + ->will($this->returnValue($feeds[0])); + $this->itemService->expects($this->once()) + ->method('getNewestItemId') + ->will($this->throwException(new ServiceNotFoundException(''))); + + $response = $this->feedAPI->create('ho', 3); + + $this->assertEquals([ + 'feeds' => [$feeds[0]->toAPI()] + ], $response); + } + + + + public function testCreateExists() { + $this->feedService->expects($this->once()) + ->method('purgeDeleted') + ->with($this->equalTo($this->user), $this->equalTo(false)); + $this->feedService->expects($this->once()) + ->method('create') + ->will($this->throwException(new ServiceConflictException($this->msg))); + + $response = $this->feedAPI->create('ho', 3); + + $data = $response->getData(); + $this->assertEquals($this->msg, $data['message']); + $this->assertEquals(Http::STATUS_CONFLICT, $response->getStatus()); + } - public function testCreateError() { - $this->feedService->expects($this->once()) - ->method('create') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + public function testCreateError() { + $this->feedService->expects($this->once()) + ->method('create') + ->will($this->throwException(new ServiceNotFoundException($this->msg))); - $response = $this->feedAPI->create('ho', 3); + $response = $this->feedAPI->create('ho', 3); - $data = $response->getData(); - $this->assertEquals($this->msg, $data['message']); - $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); - } + $data = $response->getData(); + $this->assertEquals($this->msg, $data['message']); + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); + } - public function testRead() { - $this->itemService->expects($this->once()) - ->method('readFeed') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->user)); - - $this->feedAPI->read(3, 30); - } - - - public function testMove() { - $this->feedService->expects($this->once()) - ->method('move') - ->with( - $this->equalTo(3), - $this->equalTo(30), - $this->equalTo($this->user)); - - $this->feedAPI->move(3, 30); - } - - - public function testMoveDoesNotExist() { - $this->feedService->expects($this->once()) - ->method('move') - ->will($this->throwException(new ServiceNotFoundException($this->msg))); + public function testRead() { + $this->itemService->expects($this->once()) + ->method('readFeed') + ->with( + $this->equalTo(3), + $this->equalTo(30), + $this->equalTo($this->user)); + + $this->feedAPI->read(3, 30); + } + + + public function testMove() { + $this->feedService->expects($this->once()) + ->method('move') + ->with( + $this->equalTo(3), + $this->equalTo(30), + $this->equalTo($this->user)); + + $this->feedAPI->move(3, 30); + } + + + public function testMoveDoesNotExist() { + $this->feedService->expects($this->once()) + ->method('move') + ->will($this->throwException(new ServiceNotFoundException($this->msg))); - $response = $this->feedAPI->move(3, 4); + $response = $this->feedAPI->move(3, 4); - $data = $response->getData(); - $this->assertEquals($this->msg, $data['message']); - $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); - } + $data = $response->getData(); + $this->assertEquals($this->msg, $data['message']); + $this->assertEquals(Http::STATUS_NOT_FOUND, $response->getStatus()); + } - public function testRename() { - $feedId = 3; - $feedTitle = 'test'; + public function testRename() { + $feedId = 3; + $feedTitle = 'test'; - $this->feedService->expects($this->once()) - ->method('rename') - ->with( - $this->equalTo($feedId), - $this->equalTo($feedTitle), - $this->equalTo($this->user)); + $this->feedService->expects($this->once()) + ->method('rename') + ->with( + $this->equalTo($feedId), + $this->equalTo($feedTitle), + $this->equalTo($this->user)); - $this->feedAPI->rename($feedId, $feedTitle); - } + $this->feedAPI->rename($feedId, $feedTitle); + } - public function testRenameError() { - $feedId = 3; - $feedTitle = 'test'; + public function testRenameError() { + $feedId = 3; + $feedTitle = 'test'; - $this->feedService->expects($this->once()) - ->method('rename') - ->with( - $this->equalTo($feedId), - $this->equalTo($feedTitle), - $this->equalTo($this->user)) - ->will($this->throwException(new ServiceNotFoundException('hi'))); + $this->feedService->expects($this->once()) + ->method('rename') + ->with( + $this->equalTo($feedId), + $this->equalTo($feedTitle), + $this->equalTo($this->user)) + ->will($this->throwException(new ServiceNotFoundException('hi'))); - $result = $this->feedAPI->rename($feedId, $feedTitle); - $data = $result->getData(); - $code = $result->getStatus(); + $result = $this->feedAPI->rename($feedId, $feedTitle); + $data = $result->getData(); + $code = $result->getStatus(); - $this->assertSame(Http::STATUS_NOT_FOUND, $code); - $this->assertSame('hi', $data['message']); - } + $this->assertSame(Http::STATUS_NOT_FOUND, $code); + $this->assertSame('hi', $data['message']); + } - public function testfromAllUsers(){ - $feed = new Feed(); - $feed->setUrl(3); - $feed->setId(1); - $feed->setUserId('john'); - $feeds = [$feed]; - $this->feedService->expects($this->once()) - ->method('findAllFromAllUsers') - ->will($this->returnValue($feeds)); - $response = json_encode($this->feedAPI->fromAllUsers()); - $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response); - } + public function testfromAllUsers(){ + $feed = new Feed(); + $feed->setUrl(3); + $feed->setId(1); + $feed->setUserId('john'); + $feeds = [$feed]; + $this->feedService->expects($this->once()) + ->method('findAllFromAllUsers') + ->will($this->returnValue($feeds)); + $response = json_encode($this->feedAPI->fromAllUsers()); + $this->assertEquals('{"feeds":[{"id":1,"userId":"john"}]}', $response); + } - public function testUpdate() { - $feedId = 3; - $userId = 'hi'; + public function testUpdate() { + $feedId = 3; + $userId = 'hi'; - $this->feedService->expects($this->once()) - ->method('update') - ->with($this->equalTo($feedId), $this->equalTo($userId)); + $this->feedService->expects($this->once()) + ->method('update') + ->with($this->equalTo($feedId), $this->equalTo($userId)); - $this->feedAPI->update($userId, $feedId); - } + $this->feedAPI->update($userId, $feedId); + } - public function testUpdateError() { - $feedId = 3; - $userId = 'hi'; - $this->feedService->expects($this->once()) - ->method('update') - ->will($this->throwException(new \Exception($this->msg))); - $this->logger->expects($this->once()) - ->method('debug') - ->with($this->equalTo('Could not update feed ' . $this->msg), - $this->equalTo($this->loggerParams)); + public function testUpdateError() { + $feedId = 3; + $userId = 'hi'; + $this->feedService->expects($this->once()) + ->method('update') + ->will($this->throwException(new \Exception($this->msg))); + $this->logger->expects($this->once()) + ->method('debug') + ->with($this->equalTo('Could not update feed ' . $this->msg), + $this->equalTo($this->loggerParams)); - $this->feedAPI->update($userId, $feedId); + $this->feedAPI->update($userId, $feedId); - } + } } diff --git a/tests/unit/controller/FeedControllerTest.php b/tests/unit/controller/FeedControllerTest.php index ed20308ec..34b0a847b 100644 --- a/tests/unit/controller/FeedControllerTest.php +++ b/tests/unit/controller/FeedControllerTest.php @@ -23,483 +23,483 @@ use \OCA\News\Service\ServiceConflictException; class FeedControllerTest extends \PHPUnit_Framework_TestCase { - private $appName; - private $feedService; - private $request; - private $controller; - private $folderService; - private $itemService; - private $settings; - private $exampleResult; - - - /** - * Gets run before each test - */ - public function setUp(){ - $this->appName = 'news'; - $this->user = 'jack'; - $this->settings = $this->getMockBuilder( - '\OCP\IConfig') - ->disableOriginalConstructor() - ->getMock(); - $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->controller = new FeedController($this->appName, $this->request, - $this->folderService, - $this->feedService, - $this->itemService, - $this->settings, - $this->user); - $this->exampleResult = [ - 'activeFeed' => [ - 'id' => 0, - 'type' => FeedType::SUBSCRIPTIONS - ] - ]; - } - - - public function testIndex(){ - $result = [ - 'feeds' => [ - ['a feed'], - ], - 'starred' => 13 - ]; - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($result['feeds'])); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo($this->user)) - ->will($this->throwException(new ServiceNotFoundException(''))); - $this->itemService->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($result['starred'])); - - $response = $this->controller->index(); - - $this->assertEquals($result, $response); - } - - - public function testIndexHighestItemIdExists(){ - $result = [ - 'feeds' => [ - ['a feed'], - ], - 'starred' => 13, - 'newestItemId' => 5 - ]; - $this->feedService->expects($this->once()) - ->method('findAll') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($result['feeds'])); - $this->itemService->expects($this->once()) - ->method('getNewestItemId') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($result['newestItemId'])); - $this->itemService->expects($this->once()) - ->method('starredCount') - ->with($this->equalTo($this->user)) - ->will($this->returnValue($result['starred'])); - - $response = $this->controller->index(); - - $this->assertEquals($result, $response); - } - - - - private function activeInitMocks($id, $type){ - $this->settings->expects($this->at(0)) - -> |