. * */ namespace OCA\News\Controller; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Http\TextDownloadResponse; use \OCA\AppFramework\Utility\ControllerTestUtility; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Utility\OPMLExporter; require_once(__DIR__ . "/../../classloader.php"); class ExportControllerTest extends ControllerTestUtility { private $api; private $request; private $controller; private $user; private $feedBusinessLayer; private $folderBusinessLayer; private $opmlExporter; /** * Gets run before each test */ public function setUp(){ $this->api = $this->getAPIMock(); $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->opmlExporter); $this->user = 'john'; } public function testOpmlAnnotations(){ $annotations = array('IsAdminExemption', 'IsSubAdminExemption', 'CSRFExemption'); $this->assertAnnotations($this->controller, 'opml', $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()); } }