. * */ 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"); class ExportControllerTest extends ControllerTestUtility { private $api; private $request; private $controller; private $user; private $feedBusinessLayer; private $folderBusinessLayer; private $itemBusinessLayer; private $opmlExporter; /** * Gets run before each test */ 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(); $this->folderBusinessLayer = $this->getMockBuilder('\OCA\News\BusinessLayer\FolderBusinessLayer') ->disableOriginalConstructor() ->getMock(); $this->request = new Request(); $this->opmlExporter = new OPMLExporter(); $this->controller = new ExportController($this->api, $this->request, $this->feedBusinessLayer, $this->folderBusinessLayer, $this->itemBusinessLayer, $this->opmlExporter); $this->user = 'john'; } public function testOpmlAnnotations(){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'CSRFExemption'); $this->assertAnnotations($this->controller, 'opml', $annotations); } public function testArticlesAnnotations(){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'CSRFExemption'); $this->assertAnnotations($this->controller, 'articles', $annotations); } public function testOpmlExportNoFeeds(){ $opml = "\n" . "\n" . " \n" . " Subscriptions\n" . " \n" . " \n" . "\n"; $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(array())); $this->folderBusinessLayer->expects($this->once()) ->method('findAll') ->with($this->equalTo($this->user)) ->will($this->returnValue(array())); $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 = 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()); } }