diff options
Diffstat (limited to 'tests/unit/controller/ExportControllerTest.php')
-rw-r--r-- | tests/unit/controller/ExportControllerTest.php | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php index 29e0b6f71..2b9d41dde 100644 --- a/tests/unit/controller/ExportControllerTest.php +++ b/tests/unit/controller/ExportControllerTest.php @@ -27,11 +27,14 @@ namespace OCA\News\Controller; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Http\TextDownloadResponse; +use \OCA\AppFramework\Http\JSONResponse; use \OCA\AppFramework\Utility\ControllerTestUtility; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Utility\OPMLExporter; +use \OCA\News\Db\Item; +use \OCA\News\Db\Feed; require_once(__DIR__ . "/../../classloader.php"); @@ -44,6 +47,7 @@ class ExportControllerTest extends ControllerTestUtility { private $user; private $feedBusinessLayer; private $folderBusinessLayer; + private $itemBusinessLayer; private $opmlExporter; /** @@ -51,6 +55,9 @@ class ExportControllerTest extends ControllerTestUtility { */ public function setUp(){ $this->api = $this->getAPIMock(); + $this->itemBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\ItemBusinessLayer') + ->disableOriginalConstructor() + ->getMock(); $this->feedBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FeedBusinessLayer') ->disableOriginalConstructor() ->getMock(); @@ -60,7 +67,8 @@ class ExportControllerTest extends ControllerTestUtility { $this->request = new Request(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->api, $this->request, - $this->feedBusinessLayer, $this->folderBusinessLayer, $this->opmlExporter); + $this->feedBusinessLayer, $this->folderBusinessLayer, + $this->itemBusinessLayer, $this->opmlExporter); $this->user = 'john'; } @@ -72,6 +80,13 @@ class ExportControllerTest extends ControllerTestUtility { } + public function testArticlesAnnotations(){ + $annotations = array('IsAdminExemption', 'IsSubAdminExemption', + 'CSRFExemption'); + $this->assertAnnotations($this->controller, 'articles', $annotations); + } + + public function testOpmlExportNoFeeds(){ $opml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" . @@ -100,4 +115,49 @@ class ExportControllerTest extends ControllerTestUtility { } + 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 = array($feed1, $feed2); + + $articles = array( + $item1, $item2 + ); + + $this->api->expects($this->once()) + ->method('getUserId') + ->will($this->returnValue($this->user)); + $this->feedBusinessLayer->expects($this->once()) + ->method('findAll') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($feeds)); + $this->itemBusinessLayer->expects($this->once()) + ->method('getUnreadOrStarred') + ->with($this->equalTo($this->user)) + ->will($this->returnValue($articles)); + + + $return = $this->controller->articles(); + $headers = $return->getHeaders(); + $this->assertTrue($return instanceof JSONResponse); + $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 |